Professional Documents
Culture Documents
GL Utter
GL Utter
Flutter 2.5 is released to stable! For details, see What's new in Flutter 2.5.
keyboard_arrow_down
Write your first Flutter app on the web
Get started Docs chevron_right Get started chevron_right Write your first web app
1. Install
2. Set up an editor
User interface
Platform integration
Migration notes
Who is Dash?
Widget index
What you’ll learn
How to write a Flutter app that looks natural on the web.
API reference
Basic structure of a Flutter app.
flutter CLI reference
How to implement a Tween animation.
Package site How to implement a stateful widget.
How to use the debugger to set breakpoints.
Flutter SDK
Chrome browser
Text editor or IDE
You’ll start with a simple web app that we provide for you.
2. Set up an editor
If you have problems enabling web development,
see Building a web application with Flutter.
3. Test drive
5. Learn more The flutter doctor command reports the status of the installation.
You should see something like the following:
$ flutter doctor
arrow_drop_downFrom another platform?
Flutter for Android devs
[✓] Flutter: is fully installed. (Channel dev, v1.9.5, on Mac OS X 10.14.6 18G87, locale en-US)
Flutter for iOS devs [✗] Android toolchain - develop for Android devices: is not installed.
Flutter for React Native devs [✗] Xcode - develop for iOS and macOS: is not installed.
[✓] Chrome - develop for the web: is fully installed.
Flutter for web devs
[!] Android Studio: is not available. (not installed)
Flutter for Xamarin.Forms devs [✓] Connected device: is fully installed. (1 available)
Introduction to declarative UI
Dart language overview It’s okay if the Android toolchain, Android Studio,
and the Xcode tools are not installed,
since the app is intended for the web
only.
If you later want this app to work on mobile,
you will need to do additional installation and setup.
Building a web app
Who is Dash?
Widget index
API reference
Package site
Important:
This page uses an embedded version of DartPad
to display examples and exercises.
If you see empty
boxes instead of DartPads,
go to the DartPad troubleshooting page.
https://flutter.dev/docs/get-started/codelab-web 2/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
Observations
keyboard_arrow_down
Get started The entire code for this example lives in the
lib/main.dart file.
If you know Java, the Dart language should feel very familiar.
1. Install
All of the app’s UI is created in Dart code.
For more information, see Introduction to declarative UI.
2. Set up an editor The app’s UI adheres Material Design,
a visual design language that runs on any device or platform.
You can customize the
3. Test drive Material Design widgets,
but if you prefer something else,
Flutter also offers the Cupertino widget library,
which implements
4. Write your first app current iOS design language.
Or you can create your own custom widget library.
In Flutter, almost everything is a Widget.
Even the app itself is a widget.
The app’s UI can be described as a widget tree.
5. Learn more
User interface
Widget index
onPressed: _showWelcomeScreen,
API reference
void _showWelcomeScreen() {
Navigator.of(context).pushNamed('/welcome');
}
Observations
The _showWelcomeScreen() function is used in the build()
method as a callback function. Callback functions are often
us
in Dart code and, in this case, this means
“call this method when the button is pressed”.
https://flutter.dev/docs/get-started/codelab-web 3/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
keyboard_arrow_down
Get started
5. Learn more
Note:
This example does not validate the accuracy of the user input.
That is something you can add later using form
arrow_drop_downFrom another platform? validation, if you like.
Flutter for Android devs
Migration notes
This method updates the _formProgress field based on the
the number of non-empty text fields.
Testing & debugging keyboard_arrow_down 2. Call _updateFormProgress when the form
changes.
Package site
...
TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.disabled) ? null : Colors.white;
}),
backgroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.disabled) ? null : Colors.blue;
}),
),
onPressed: _formProgress == 1 ? _showWelcomeScreen : null, // UPDATED
child: Text('Sign up'),
),
...
Observations
https://flutter.dev/docs/get-started/codelab-web 4/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
4. Write your first app Where methodName is a named function that takes an anonymous
callback function as an argument.
5. Learn more
The Dart syntax in the last step that displays the
welcome screen is:
Flutter for iOS devs This is a Dart conditional assignment and has the syntax:
condition ? expression1 : expression2.
If the expression
Flutter for React Native devs _formProgress == 1 is true, the entire expression results
in the value on the left hand side of the :, which is the
_showWelcomeScreen method in this case.
Flutter for web devs
User interface
Accessibility & internationalization If your app isn’t currently running, launch it.
Select the Chrome device from the pull down
and launch it from your IDE or,
from
the command line, use flutter run -d chrome,
Platform integration
Packages & plugins 2. Get the web socket info for DevTools.
Who is Dash?
When DevTools launches, you should see something
like the following:
Widget index
API reference
Serving DevTools at http://127.0.0.1:9100
flutter CLI reference
Package site Go to this URL in a Chrome browser. You should see the DevTools
launch screen. It should look like the following:
https://flutter.dev/docs/get-started/codelab-web 5/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
keyboard_arrow_down
Get started
1. Install
2. Set up an editor
3. Test drive
5. Learn more
Introduction to declarative UI
User interface
DevTools
running successfully in your Chrome browser:
Data & backend
Platform integration
Migration notes
Who is Dash?
Widget index
API reference
Package site
Note:
This is not the only way to launch DevTools.
If you are using IntelliJ,
you can open DevTools by going to
Flutter
Inspector -> More Actions -> Open DevTools:
https://flutter.dev/docs/get-started/codelab-web 6/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
keyboard_arrow_down
Get started
1. Install
2. Set up an editor
3. Test drive
5. Learn more
Introduction to declarative UI
User interface
Platform integration
Migration notes
Who is Dash?
Widget index
API reference
Place a breakpoint on the line with the for loop by clicking to the
left of the line number. The breakpoint now appears
in the
Breakpoints section to the left of the window.
In the running app, click one of the text fields to gain focus.
The app hits the breakpoint and pauses.
In the DevTools screen
can see on the left
the value of progress, which is 0. This is to be expected,
since none of the fields are filled in.
Step throug
the for loop to see
the program execution.
https://flutter.dev/docs/get-started/codelab-web 7/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
1. Add an AnimatedProgressIndicator.
User interface
with SingleTickerProviderStateMixin {
Data & backend late AnimationController _controller;
Accessibility & internationalization late Animation<Color?> _colorAnimation;
late Animation<double> _curveAnimation;
Platform integration
@override
void didUpdateWidget(oldWidget) {
super.didUpdateWidget(oldWidget);
_controller.animateTo(widget.value);
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) => LinearProgressIndicator(
value: _curveAnimation.value,
valueColor: _colorAnimation,
backgroundColor: _colorAnimation.value?.withOpacity(0.4),
),
);
}
}
https://flutter.dev/docs/get-started/codelab-web 8/9
21/09/2021 16:49 Flutter | Write your first Flutter app on the web
...
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
keyboard_arrow_down AnimatedProgressIndicator(value: _formProgress), // NEW
Get started Text('Sign up', style: Theme.of(context).textTheme.headline4),
Padding(
1. Install
...
2. Set up an editor
5. Learn more
Type anything into the three fields to verify that
the animation works, and that clicking the
Sign up button brings up the
Welcome screen.
arrow_drop_downFrom another platform?
Flutter for Android devs
Flutter for web devs Dart Tests Install SDK Hint Format Reset Run
Introduction to declarative UI
User interface
Platform integration
Migration notes
API reference
Package site
What next?
Congratulations!
You have created your first web app using Flutter!
Animation docs
Dart DevTools
Implicit animations codelab
Web samples
flutter-dev@ •
terms •
brand usage •
security •
privacy •
español •
社区中文资源 • 한국어 •
We stand in solidarity with the Black community. Black Lives Matter.
Except as otherwise noted,
this work is licensed under a
Creative
Commons Attribution 4.0 International License,
and code samples are licensed under the BSD License.
https://flutter.dev/docs/get-started/codelab-web 9/9