Skip to main content

What’s so Great About DartPad, How Can We Embed Flutter App in a Website?


Flutter is a framework that creates a native app for android and iOS. And has now started with the web. Which means you can now create a website using Flutter. DartPad an open-source tool allows using Dart language for any modern browser. It comes with several pages in this site especially codelabs that have to embed Dartpads. To get started with this, you need to visit the DartPad site (dartpad.dev).

Flutter Dartpad looks like below:

DartPad site

How to get started with DartPad Flutter Online?

  • Open DartPad: A sample shown above will open on the left, and you’ll get output on the right. Click on New pad to get the previous screen.
  • Click on Run to get updated output
  • Choose HTML sample and check output again
  • Click on Console to view the sample’s console output
  • On the left, click on HTML tab and see the sample’s HTML markup

How to create a command-line app?

  • Click on the new pad and make sure you discard the change.
  • Clear the show web content at the bottom right so HTML and CSS tabs will disappear
  • Change the code as per your need. Here DartPad will show the hints and autocomplete suggestions.
  • Click on the Format button. Ensure the code you have written has proper spacing, indentation, and line-wrapping.
  • Now, Run your application

I hope you’re clear about the installation and working of Flutter DartPad. Let’s move on with embedding code in webpages.

Instead of hosting the Flutter application, you can make a simple application. The application should work on the web and share it with others. It comes with powerful and useful features that we can’t even imagine. Here we have a list of steps that helps in the Dartpad embed Flutter app. According to Jose Alba, a developer at Google said: There are two ways to create a DartPad instance.

  • Using a Gist File
  • Using a GitHub Repo

Let’s understand in brief how it works

Using a Gist File

As explained above, open DartPad and create an application. You can write code in the main.dart file in flutter application. Flutter app Developer can use the editor to be aware of the DartPad limitations. Where suppose one limited Dart file can’t import non-Dart libraries.

Note that the below import package example tells DartPad that this is a Flutter Application.

import ‘package:flutter/material.dart’;

 

void main() => runApp(MyApp());

 

class MyApp extends StatelessWidget {

@override

Widget build(BuildContext context) {

return MaterialApp(

title: ‘Flutter Demo’,

debugShowCheckedModeBanner: false,

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: MyHomePage(),

);

}

}

 

class MyHomePage extends StatelessWidget {

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text(‘Flutter Applcation Embedded in Website’),

),

body: Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

Text(

‘The Gist URL to this website is:’,

textAlign: TextAlign.center,

),

Text(

‘https://gist.github.com/JoseAlba/a205e21aa0d0a64fe7c977107ce22cbf \n’,

textAlign: TextAlign.center,

),

Text(

‘The Dartpad URL to this website is:’,

textAlign: TextAlign.center,

),

Text(

‘https://dartpad.dev/a205e21aa0d0a64fe7c977107ce22cbf \n’,

textAlign: TextAlign.center,

),

Text(

‘The iFrame code is:’,

textAlign: TextAlign.center,

),

Text(

‘<iframe src=”https://dartpad.dev/embed-flutter.html?id=a205e21aa0d0a64fe7c977107ce22cbf”></iframe> \n’,

textAlign: TextAlign.center,

),

Text(

‘This Flutter application might be within an iFrame. \n’,

textAlign: TextAlign.center,

),

],

),

),

);

}

}

Source: Hosted by Github

As soon as the Flutter app built on DartPad, you can copy-paste it on new gist file. The new gist file on GitHub can be either Public or Private. Check the file name on your main.dart before sharing code. If you found any errors you can look at DartPad Sharing Guide. To test the file, you can check on gist that’s available on DartPad. For DartPad Embed Flutter app, you can get most of the information from DartPad Embedding Guide.

Using a GitHub Repo

If you’re planning to create a repository, then there are few files that you can use.

  • dartpad_metadata.yaml (MANDATORY)
  • hint.txt (OPTIONAL)
  • main.dart (MANDATORY)
  • solution.dart (OPTIONAL)
  • test.dart (OPTIONAL)

If you have one Dart file, then you need to use dartpad_metadata.yaml and main.dart rest all are optional. Suppose you need to test the file then without using runApp() method, you can test the application. As main. Dart and test.dart considered as a single file.

Moving on, if you want to import the material package from main.dart the use test.dart. DartPad instance will load the file. But to load the folder, you need to have following access into DartPad.

  • gh_owner: Owner of the GitHub account.
  • gh_repo: Name of the repo within the above account.
  • gh_path: Path to a dartpad_metadata.yaml file within the repo.
  • gh_ref: (optional) Branch to use when loading the file. Defaults to master.

Source: Flutter in DartPad

Final Thoughts

Dart is a mobile-friendly object-oriented class and defined as a garbage collector language. Whereas, DartPad uses Dart language, which helps to embed Flutter app on a website. If you’re interested in playing with Flutter. Hire flutter app developer and customize your site.

Comments

Popular posts from this blog

How Much Does It Cost To Hire An App Developer In 2019?

It is considered a very important question that how much it effectively costs for the purpose of hiring an app developer and that too in the year 2019. Nowadays, due to the rising trend, it is very important to hire iPhone developer. Also, it seems that each business, as well as every brand, has its own app in the year 2019. In that way, you can also hire iPhone app developer India. Even, there are many of the local coffee shops which possess an app for the purpose of ordering a frappuccino available at your doorstep or you can collect it on discounts. For developing these apps, sometimes it becomes very important to preferably hire iPhone programmer. There is a gradual presence of many of the IT entrepreneur who is usually making a fortune from a hit app. So, here are given some of the ever-actual issues of how to  hire iPhone app developer  for the development purpose. We will preferably talk about some of the important as well as general tips which can prove helpful to hire io

Engagement Models For Laravel Application Development

  In the mobile app, the development backend holds prime importance. It has a trusted and dependable technology that would take good care of your backend operations with ease. For this purpose, Laravel creator said, “we want to simplify the development process”. Today the Laravel 5.4 is the latest released version that enforces the same ideology with new features. Leverage the best Laravel application development service & create a well-tailored web app. Hire a Laravel development company to scale business growth. Laravel provides predefined architecture and customized backend logic to stand out differently from the crowd. Hire Laravel developers in India and choose the company that understands your needs. We are one of the best leading web application development companies in India. We offer a wide range of engagement models that suits our customer’s needs. Let’s dive into understanding the engagement models in a better way. What are engagement models? An engagement model is a

Get Familiar With AWS SDK In .NET Core

In this post, we will see how to get started with AWS SDK for dot NET core. How it helps in creating  .NET core applications . The main objective is to gain foundation-level knowledge. It can be useful for starting developing .NET applications with AWS SDK. There are many aspects to get familiar with AWS SDK used for dot NET core. To take an initiation towards it, one must know from where to start and how to use it. Few topics that we are going to elaborate on here for AWS are What Is the AWS SDK? How can be secure with AWS Requests? What are the ways for Creating a user in AWS IAM? How to apply for the AWS credentials locally? Is it necessary for registering credentials? What are  AWS .Net core SDK  Essentials? What is the AWS SDK? To manage and consume AWS services and resources, AWS SDK provides access. The SDK libraries are available via Nuget as several packages related to AWS services. You can even access AWS via a variety of tools such as AWS Console or the AWS CLI experience. W