id
stringlengths 14
17
| text
stringlengths 23
1.11k
| source
stringlengths 35
114
|
---|---|---|
6367d524307d-2 | class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter layout demo',
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter layout demo'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}
Step 1: Diagram the layout
The first step is to break the layout down to its basic elements:
Identify the rows and columns.
Does the layout include a grid?
Are there overlapping elements?
Does the UI need tabs?
Notice areas that require alignment, padding, or borders.
First, identify the larger elements. In this example,
four elements are arranged into a column: an image, two rows, and a block of text. | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-3 | Next, diagram each row. The first row, called the Title
section, has 3 children: a column of text, a star icon,
and a number. Its first child, the column, contains 2 lines of text.
That first column takes a lot of space, so it must be wrapped in an
Expanded widget.
The second row, called the Button section, also has
3 children: each child is a column that contains an icon and text.
Once the layout has been diagrammed, it’s easiest to
take a bottom-up approach to implementing it.
To minimize the visual confusion of deeply nested layout code,
place some of the implementation in variables and functions.
Step 2: Implement the title row
First, you’ll build the left column in the title section.
Add the following code at the top of the build()
method of the MyApp class:
lib/main.dart (titleSection) | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-4 | lib/main.dart (titleSection)
Putting a Column inside an Expanded widget stretches
the column to use all remaining free space in the row.
Setting the crossAxisAlignment property to
CrossAxisAlignment.start positions the column at
the start of the row.
Putting the first row of text inside a Container
enables you to add padding. The second child in the
Column, also text, displays as grey.
The last two items in the title row are a star icon,
painted red, and the text “41”. The entire row is in
a Container and padded along each edge by 32 pixels.
Add the title section to the app body like this:
{../base → step2}/lib/main.dart
@@ -14,11 +48,13 @@
14
48
return MaterialApp(
15
49
title: 'Flutter layout demo', | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-5 | 15
49
title: 'Flutter layout demo',
16
50
home: Scaffold(
17
51
appBar: AppBar(
18
52
title: const Text('Flutter layout demo'),
19
53
),
20
body: const Center(
21
child: Text('Hello World'),
54
+
body: Column(
55
+
children: [
56
+
titleSection,
57
+
],
22
58
), | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-6 | 22
58
),
23
59
),
24
60
);
Tip:
When pasting code into your app, indentation can
become skewed. You can fix this in your Flutter editor
using the automatic reformatting support.
For a faster development experience,
try Flutter’s hot reload feature.
If you have problems, compare your code to lib/main.dart.
Step 3: Implement the button row
The button section contains 3 columns that use the same
layout—an icon over a row of text.
The columns in this row are evenly spaced,
and the text and icons are painted with the primary color. | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-7 | Since the code for building each column is almost identical,
create a private helper method named buildButtonColumn(),
which takes a color, an Icon and Text,
and returns a column with its widgets painted in the given color.
lib/main.dart (_buildButtonColumn)
The function adds the icon directly to the column.
The text is inside a Container with a top-only margin,
separating the text from the icon.
Build the row containing these columns by calling the
function and passing the color, Icon, and text specific
to that column. Align the columns along the main axis
using MainAxisAlignment.spaceEvenly to arrange the
free space evenly before, between, and after each column.
Add the following code just below the
titleSection declaration inside the build() method:
lib/main.dart (buttonSection)
Add the button section to the body:
{step2 → step3}/lib/main.dart
@@ -48,3 +59,3 @@ | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-8 | @@ -48,3 +59,3 @@
48
59
return MaterialApp(
49
60
title: 'Flutter layout demo',
50
61
home: Scaffold(
@@ -54,8 +65,9 @@
54
65
body: Column(
55
66
children: [
56
67
titleSection,
68
+
buttonSection,
57
69
],
58
70
),
59
71
),
60
72
); | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-9 | ),
60
72
);
61
73
Step 4: Implement the text section
Define the text section as a variable. Put the text
in a Container and add padding along each edge.
Add the following code just below the buttonSection
declaration:
lib/main.dart (textSection)
By setting softwrap to true, text lines will fill the column width before
wrapping at a word boundary.
Add the text section to the body:
{step3 → step4}/lib/main.dart
@@ -59,3 +72,3 @@
59
72
return MaterialApp(
60
73
title: 'Flutter layout demo',
61
74
home: Scaffold( | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-10 | 61
74
home: Scaffold(
@@ -66,6 +79,7 @@
66
79
children: [
67
80
titleSection,
68
81
buttonSection,
82
+
textSection,
69
83
],
70
84
),
71
85
),
Step 5: Implement the image section
Three of the four column elements are now complete,
leaving only the image. Add the image file to the example:
Create an images directory at the top of the project.
Add lake.jpg. | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-11 | Add lake.jpg.
Note that wget doesn’t work for saving this binary file.
The original image is available online under a
Creative Commons license, but it’s large and slow to fetch.
Update the pubspec.yaml file to include an assets tag.
This makes the image available to your code.
{step4 → step5}/pubspec.yaml
Viewed
@@ -18,3 +18,5 @@
18
18
flutter:
19
19
uses-material-design: true | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-12 | 20
+
assets:
21
+
- images/lake.jpg
Tip:
Note that pubspec.yaml is case sensitive,
so write assets: and the image URL
as shown above.
The pubspec file is also sensitive to white
space, so use proper indentation.
You might need to restart the running program
(either on the simulator or a connected device) for the
pubspec changes to take effect.
Now you can reference the image from your code:
{step4 → step5}/lib/main.dart
@@ -77,6 +77,12 @@
77
77
),
78
78
body: Column( | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-13 | 78
78
body: Column(
79
79
children: [
80
+
Image.asset(
81
+
'images/lake.jpg',
82
+
width: 600,
83
+
height: 240,
84
+
fit: BoxFit.cover,
85
+
),
80
86
titleSection,
81
87
buttonSection,
82
88
textSection, | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-14 | 82
88
textSection,
BoxFit.cover tells the framework that the image should
be as small as possible but cover its entire render box.
Step 6: Final touch
In this final step, arrange all of the elements in a
ListView, rather than a Column, because a
ListView supports app body scrolling when the app is run
on a small device.
{step5 → step6}/lib/main.dart
@@ -72,13 +77,13 @@
72
77
return MaterialApp(
73
78
title: 'Flutter layout demo',
74
79
home: Scaffold(
75
80
appBar: AppBar(
76
81 | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-15 | appBar: AppBar(
76
81
title: const Text('Flutter layout demo'),
77
82
),
78
body: Column(
83
+
body: ListView(
79
84
children: [
80
85
Image.asset(
81
86
'images/lake.jpg',
82
87
width: 600,
83
88
height: 240,
84
89
fit: BoxFit.cover,
main.dart
images
pubspec.yaml | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
6367d524307d-16 | main.dart
images
pubspec.yaml
That’s it! When you hot reload the app,
you should see the same app layout as
the screenshot at the top of this page.
You can add interactivity to this layout by following
Adding Interactivity to Your Flutter App. | https://docs.flutter.dev/development/ui/layout/tutorial/index.html |
c4c2a7ce07c2-0 | Material Design for Flutter
UI
Material Design for Flutter
Material Design is an open-source design system built
and supported by Google designers and developers.
The latest version, Material 3, enables personal,
adaptive, and expressive experiences—from dynamic color
and enhanced accessibility, to foundations for
large screen layouts, and design tokens.
Flutter is in the process of migrating to Material 3.
Note:
A few facts about Material 3 (M3),
the next generation of Material Design:
Most Flutter widgets are already migrated to M3,
but you can follow progress on the
Material 3 Flutter GitHub project and the
GitHub umbrella issue.
You can opt in to
Material 3 using the useMaterial3 flag.
However, your UI might be inconsistent until
all of Flutter and your code are migrated. | https://docs.flutter.dev/development/ui/material/index.html |
c4c2a7ce07c2-1 | For the latest list of Flutter’s widgets that
are affected by the useMaterial3 flag, see
Affected widgets.
The vast majority of Flutter widgets have similar
behavior in M2 and M3, so those widget names are unchanged.
However, a couple widgets have substantially different
behavior in M3, so new widgets have been created.
Once migration is complete, Material 3 will
become the Material library’s default look and feel.
Support for Material 2 will eventually be removed according
to Flutter’s deprecation policy.
Explore the updated components, typography, color system,
and elevation support with the
interactive Material 3 demo:
More information
To learn more about Material Design and Flutter,
check out:
Material.io developer documentation
Migrating a Flutter app to Material 3 blog post by Taha Tesser | https://docs.flutter.dev/development/ui/material/index.html |
e7196a406883-0 | Deep linking
UI
Navigation and routing
Deep linking
Get started
Migrating from plugin-based deep linking
Behavior
For more information
Flutter supports deep linking on iOS, Android, and web browsers.
Opening a URL displays that screen in your app. With the following
steps, you can launch and display routes by using named routes
(either with the routes parameter or
onGenerateRoute), or by
using the Router widget.
Note:
Named routes are no longer recommended for most
applications. For more information, see
Limitations in the navigation overview page. | https://docs.flutter.dev/development/ui/navigation/deep-linking/index.html |
e7196a406883-1 | If you’re running the app in a web browser, there’s no additional setup
required. Route paths are handled in the same way as an iOS or Android deep
link. By default, web apps read the deep link path from the url fragment using
the pattern: /#/path/to/app/screen, but this can be changed by
configuring the URL strategy for your app.
If you are a visual learner, check out the following video:
Deep linking in Flutter
Get started
To get started, see our cookbooks for Android and iOS:
Android
iOS
Migrating from plugin-based deep linking
If you have written a plugin to handle deep links, as described in
Deep Links and Flutter applications
(a free article on Medium),
it will continue to work until you opt-in to this behavior by adding
FlutterDeepLinkingEnabled to Info.plist or
flutter_deeplinking_enabled to AndroidManifest.xml, respectively. | https://docs.flutter.dev/development/ui/navigation/deep-linking/index.html |
e7196a406883-2 | Behavior
The behavior varies slightly based on the platform and whether the app is
launched and running.
iOS (not launched)
App gets initialRoute (“/”) and a short time after gets a pushRoute
App gets initialRoute (“/”) and a short time after uses the RouteInformationParser to parse the route and call RouterDelegate.setNewRoutePath, which configures the Navigator with the corresponding Page.
Android - (not launched)
App gets initialRoute containing the route (“/deeplink”)
App gets initialRoute (“/deeplink”) and passes it to the RouteInformationParser to parse the route and call RouterDelegate.setNewRoutePath, which configures the Navigator with the corresponding Pages.
iOS (launched)
pushRoute is called
Path is parsed, and the Navigator is configured with a new set of Pages.
Android (launched) | https://docs.flutter.dev/development/ui/navigation/deep-linking/index.html |
e7196a406883-3 | Android (launched)
pushRoute is called
Path is parsed, and the Navigator is configured with a new set of Pages.
When using the Router widget,
your app has the ability to replace the
current set of pages when a new deep link
is opened while the app is running.
For more information
Learning Flutter’s new navigation and routing system provides an introduction to the Router system. | https://docs.flutter.dev/development/ui/navigation/deep-linking/index.html |
b3214f63d09e-0 | Navigation and routing
UI
Navigation and routing
Using the Navigator
Using named routes
Limitations
Using the Router
Using Router and Navigator together
Web support
More information
Flutter provides a complete system for navigating between screens and handling
deep links. Small applications without complex deep linking can use
Navigator, while apps with specific deep linking and navigation
requirements should also use the Router to correctly handle deep links on
Android and iOS, and to stay in sync with the address bar when the app is
running on the web.
To configure your Android or iOS application to handle deep links, see
Deep linking.
Using the Navigator
The Navigator widget displays screens as a stack using the correct transition
animations for the target platform. To navigate to a new screen, access the
Navigator through the route’s BuildContext and call imperative methods such
as push() or pop(): | https://docs.flutter.dev/development/ui/navigation/index.html |
b3214f63d09e-1 | onPressed:
()
Navigator
of
context
push
MaterialPageRoute
builder:
context
const
SongScreen
song:
song
),
),
);
},
child:
Text
song
name
),
navigation recipes from the Flutter Cookbook or visit the
Navigator API
documentation.
Using named routes
Note:
We don’t recommend using named routes for most applications.
For more information, see the Limitations section below.
Applications with simple navigation and deep linking requirements can use the
Navigator for navigation and the MaterialApp.routes parameter for deep
links:
@override | https://docs.flutter.dev/development/ui/navigation/index.html |
b3214f63d09e-2 | @override
Widget
build
BuildContext
context
return
MaterialApp
routes:
'/'
context
HomeScreen
(),
'/details'
context
DetailScreen
(),
},
);
Routes specified here are called named routes. For a complete example, follow
the Navigate with named routes recipe from the Flutter Cookbook.
Limitations
Although named routes can handle deep links, the behavior is always the same and
can’t be customized. When a new deep link is received by the platform, Flutter
pushes a new Route onto the Navigator regardless where the user currently is. | https://docs.flutter.dev/development/ui/navigation/index.html |
b3214f63d09e-3 | Flutter also doesn’t support the browser forward button for applications using
named routes. For these reasons, we don’t recommend using named routes in most
applications.
Using the Router
Flutter applications with advanced navigation and routing requirements (such as
a web app that uses direct links to each screen, or an app with multiple
Navigator widgets) should use a routing package such as go_router that can
parse the route path and configure the Navigator whenever the app receives a
new deep link.
To use the Router, switch to the router constructor on MaterialApp or
CupertinoApp and provide it with a Router configuration. Routing packages,
such as go_router, typically provide a
configuration for you. For example:
MaterialApp
router
routerConfig:
GoRouter
// …
);
Because packages like go_router are declarative, they will always display the
same screen(s) when a deep link is received. | https://docs.flutter.dev/development/ui/navigation/index.html |
b3214f63d09e-4 | Using Router and Navigator together
Page using the
pages
argument on the
Note:
You can’t prevent navigation from page-backed screens using WillPopScope.
Instead, you should consult your routing package’s API documentation.
Web support
reverse
chronological navigation
More information
For more information on navigation and routing, check out the following
resources:
The Flutter cookbook includes multiple navigation recipes that show how to
use the Navigator.
The Navigator and Router API documentation contain details on how
to set up declarative navigation without a routing package.
Understanding navigation, a page from the Material Design documentation,
outlines concepts for designing the navigation in your app, including
explanations for forward, upward, and chronological navigation.
Learning Flutter’s new navigation and routing system, an article on
Medium, describes how to use the Router widget directly, without
a routing package. | https://docs.flutter.dev/development/ui/navigation/index.html |
b3214f63d09e-5 | The Router design document contains the motivation and design of the
Router` API. | https://docs.flutter.dev/development/ui/navigation/index.html |
5c8f91fad88e-0 | Configuring the URL strategy on the web
UI
Navigation and routing
Configuring the URL strategy on the web
Configuring the URL strategy
Configuring your web server
Hosting a Flutter app at a non-root location
Flutter web apps support two ways of configuring
URL-based navigation on the web:
Paths are read and written to the hash fragment.
For example, flutterexample.dev/#/path/to/screen.
Paths are read and written without a hash. For example,
flutterexample.dev/path/to/screen.
Configuring the URL strategy
To configure Flutter to use the path instead, use the
usePathUrlStrategy function provided by the flutter_web_plugins library
in the SDK:
import
'package:flutter_web_plugins/url_strategy.dart'
void
main | https://docs.flutter.dev/development/ui/navigation/url-strategies/index.html |
5c8f91fad88e-1 | void
main
()
usePathUrlStrategy
();
runApp
ExampleApp
());
Configuring your web server
PathUrlStrategy uses the History API, which requires additional
configuration for web servers.
To configure your web server to support PathUrlStrategy, check your web server’s
documentation to rewrite requests to index.html.Check your web server’s
documentation for details on how to configure single-page apps.
If you are using Firebase Hosting, choose the “Configure as a single-page app”
option when initializing your project. For more information see Firebase’s
Configure rewrites documentation.
The local dev server created by running flutter run -d chrome is configured to
handle any path gracefully and fallback to your app’s index.html file.
Hosting a Flutter app at a non-root location | https://docs.flutter.dev/development/ui/navigation/url-strategies/index.html |
5c8f91fad88e-2 | Hosting a Flutter app at a non-root location
Update the <base href="/"> tag in web/index.html
to the path where your app is hosted.
For example, to host your Flutter app at
my_app.dev/flutter_app, change
this tag to <base href="/flutter_app/">. | https://docs.flutter.dev/development/ui/navigation/url-strategies/index.html |
4b1645d8f773-0 | Accessibility widgets
UI
Widgets
Accessibility
Make your app accessible.
See more widgets in the widget catalog.
ExcludeSemantics
A widget that drops all the semantics of its descendants. This can be used to hide subwidgets that would otherwise be reported but that would...
MergeSemantics
A widget that merges the semantics of its descendants.
Semantics
A widget that annotates the widget tree with a description of the meaning of the widgets. Used by accessibility tools, search engines, and other semantic...
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/accessibility/index.html |
16d239581858-0 | Animation and motion widgets
UI
Widgets
Animation
Bring animations to your app.
See more widgets in the widget catalog.
AnimatedAlign
Animated version of Align which automatically transitions the child's position over a given duration whenever the given alignment changes.
AnimatedBuilder
A general-purpose widget for building animations. AnimatedBuilder is useful for more complex widgets that wish to include animation as part of a larger build function....
AnimatedContainer
A container that gradually changes its values over a period of time.
AnimatedCrossFade
A widget that cross-fades between two given children and animates itself between their sizes.
AnimatedDefaultTextStyle
Animated version of DefaultTextStyle which automatically transitions the default text style (the text style to apply to descendant Text widgets without explicit style) over a... | https://docs.flutter.dev/development/ui/widgets/animation/index.html |
16d239581858-1 | AnimatedList
A scrolling container that animates items when they are inserted or removed.
AnimatedListState
The state for a scrolling container that animates items when they are inserted or removed.
AnimatedModalBarrier
A widget that prevents the user from interacting with widgets behind itself.
AnimatedOpacity
Animated version of Opacity which automatically transitions the child's opacity over a given duration whenever the given opacity changes.
AnimatedPhysicalModel
Animated version of PhysicalModel.
AnimatedPositioned
Animated version of Positioned which automatically transitions the child's position over a given duration whenever the given position changes.
AnimatedSize
Animated widget that automatically transitions its size over a given duration whenever the given child's size changes.
AnimatedWidget
A widget that rebuilds when the given Listenable changes value. | https://docs.flutter.dev/development/ui/widgets/animation/index.html |
16d239581858-2 | A widget that rebuilds when the given Listenable changes value.
AnimatedWidgetBaseState
A base class for widgets with implicit animations.
DecoratedBoxTransition
Animated version of a DecoratedBox that animates the different properties of its Decoration.
FadeTransition
Animates the opacity of a widget.
Hero
A widget that marks its child as being a candidate for hero animations.
PositionedTransition
Animated version of Positioned which takes a specific Animation to transition the child's position from a start position to and end position over the lifetime...
RotationTransition
Animates the rotation of a widget.
ScaleTransition
Animates the scale of transformed widget.
SizeTransition
Animates its own size and clips and aligns the child.
SlideTransition | https://docs.flutter.dev/development/ui/widgets/animation/index.html |
16d239581858-3 | SlideTransition
Animates the position of a widget relative to its normal position.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/animation/index.html |
f304205efa84-0 | Assets, images, and icon widgets
UI
Widgets
Assets
Manage assets, display images, and show icons.
See more widgets in the widget catalog.
AssetBundle
Asset bundles contain resources, such as images and strings, that can be used by an application. Access to these resources is asynchronous so that they...
Icon
A Material Design icon.
Image
A widget that displays an image.
RawImage
A widget that displays a dart:ui.Image directly.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/assets/index.html |
9cb4f91e4435-0 | Async widgets
UI
Widgets
Async
Async patterns to your Flutter application.
See more widgets in the widget catalog.
FutureBuilder
Widget that builds itself based on the latest snapshot of interaction with a Future.
StreamBuilder
Widget that builds itself based on the latest snapshot of interaction with a Stream.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/async/index.html |
02255f91d470-0 | Basic widgets
UI
Widgets
Basics
Widgets you absolutely need to know before building your first Flutter app.
See more widgets in the widget catalog.
AppBar
A Material Design app bar. An app bar consists of a toolbar and potentially other widgets, such as a TabBar and a FlexibleSpaceBar.
Column
Layout a list of child widgets in the vertical direction.
Container
A convenience widget that combines common painting, positioning, and sizing widgets.
ElevatedButton
A Material Design elevated button. A filled button whose material elevates when pressed.
FlutterLogo
The Flutter logo, in widget form. This widget respects the IconTheme.
Icon
A Material Design icon.
Image
A widget that displays an image. | https://docs.flutter.dev/development/ui/widgets/basics/index.html |
02255f91d470-1 | Image
A widget that displays an image.
Placeholder
A widget that draws a box that represents where other widgets will one day be added.
Row
Layout a list of child widgets in the horizontal direction.
Scaffold
Implements the basic Material Design visual layout structure. This class provides APIs for showing drawers, snack bars, and bottom sheets.
Abc
Text
A run of text with a single style.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/basics/index.html |
2779b1dad33c-0 | Cupertino (iOS-style) widgets
UI
Widgets
Cupertino
Beautiful and high-fidelity widgets for current iOS design language.
See more widgets in the widget catalog.
CupertinoActionSheet
An iOS-style modal bottom action sheet to choose an option among many.
CupertinoActivityIndicator
An iOS-style activity indicator. Displays a circular 'spinner'.
CupertinoAlertDialog
An iOS-style alert dialog.
CupertinoButton
An iOS-style button.
CupertinoContextMenu
An iOS-style full-screen modal route that opens when the child is long-pressed. Used to display relevant actions for your content.
CupertinoDatePicker
An iOS-style date or date and time picker.
CupertinoDialogAction | https://docs.flutter.dev/development/ui/widgets/cupertino/index.html |
2779b1dad33c-1 | CupertinoDialogAction
A button typically used in a CupertinoAlertDialog.
CupertinoFullscreenDialogTransition
An iOS-style transition used for summoning fullscreen dialogs.
CupertinoNavigationBar
An iOS-style top navigation bar. Typically used with CupertinoPageScaffold.
CupertinoPageScaffold
Basic iOS style page layout structure. Positions a navigation bar and content on a background.
CupertinoPageTransition
Provides an iOS-style page transition animation.
CupertinoPicker
An iOS-style picker control. Used to select an item in a short list.
CupertinoPopupSurface
Rounded rectangle surface that looks like an iOS popup surface, such as an alert dialog or action sheet.
CupertinoScrollbar | https://docs.flutter.dev/development/ui/widgets/cupertino/index.html |
2779b1dad33c-2 | CupertinoScrollbar
An iOS-style scrollbar that indicates which portion of a scrollable widget is currently visible.
CupertinoSearchTextField
An iOS-style search field.
CupertinoSegmentedControl
An iOS-style segmented control. Used to select mutually exclusive options in a horizontal list.
CupertinoSlider
Used to select from a range of values.
CupertinoSlidingSegmentedControl
An iOS-13-style segmented control. Used to select mutually exclusive options in a horizontal list.
CupertinoSliverNavigationBar
An iOS-styled navigation bar with iOS-11-style large titles using slivers.
CupertinoSwitch
An iOS-style switch. Used to toggle the on/off state of a single setting.
CupertinoTabBar | https://docs.flutter.dev/development/ui/widgets/cupertino/index.html |
2779b1dad33c-3 | CupertinoTabBar
An iOS-style bottom tab bar. Typically used with CupertinoTabScaffold.
CupertinoTabScaffold
Tabbed iOS app structure. Positions a tab bar on top of tabs of content.
CupertinoTabView
Root content of a tab that supports parallel navigation between tabs. Typically used with CupertinoTabScaffold.
CupertinoTextField
An iOS-style text field.
CupertinoListSection
An iOS-style container for a scrollable view.
CupertinoListTile
An iOS-style tile that makes up a row in a list.
CupertinoTimerPicker
An iOS-style countdown timer picker.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/cupertino/index.html |
59b97bad2f4e-0 | Widget catalog
UI
Widgets
Create beautiful apps faster with Flutter’s collection of visual, structural,
platform, and interactive widgets. In addition to browsing widgets by category,
you can also see all the widgets in the widget index.
Accessibility
Make your app accessible.
Visit
Animation and Motion
Bring animations to your app.
Visit
Assets, Images, and Icons
Manage assets, display images, and show icons.
Visit
Async
Async patterns to your Flutter application.
Visit
Basics
Widgets you absolutely need to know before building your first Flutter app.
Visit
Cupertino (iOS-style widgets) | https://docs.flutter.dev/development/ui/widgets/index.html |
59b97bad2f4e-1 | Visit
Cupertino (iOS-style widgets)
Beautiful and high-fidelity widgets for current iOS design language.
Visit
Input
Take user input in addition to input widgets in Material Components and Cupertino.
Visit
Interaction Models
Respond to touch events and route users to different views.
Visit
Layout
Arrange other widgets columns, rows, grids, and many other layouts.
Visit
Material Components
Visual, behavioral, and motion-rich widgets implementing the Material Design guidelines.
Visit
Painting and effects
These widgets apply visual effects to the children without changing their layout, size, or position.
Visit
Scrolling | https://docs.flutter.dev/development/ui/widgets/index.html |
59b97bad2f4e-2 | Visit
Scrolling
Scroll multiple widgets as children of the parent.
Visit
Styling
Manage the theme of your app, makes your app responsive to screen sizes, or add padding.
Visit
Text
Display and style text.
Visit
Widget of the Week
100+ short, 1 minute explainer videos to help you quickly get started with Flutter widgets.
See more Widget of the Weeks | https://docs.flutter.dev/development/ui/widgets/index.html |
53afa4f5091f-0 | Input widgets
UI
Widgets
Input
Take user input in addition to input widgets in Material Components and Cupertino.
See more widgets in the widget catalog.
Autocomplete
A widget for helping the user make a selection by entering some text and choosing from among a list of options.
Form
An optional container for grouping together multiple form field widgets (e.g. TextField widgets).
FormField
A single form field. This widget maintains the current state of the form field, so that updates and validation errors are visually reflected in the...
RawKeyboardListener
A widget that calls a callback whenever the user presses or releases a key on a keyboard.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/input/index.html |
448aef8d20a9-0 | Interaction model widgets
UI
Widgets
Interaction
Respond to touch events and route users to different views.
Touch interactions
Routing
See more widgets in the widget catalog.
Touch interactions
AbsorbPointer
A widget that absorbs pointers during hit testing. When absorbing is true, this widget prevents its subtree from receiving pointer events by terminating hit testing...
Dismissible
A widget that can be dismissed by dragging in the indicated direction. Dragging or flinging this widget in the DismissDirection causes the child to slide...
DragTarget
A widget that receives data when a Draggable widget is dropped. When a draggable is dragged on top of a drag target, the drag target...
Draggable | https://docs.flutter.dev/development/ui/widgets/interaction/index.html |
448aef8d20a9-1 | Draggable
A widget that can be dragged from to a DragTarget. When a draggable widget recognizes the start of a drag gesture, it displays a feedback...
DraggableScrollableSheet
A container for a Scrollable that responds to drag gestures by resizing the scrollable until a limit is reached, and then scrolling.
GestureDetector
A widget that detects gestures. Attempts to recognize gestures that correspond to its non-null callbacks. If this widget has a child, it defers to that...
IgnorePointer
A widget that is invisible during hit testing. When ignoring is true, this widget (and its subtree) is invisible to hit testing. It still consumes...
InteractiveViewer
A widget that enables pan and zoom interactions with its child.
LongPressDraggable
Makes its child draggable starting from long press.
Scrollable | https://docs.flutter.dev/development/ui/widgets/interaction/index.html |
448aef8d20a9-2 | Makes its child draggable starting from long press.
Scrollable
Scrollable implements the interaction model for a scrollable widget, including gesture recognition, but does not have an opinion about how the viewport, which actually displays...
Routing
Hero
A widget that marks its child as being a candidate for hero animations.
Navigator
A widget that manages a set of child widgets with a stack discipline. Many apps have a navigator near the top of their widget hierarchy...
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/interaction/index.html |
3ccd6e8a352b-0 | Layout widgets
UI
Widgets
Layout
Arrange other widgets columns, rows, grids, and many other layouts.
Single-child layout widgets
Multi-child layout widgets
Sliver widgets
See more widgets in the widget catalog.
Single-child layout widgets
Align
A widget that aligns its child within itself and optionally sizes itself based on the child's size.
AspectRatio
A widget that attempts to size the child to a specific aspect ratio.
Abc
Baseline
A widget that positions its child according to the child's baseline.
Center
A widget that centers its child within itself.
ConstrainedBox
A widget that imposes additional constraints on its child.
Container | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-1 | A widget that imposes additional constraints on its child.
Container
A convenience widget that combines common painting, positioning, and sizing widgets.
CustomSingleChildLayout
A widget that defers the layout of its single child to a delegate.
Expanded
A widget that expands a child of a Row, Column, or Flex.
FittedBox
Scales and positions its child within itself according to fit.
FractionallySizedBox
A widget that sizes its child to a fraction of the total available space. For more details about the layout algorithm, see RenderFractionallySizedOverflowBox.
IntrinsicHeight
A widget that sizes its child to the child's intrinsic height.
IntrinsicWidth
A widget that sizes its child to the child's intrinsic width.
LimitedBox | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-2 | LimitedBox
A box that limits its size only when it's unconstrained.
Offstage
A widget that lays the child out as if it was in the tree, but without painting anything, without making the child available for hit...
OverflowBox
A widget that imposes different constraints on its child than it gets from its parent, possibly allowing the child to overflow the parent.
Padding
A widget that insets its child by the given padding.
SizedBox
A box with a specified size. If given a child, this widget forces its child to have a specific width and/or height (assuming values are...
SizedOverflowBox
A widget that is a specific size but passes its original constraints through to its child, which will probably overflow.
Transform
A widget that applies a transformation before painting its child.
Multi-child layout widgets
Column | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-3 | Multi-child layout widgets
Column
Layout a list of child widgets in the vertical direction.
CustomMultiChildLayout
A widget that uses a delegate to size and position multiple children.
Flow
A widget that implements the flow layout algorithm.
GridView
A grid list consists of a repeated pattern of cells arrayed in a vertical and horizontal layout. The GridView widget implements this component.
IndexedStack
A Stack that shows a single child from a list of children.
LayoutBuilder
Builds a widget tree that can depend on the parent widget's size.
ListBody
A widget that arranges its children sequentially along a given axis, forcing them to the dimension of the parent in the other axis.
ListView | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-4 | ListView
A scrollable, linear list of widgets. ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction....
Row
Layout a list of child widgets in the horizontal direction.
Stack
This class is useful if you want to overlap several children in a simple way, for example having some text and an image, overlaid with...
Table
A widget that uses the table layout algorithm for its children.
Wrap
A widget that displays its children in multiple horizontal or vertical runs.
Sliver widgets
CupertinoSliverNavigationBar
An iOS-styled navigation bar with iOS-11-style large titles using slivers.
CustomScrollView
A ScrollView that creates custom scroll effects using slivers.
SliverAppBar
A material design app bar that integrates with a CustomScrollView. | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-5 | A material design app bar that integrates with a CustomScrollView.
SliverChildBuilderDelegate
A delegate that supplies children for slivers using a builder callback.
SliverChildListDelegate
A delegate that supplies children for slivers using an explicit list.
SliverFixedExtentList
A sliver that places multiple box children with the same main axis extent in a linear array.
SliverGrid
A sliver that places multiple box children in a two dimensional arrangement.
SliverList
A sliver that places multiple box children in a linear array along the main axis.
SliverPadding
A sliver that applies padding on each side of another sliver.
SliverPersistentHeader
A sliver whose size varies when the sliver is scrolled to the edge of the viewport opposite the sliver's GrowthDirection.
SliverToBoxAdapter | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3ccd6e8a352b-6 | SliverToBoxAdapter
A sliver that contains a single box widget.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/layout/index.html |
3e17f54caa48-0 | Material Components widgets
UI
Widgets
Material
Visual, behavioral, and motion-rich widgets implementing the Material Design guidelines.
App structure and navigation
Buttons
Input and selections
Dialogs, alerts, and panels
Information displays
Layout
See more widgets in the widget catalog.
App structure and navigation
AppBar
A Material Design app bar. An app bar consists of a toolbar and potentially other widgets, such as a TabBar and a FlexibleSpaceBar.
BottomNavigationBar
Bottom navigation bars make it easy to explore and switch between top-level views in a single tap. The BottomNavigationBar widget implements this component.
Drawer | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-1 | Drawer
A Material Design panel that slides in horizontally from the edge of a Scaffold to show navigation links in an application.
MaterialApp
A convenience widget that wraps a number of widgets that are commonly required for applications implementing Material Design.
Scaffold
Implements the basic Material Design visual layout structure. This class provides APIs for showing drawers, snack bars, and bottom sheets.
SliverAppBar
A material design app bar that integrates with a CustomScrollView.
TabBar
A Material Design widget that displays a horizontal row of tabs.
TabBarView
A page view that displays the widget which corresponds to the currently selected tab. Typically used in conjunction with a TabBar.
TabController
Coordinates tab selection between a TabBar and a TabBarView.
TabPageSelector | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-2 | TabPageSelector
Displays a row of small circular indicators, one per tab. The selected tab's indicator is highlighted. Often used in conjunction with a TabBarView.
WidgetsApp
A convenience class that wraps a number of widgets that are commonly required for an application.
Buttons
DropdownButton
Shows the currently selected item and an arrow that opens a menu for selecting another item.
ElevatedButton
A Material Design elevated button. A filled button whose material elevates when pressed.
FloatingActionButton
A floating action button is a circular icon button that hovers over content to promote a primary action in the application. Floating action buttons are...
IconButton
An icon button is a picture printed on a Material widget that reacts to touches by filling with color (ink).
OutlinedButton | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-3 | OutlinedButton
A Material Design outlined button, essentially a TextButton with an outlined border.
PopupMenuButton
Displays a menu when pressed and calls onSelected when the menu is dismissed because an item was selected.
TextButton
A Material Design text button. A simple flat button without a border outline.
Input and selections
Checkbox
Checkboxes allow the user to select multiple options from a set. The Checkbox widget implements this component.
Date & Time Pickers
Date pickers use a dialog window to select a single date on mobile. Time pickers use a dialog to select a single time (in the...
Radio
Radio buttons allow the user to select one option from a set. Use radio buttons for exclusive selection if you think that the user needs...
Slider
Sliders let users select from a range of values by moving the slider thumb.
Switch | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-4 | Switch
On/off switches toggle the state of a single settings option. The Switch widget implements this component.
TextField
Touching a text field places the cursor and displays the keyboard. The TextField widget implements this component.
Dialogs, alerts, and panels
AlertDialog
Alerts are urgent interruptions requiring acknowledgement that inform the user about a situation. The AlertDialog widget implements this component.
BottomSheet
Bottom sheets slide up from the bottom of the screen to reveal more content. You can call showBottomSheet() to implement a persistent bottom sheet or...
ExpansionPanel
Expansion panels contain creation flows and allow lightweight editing of an element. The ExpansionPanel widget implements this component.
SimpleDialog
Simple dialogs can provide additional details or actions about a list item. For example they can display avatars icons clarifying subtext or orthogonal actions (such... | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-5 | SnackBar
A lightweight message with an optional action which briefly displays at the bottom of the screen.
Information displays
Card
A Material Design card. A card has slightly rounded corners and a shadow.
Chip
A Material Design chip. Chips represent complex entities in small blocks, such as a contact.
CircularProgressIndicator
A material design circular progress indicator, which spins to indicate that the application is busy.
DataTable
Data tables display sets of raw data. They usually appear in desktop enterprise products. The DataTable widget implements this component.
GridView
A grid list consists of a repeated pattern of cells arrayed in a vertical and horizontal layout. The GridView widget implements this component.
Icon
A Material Design icon.
Image
A widget that displays an image.
LinearProgressIndicator | https://docs.flutter.dev/development/ui/widgets/material/index.html |
3e17f54caa48-6 | A widget that displays an image.
LinearProgressIndicator
A material design linear progress indicator, also known as a progress bar.
Tooltip
Tooltips provide text labels that help explain the function of a button or other user interface action. Wrap the button in a Tooltip widget to...
Layout
Divider
A one logical pixel thick horizontal line, with padding on either side.
ListTile
A single fixed-height row that typically contains some text as well as a leading or trailing icon.
Stepper
A Material Design stepper widget that displays progress through a sequence of steps.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/material/index.html |
b683928f54c2-0 | Painting and effect widgets
UI
Widgets
Painting
These widgets apply visual effects to the children without changing their layout, size, or position.
See more widgets in the widget catalog.
BackdropFilter
A widget that applies a filter to the existing painted content and then paints a child. This effect is relatively expensive, especially if the filter...
ClipOval
A widget that clips its child using an oval.
ClipPath
A widget that clips its child using a path.
ClipRect
A widget that clips its child using a rectangle.
CustomPaint
A widget that provides a canvas on which to draw during the paint phase.
DecoratedBox
A widget that paints a Decoration either before or after its child paints. | https://docs.flutter.dev/development/ui/widgets/painting/index.html |
b683928f54c2-1 | A widget that paints a Decoration either before or after its child paints.
FractionalTranslation
A widget that applies a translation expressed as a fraction of the box's size before painting its child.
Opacity
A widget that makes its child partially transparent.
RotatedBox
A widget that rotates its child by a integral number of quarter turns.
Transform
A widget that applies a transformation before painting its child.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/painting/index.html |
d551d886bfd0-0 | Scrolling widgets
UI
Widgets
Scrolling
Scroll multiple widgets as children of the parent.
See more widgets in the widget catalog.
CustomScrollView
A ScrollView that creates custom scroll effects using slivers.
DraggableScrollableSheet
A container for a Scrollable that responds to drag gestures by resizing the scrollable until a limit is reached, and then scrolling.
GridView
A grid list consists of a repeated pattern of cells arrayed in a vertical and horizontal layout. The GridView widget implements this component.
ListView
A scrollable, linear list of widgets. ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction....
NestedScrollView
A scrolling view inside of which can be nested other scrolling views, with their scroll positions being intrinsically linked.
NotificationListener | https://docs.flutter.dev/development/ui/widgets/scrolling/index.html |
d551d886bfd0-1 | NotificationListener
A widget that listens for Notifications bubbling up the tree.
PageView
A scrollable list that works page by page.
RefreshIndicator
A Material Design pull-to-refresh wrapper for scrollables.
ReorderableListView
A list whose items the user can interactively reorder by dragging.
ScrollConfiguration
Controls how Scrollable widgets behave in a subtree.
Scrollable
Scrollable implements the interaction model for a scrollable widget, including gesture recognition, but does not have an opinion about how the viewport, which actually displays...
Scrollbar
A Material Design scrollbar. A scrollbar indicates which portion of a Scrollable widget is actually visible.
SingleChildScrollView
A box in which a single widget can be scrolled. This widget is useful when you have a single box that will normally be entirely... | https://docs.flutter.dev/development/ui/widgets/scrolling/index.html |
d551d886bfd0-2 | See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/scrolling/index.html |
625d695a6613-0 | Styling widgets
UI
Widgets
Styling
Manage the theme of your app, makes your app responsive to screen sizes, or add padding.
See more widgets in the widget catalog.
MediaQuery
Establishes a subtree in which media queries resolve to the given data.
Padding
A widget that insets its child by the given padding.
Theme
Applies a theme to descendant widgets. A theme describes the colors and typographic choices of an application.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/styling/index.html |
08e093950e6f-0 | Text widgets
UI
Widgets
Text
Display and style text.
See more widgets in the widget catalog.
DefaultTextStyle
The text style to apply to descendant Text widgets without explicit style.
RichText
The RichText widget displays text that uses multiple different styles. The text to display is described using a tree of TextSpan objects, each of which...
Abc
Text
A run of text with a single style.
See more widgets in the widget catalog. | https://docs.flutter.dev/development/ui/widgets/text/index.html |
c39f5d1e7e25-0 | Introduction to widgets
UI
Introduction to widgets
Flutter widgets are built using a modern framework that takes
inspiration from React. The central idea is that you build
your UI out of widgets. Widgets describe what their view
should look like given their current configuration and state.
When a widget’s state changes, the widget rebuilds its description,
which the framework diffs against the previous description in order
to determine the minimal changes needed in the underlying render
tree to transition from one state to the next.
Note:
If you would like to become better acquainted with Flutter by diving
into some code, check out basic layout codelab,
building layouts,
and adding interactivity to your Flutter app.
Hello world
The minimal Flutter app simply calls the runApp()
function with a widget: | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-1 | The minimal Flutter app simply calls the runApp()
function with a widget:
The runApp() function takes the given
Widget and makes it the root of the widget tree.
In this example, the widget tree consists of two widgets,
the Center widget and its child, the Text widget.
The framework forces the root widget to cover the screen,
which means the text “Hello, world” ends up centered on screen.
The text direction needs to be specified in this instance;
when the MaterialApp widget is used,
this is taken care of for you, as demonstrated later.
When writing an app, you’ll commonly author new widgets that
are subclasses of either StatelessWidget or StatefulWidget,
depending on whether your widget manages any state.
A widget’s main job is to implement a build() function,
which describes the widget in terms of other, lower-level widgets.
The framework builds those widgets in turn until the process
bottoms out in widgets that represent the underlying RenderObject,
which computes and describes the geometry of the widget. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-2 | Basic widgets
Flutter comes with a suite of powerful basic widgets,
of which the following are commonly used:
Text
The Text widget lets you create a run of styled text
within your application.
Row,
Column
These flex widgets let you create flexible layouts in
both the horizontal (Row) and vertical (Column) directions.
The design of these objects is based on the web’s
flexbox layout model.
Stack
Instead of being linearly oriented (either horizontally or vertically),
a Stack widget lets you place widgets on top of each other in paint order.
You can then use the Positioned widget on children of a
Stack to position them relative to the top, right, bottom,
or left edge of the stack. Stacks are based on the web’s
absolute positioning layout model.
Container | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-3 | Container
The Container widget lets you create a rectangular visual element.
A container can be decorated with a BoxDecoration, such as a
background, a border, or a shadow. A Container can also have margins,
padding, and constraints applied to its size. In addition, a
Container can be transformed in three dimensional space using a matrix.
Below are some simple widgets that combine these and other widgets:
Be sure to have a uses-material-design: true entry in the flutter
section of your pubspec.yaml file. It allows you to use the predefined
set of Material icons. It’s generally a good idea to include this line
if you are using the Materials library.
name
my_app
flutter
uses-material-design
true
Many Material Design widgets need to be inside of a MaterialApp
to display properly, in order to inherit theme data.
Therefore, run the application with a MaterialApp. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-4 | Container with a height of 56
device-independent pixels with an internal padding of 8 pixels,
both on the left and the right. Inside the container,
Row layout to organize its children.
The middle child, the
Expanded,
which means it expands to fill any remaining available space
that hasn’t been consumed by the other children.
You can have multiple
flex argument to
The MyScaffold widget organizes its children in a vertical column.
At the top of the column it places an instance of MyAppBar,
passing the app bar a Text widget to use as its title.
Passing widgets as arguments to other widgets is a powerful technique
that lets you create generic widgets that can be reused in a wide
variety of ways. Finally, MyScaffold uses an
Expanded to fill the remaining space with its body,
which consists of a centered message.
For more information, see Layouts.
Using Material Components | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-5 | For more information, see Layouts.
Using Material Components
Flutter provides a number of widgets that help you build apps
that follow Material Design. A Material app starts with the
MaterialApp widget, which builds a number of useful widgets
at the root of your app, including a Navigator,
which manages a stack of widgets identified by strings,
also known as “routes”. The Navigator lets you transition smoothly
between screens of your application. Using the MaterialApp
widget is entirely optional but a good practice.
Now that the code has switched from MyAppBar and MyScaffold to the
AppBar and Scaffold widgets, and from material.dart,
the app is starting to look a bit more Material.
For example, the app bar has a shadow and the title text inherits the
correct styling automatically. A floating action button is also added.
Scaffold widget takes a number of different widgets as
named arguments, each of which are placed in the | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-6 | AppBar widget lets you pass in widgets for the
leading widget, and the
actions of the
title widget.
This pattern recurs throughout the framework and is something you
might consider when designing your own widgets.
For more information, see Material Components widgets.
Note:
Material is one of the 2 bundled designs included with Flutter.
To create an iOS-centric design,
see the Cupertino components package,
which has its own versions of
CupertinoApp, and CupertinoNavigationBar.
Handling gestures
Most applications include some form of user interaction with the system.
The first step in building an interactive application is to detect
input gestures. See how that works by creating a simple button: | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-7 | The GestureDetector widget doesn’t have a visual
representation but instead detects gestures made by the
user. When the user taps the Container,
the GestureDetector calls its onTap() callback, in this
case printing a message to the console. You can use
GestureDetector to detect a variety of input gestures,
including taps, drags, and scales.
Many widgets use a GestureDetector to provide
optional callbacks for other widgets. For example, the
IconButton, ElevatedButton, and
FloatingActionButton widgets have onPressed()
callbacks that are triggered when the user taps the widget.
For more information, see Gestures in Flutter.
Changing widgets in response to input
So far, this page has used only stateless widgets.
Stateless widgets receive arguments from their parent widget,
which they store in final member variables.
When a widget is asked to build(), it uses these stored
values to derive new arguments for the widgets it creates. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-8 | In order to build more complex experiences—for example,
to react in more interesting ways to user input—applications
typically carry some state. Flutter uses StatefulWidgets to capture
this idea. StatefulWidgets are special widgets that know how to generate
State objects, which are then used to hold state.
Consider this basic example, using the ElevatedButton mentioned earlier:
You might wonder why StatefulWidget and State are separate objects.
In Flutter, these two types of objects have different life cycles.
Widgets are temporary objects, used to construct a presentation of
the application in its current state. State objects, on the other
hand, are persistent between calls to
build(), allowing them to remember information. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-9 | The example above accepts user input and directly uses
the result in its build() method. In more complex applications,
different parts of the widget hierarchy might be
responsible for different concerns; for example, one
widget might present a complex user interface
with the goal of gathering specific information,
such as a date or location, while another widget might
use that information to change the overall presentation.
In Flutter, change notifications flow “up” the widget
hierarchy by way of callbacks, while current state flows
“down” to the stateless widgets that do presentation.
The common parent that redirects this flow is the State.
The following slightly more complex example shows how
this works in practice:
Notice the creation of two new stateless widgets,
cleanly separating the concerns of displaying the counter
(CounterDisplay) and changing the counter (CounterIncrementor).
Although the net result is the same as the previous example,
the separation of responsibility allows greater complexity to
be encapsulated in the individual widgets,
while maintaining simplicity in the parent. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-10 | For more information, see:
StatefulWidget
setState()
Bringing it all together
What follows is a more complete example that brings together
these concepts: A hypothetical shopping application displays various
products offered for sale, and maintains a shopping cart for
intended purchases. Start by defining the presentation class,
ShoppingListItem:
The ShoppingListItem widget follows a common pattern
for stateless widgets. It stores the values it receives
in its constructor in final member variables,
which it then uses during its build() function.
For example, the inCart boolean toggles between two visual
appearances: one that uses the primary color from the current
theme, and another that uses gray. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-11 | When the user taps the list item, the widget doesn’t modify
its inCart value directly. Instead, the widget calls the
onCartChanged function it received from its parent widget.
This pattern lets you store state higher in the widget
hierarchy, which causes the state to persist for longer periods of time.
In the extreme, the state stored on the widget passed to
runApp() persists for the lifetime of the
application.
When the parent receives the onCartChanged callback,
the parent updates its internal state, which triggers
the parent to rebuild and create a new instance
of ShoppingListItem with the new inCart value.
Although the parent creates a new instance of
ShoppingListItem when it rebuilds, that operation is cheap
because the framework compares the newly built widgets with the previously
built widgets and applies only the differences to the underlying
RenderObject.
Here’s an example parent widget that stores mutable state:
StatefulWidget,
which means this widget stores mutable state.
When the | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-12 | StatefulWidget,
which means this widget stores mutable state.
When the
createState() function
to create a fresh instance of
State are typically named with leading underscores to
indicate that they are private implementation details.)
When this widget’s parent rebuilds, the parent creates a new instance
of
widget property.
If the parent rebuilds and creates a new
didUpdateWidget() function, which is passed
an
setState() call.
Calling
build() function,
which means the user interface might not update to reflect
the changed state. By managing state in this way,
you don’t need to write separate code for creating and
updating child widgets. Instead, you simply implement the
Responding to widget lifecycle events
createState() on the
initState() on the state object.
A subclass of
State can override | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-13 | State can override
When a state object is no longer needed,
the framework calls dispose() on the state object.
Override the dispose function to do cleanup work.
For example, override dispose to cancel timers or to
unsubscribe from platform services. Implementations of
dispose typically end by calling super.dispose.
For more information, see State.
Keys
Use keys to control which widgets the framework matches up
with other widgets when a widget rebuilds. By default, the
framework matches widgets in the current and previous build
according to their runtimeType and the order in which they appear.
With keys, the framework requires that the two widgets have
the same key as well as the same runtimeType.
Keys are most useful in widgets that build many instances of
the same type of widget. For example, the ShoppingList widget,
which builds just enough ShoppingListItem instances to
fill its visible region: | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-14 | Without keys, the first entry in the current build
would always sync with the first entry in the previous build,
even if, semantically, the first entry in the list just
scrolled off screen and is no longer visible in the viewport.
By assigning each entry in the list a “semantic” key,
the infinite list can be more efficient because the
framework syncs entries with matching semantic keys
and therefore similar (or identical) visual appearances.
Moreover, syncing the entries semantically means that
state retained in stateful child widgets remains attached
to the same semantic entry rather than the entry in the
same numerical position in the viewport.
For more information, see the Key API.
Global keys
Use global keys to uniquely identify child widgets.
Global keys must be globally unique across the entire
widget hierarchy, unlike local keys which need
only be unique among siblings. Because they are
globally unique, a global key can be used to
retrieve the state associated with a widget. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
c39f5d1e7e25-15 | For more information, see the GlobalKey API. | https://docs.flutter.dev/development/ui/widgets-intro/index.html |
704aa249a9b4-0 | Embedded support for Flutter
If you would like to embed Flutter engine into a car,
a refrigerator, a thermostat… you CAN! For example,
you might embed Flutter in the following situations:
Using Flutter on an “embedded device”,
typically a low-powered hardware device
such as a smart-display, a thermostat, or similar.
Embedding Flutter into a new operating system or
environment, for example a new mobile platform
or a new operating system.
The ability to embed Flutter, while stable,
uses low-level API and is not for beginners.
In addition to the resources listed below, you
might consider joining Discord, where Flutter
developers (including Google engineers) discuss
various aspects of Flutter. The Flutter
community page has info on more community
resources.
Custom Flutter Engine Embedders, on the Flutter wiki. | https://docs.flutter.dev/embedded/index.html |
704aa249a9b4-1 | Custom Flutter Engine Embedders, on the Flutter wiki.
The doc comments in the
Flutter engine embedder.h file on GitHub.
The Flutter architectural overview on docs.flutter.dev.
A small, self contained Flutter Embedder Engine GLFW example
in the Flutter engine GitHub repo.
Issue 31043: Questions for porting flutter engine to
a new os might also be helpful. | https://docs.flutter.dev/embedded/index.html |
0f0424db4f86-0 | Test drive
Learn more
Write your first Flutter app
Get started
Write your first app
You are now ready to start the “First Flutter app” codelab.
In about an hour and a half,
you will learn the basics of Flutter
by creating an app
that works on mobile, desktop, and web.
▶ Start codelab
Tip:
The codelab above walks you through writing your first Flutter
app for all platforms — mobile, desktop and web.
You might prefer to take
another codelab written specifically for the web.
If you prefer an instructor-led version of this codelab,
check out the following workshop:
Test drive
Learn more | https://docs.flutter.dev/get-started/codelab/index.html |
a70a020710a3-0 | Write your first Flutter app on the web
Get started
Write your first web app
Step 0: Get the starter web app
Step 1: Show the Welcome screen
Step 2: Enable sign in progress tracking
Step 2.5: Launch Dart DevTools
Step 3: Add animation for sign in progress
Complete sample
What next?
Tip:
This codelab walks you through writing
your first Flutter app on the web, specifically.
You might prefer to try
another codelab
that takes a more generic approach.
Note that the codelab on this page
does work on mobile and desktop
once you download and configure the appropriate tooling. | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-1 | This is a guide to creating your first Flutter web app.
If you are familiar with object-oriented programming,
and concepts such as variables, loops, and conditionals,
you can complete this tutorial.
You don’t need previous experience with Dart,
mobile, or web programming.
What you’ll build
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.
What you’ll learn
How to write a Flutter app that looks natural on the web. | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-2 | How to write a Flutter app that looks natural on the web.
Basic structure of a Flutter app.
How to implement a Tween animation.
How to implement a stateful widget.
How to use the debugger to set breakpoints.
What you'll use
You need three pieces of software to complete this lab:
Flutter SDK
Chrome browser
Text editor or IDE
While developing, run your web app in Chrome
so you can debug with Dart DevTools.
Step 0: Get the starter web app
You’ll start with a simple web app that we provide for you.
Enable web development.
At the command line, perform the following command to
make sure that you have Flutter installed correctly. | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-3 | $ 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. | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-4 | 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.
List the devices.
To ensure that web is installed,
list the devices available.
You should see something like the following:
$ flutter devices
4 connected devices: | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-5 | $ 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. | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-6 | The starting app is displayed in the following DartPad.
{$ begin main.dart $}
import 'package:flutter/material.dart';
void main() => runApp(const SignUpApp());
class SignUpApp extends StatelessWidget {
const SignUpApp();
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/': (context) => const SignUpScreen(),
},
);
}
}
class SignUpScreen extends StatelessWidget {
const SignUpScreen();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
body: const Center(
child: SizedBox(
width: 400,
child: Card(
child: SignUpForm(),
),
),
),
);
}
} | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-7 | class SignUpForm extends StatefulWidget {
const SignUpForm();
@override
State<SignUpForm> createState() => _SignUpFormState();
}
class _SignUpFormState extends State<SignUpForm> {
final _firstNameTextController = TextEditingController();
final _lastNameTextController = TextEditingController();
final _usernameTextController = TextEditingController();
double _formProgress = 0; | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-8 | @override
Widget build(BuildContext context) {
return Form(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
LinearProgressIndicator(value: _formProgress),
Text('Sign up', style: Theme.of(context).textTheme.headlineMedium),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _firstNameTextController,
decoration: const InputDecoration(hintText: 'First name'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _lastNameTextController, | https://docs.flutter.dev/get-started/codelab-web/index.html |
a70a020710a3-9 | controller: _lastNameTextController,
decoration: const InputDecoration(hintText: 'Last name'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _usernameTextController,
decoration: const InputDecoration(hintText: 'Username'),
),
),
TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) {
return states.contains(MaterialState.disabled)
? null
: Colors.white;
}),
backgroundColor: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) { | https://docs.flutter.dev/get-started/codelab-web/index.html |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.