flutter web is not release for stable release, so if you want to create flutter web project then you have to switch to beta version of flutter sdk so that you will get latest features from flutter before the public release. But keep in mind that beta versions are early release which means it make contain some defects of bugs.
below are commands to switch to flutter beta sdk, then get latest updates for flutter sdk and finally enable flutter web support
flutter channel betaflutter upgradeflutter config --enable-web
After enabling flutter web support, “Chrome” in device list if you run flutter devices
. And you can run your project by selecting Chrome as device.
Now you have to options to work with flutter web.
Create new flutter app and flutter web support will enable automatically. Below are commands to create new flutter project (run on Command prompt in windows and Terminal in Linux or Unix):
flutter create myappcd myapp
This will create new flutter app, now you can run and test your app on Chrome browser. To run your flutter web app type below command in Command prompt in windows and Terminal in Linux or Unix.
flutter run -d chrome
To build your flutter for web in release mode, you can run below command in Command prompt in windows and Terminal in Linux or Unix.
flutter build web
And this command will generate web files inside build/web
directory of your project.
If you have already built your project in flutter and you want to add support for flutter web, then you can run below command and it will create web folder with configuration inside your project directory.
flutter create .
development of flutter web app is same as normal flutter app, You have to write code for flutter app only, and when you run or build your project then it will generate html, js files internally. But in some case you have to do some extra changes to work with flutter web app.
if you want to use firebase in your flutter web app then you need to include firebase javascript libraries in <head>
tag of index.html file inside web directory of your project.
lets try to create simple login form in flutter and check if your working in flutter web as well or we need to do some modifications.
In lib/main.dart
file write below code.
import 'package:flutter/material.dart';void main() => runApp(SignUpApp());class SignUpApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(routes: {'/': (context) => SignUpScreen(),},);}}class SignUpScreen extends StatelessWidget {Widget build(BuildContext context) {return Scaffold(backgroundColor: Colors.grey[200],body: Center(child: SizedBox(width: 400,child: Card(child: SignUpForm(),),),),);}}class SignUpForm extends StatefulWidget {_SignUpFormState createState() => _SignUpFormState();}class _SignUpFormState extends State<SignUpForm> {final _firstNameTextController = TextEditingController();final _lastNameTextController = TextEditingController();final _usernameTextController = TextEditingController();double _formProgress = 0;Widget build(BuildContext context) {return Form(child: Column(mainAxisSize: MainAxisSize.min,children: [LinearProgressIndicator(value: _formProgress),Text('Sign up', style: Theme.of(context).textTheme.headline4),Padding(padding: EdgeInsets.all(8.0),child: TextFormField(controller: _firstNameTextController,decoration: InputDecoration(hintText: 'First name'),),),Padding(padding: EdgeInsets.all(8.0),child: TextFormField(controller: _lastNameTextController,decoration: InputDecoration(hintText: 'Last name'),),),Padding(padding: EdgeInsets.all(8.0),child: TextFormField(controller: _usernameTextController,decoration: InputDecoration(hintText: 'Username'),),),FlatButton(color: Colors.blue,textColor: Colors.white,onPressed: null,child: Text('Sign up'),),],),);}}
After writing above code now run this app on Android device, by using flutter run
command or directly from your IDE.
Now run this project in Chrome, using flutter run -d chrome
command, and you will see same output on Chrome as well.
LESSONS
COURSES
TUTORS
Quick Links
Legal Stuff
Social Media