Flutter for web, This page covers the following steps for getting started with web support:
flutter
tool for web support.To create a Flutter app with web support, you need the following software:
For more information, see the web FAQ.
You can use the following steps to create a new project with web support.
Run the following commands to use the latest version of the Flutter SDK:content_copy
$ flutter channel stable
$ flutter upgrade
Warning: Running flutter channel stable
replaces your current version of Flutter with the stable version and can take time if your connection is slow. After this, running flutter upgrade
upgrades your install to the latest stable
. Returning to another channel (beta or master) requires calling flutter channel <channel>
explicitly.
If Chrome is installed, the flutter devices
command outputs a Chrome
device that opens the Chrome browser with your app running, and a Web Server
that provides the URL serving the app.content_copy
$ flutter devices
1 connected device:
Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.150
In your IDE, you should see Chrome (web) in the device pulldown.
Creating a new project with web support is no different than creating a new Flutter project for other platforms.
Create a new app in your IDE and it automatically creates iOS, Android, desktop, and web versions of your app. From the device pulldown, select Chrome (web) and run your app to see it launch in Chrome.
To create a new app that includes web support (in addition to mobile support), run the following commands, substituting my_app
with the name of your project:content_copy
$ flutter create my_app
$ cd my_app
To serve your app from localhost
in Chrome, enter the following from the top of the package:content_copy
$ flutter run -d chrome
Note: If there aren’t any other connected devices, the -d chrome
is optional.
The flutter run
command launches the application using the development compiler in a Chrome browser.
Warning: Hot reload is not supported in a web browser Currently, Flutter supports hot restart, but not hot reload in a web browser.
Run the following command to generate a release build:content_copy
$ flutter build web
A release build uses dart2js (instead of the development compiler) to produce a single JavaScript file main.dart.js
. You can create a release build using release mode (flutter run --release
) or by using flutter build web
. This populates a build/web
directory with built files, including an assets
directory, which need to be served together.
You can also include --web-renderer html
or --web-renderer canvaskit
to select between the HTML or CanvasKit renderers, respectively. For more information, see Web renderers.
For more information, see Build and release a web app.
To add web support to an existing project created using a previous version of Flutter, run the following command from your project’s top-level directory:content_copy
$ flutter create --platforms web .
You’ll implement a simple web app that displays a sign in screen. The screen contains three text fields: first name, last name, and username. As the user fills out the fields, a progress bar animates along the top of the sign in area. When all three fields are filled in, the progress bar displays in green along the full width of the sign in area, and the Sign up button becomes enabled. Clicking the Sign up button causes a welcome screen to animate in from the bottom of the screen.
The animated GIF shows how the app works at the completion of this lab.
While developing, run your web app in Chrome so you can debug with Dart DevTools.
You’ll start with a simple web app that we provide for you.
$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel master, 3.4.0-19.0.pre.254, on macOS 12.6 21G115 darwin-arm64, locale en) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.71.1) [✓] Connected device (4 available) [✓] HTTP Host Availability • No issues found!
If you see “flutter: command not found”, then make sure that you have installed the Flutter SDK and that it’s in your path.It’s okay if the Android toolchain, Android Studio, and the Xcode tools aren’t installed, since the app is intended for the web only. If you later want this app to work on mobile, you’ll need to do additional installation and setup.$ flutter devices 4 connected devices: sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) iPhone 14 Pro Max (mobile) • 45A72BE1-2D4E-4202-9BB3-D6AE2601BEF8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator) macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm64 Chrome (web) • chrome • web-javascript • Google Chrome 105.0.5195.125
The Chrome device automatically starts Chrome and enables the use of the Flutter DevTools tooling.lib/main.dart
file.for more information XpertLab
similar Blogs Click