id
stringlengths
14
17
text
stringlengths
23
1.11k
source
stringlengths
35
114
770dd48484f7-1
Flutter is different from other frameworks because its UI is built in code, not (for example) in an XML file or similar. Widgets are the basic building blocks of a Flutter UI. As you progress through this codelab, you’ll learn that almost everything in Flutter is a widget. A widget is an immutable object that describes...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-2
1. Click the Run button. 2. In the code, change the Row to a Column, and run again. Axis size and alignment So far, the BlueBox widgets have been squished together (either to the left or at the top of the UI Output). You can change how the BlueBox widgets are spaced out using the axis size and alignment properties. ...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-3
Tip: MainAxisSize.max is the mainAxisSize property’s default value. If you don’t specify another value, the default value is used, as shown in the previous example. Example: Modifying axis size The following example explicitly sets mainAxisSize to its default value, MainAxisSize.max. 1. Click the Run butto...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-4
Divides the extra space evenly between children and before and after the children. Similar to MainAxisAlignment.spaceEvenly, but reduces half of the space before the first child and after the last child to half of the width between the children. Example: Modifying main axis alignment The following example explicitly...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-5
Positions children at the middle of the cross axis. (Middle for Row, Center for Column) Stretches children across the cross axis. (Top-to-bottom for Row, left-to-right for Column) Aligns children by their character baselines. (Text class only, and requires that the textBaseline property is set to TextBaseline.alphabe...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-6
Tip: Before moving to the next section, change CrossAxisAlignment.start to another value. Flexible widget Compares itself against other flex properties before determining what fraction of the total remaining space each Flexible widget receives. Determines whether a Flexible widget fills all of its extra space. ...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-7
Example: Testing flex values When flex properties are compared against one another, the ratio between their flex values determines what fraction of the total remaining space each Flexible widget receives. remainingSpace flex totalOfAllFlexValues In this example, the sum of the flex values (2), determines t...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-8
1. Click the Run button. 2. Wrap the second BlueBox widget in an Expanded widget. For example: Expanded child: BlueBox (),), 3. Select the Format button to properly format the code, and run again. SizedBox widget Example: Resizing a widget The following example wraps the middle BlueBox widget inside ...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-9
Example: Creating space The following example contains three BlueBox widgets and one SizedBox widget that separates the first and second BlueBox widgets. The SizedBox widget contains a width property equal to 50 logical pixels. 1. Click the Run button. 2. Create more space by adding another SizedBox w...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-10
Text widget The Text widget displays text and can be configured for different fonts, sizes, and colors. Example: Aligning text The following example displays “Hey!” three times, but at different font sizes and in different colors. Row specifies the crossAxisAlignment and textBaseline properties. 1. Click the ...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-11
3. Give the Icon a color of Colors.amber from the Material Color palette, and run again. Image widget The Image widget displays an image. You either can reference images using a URL, or you can include images inside your app package. Since DartPad can’t package an image, the following example uses an image f...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-12
3. Then change pic1.jpg to pic2.jpg or pic3.jpg, and run again. Putting it all together You’re almost at the end of this codelab. If you’d like to test your knowledge of the techniques that you’ve learned, why not apply those skills into building a Flutter UI that displays a business card! You’ll break down...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-13
Part 1 Exercise: Create the name and title Implement a Column that contains two text widgets: The first Text widget has the name Flutter McFlutter and the style property set to Theme.of(context).textTheme.headlineSmall. The second Text widget contains the title Experienced App Developer. For the Column, set ma...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-14
The Row should look like this: Row children: Padding padding: const EdgeInsets all 8.0 ), child: Icon Icons account_circle size: 50 ), ), Column ... ), // <--- The Column you first implemented ], ); Part 2 Exercise: Tweak the layout A SizedBox widget with a height of 8. An empty Row where you...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-15
A second SizedBox widget with a height of 16. A second empty Row where you’ll add four icons (Part 3). The Column’s list of widgets should be formatted as follows, so the contact information and icons are displayed below the name and title: ], ), // <--- Closing parenthesis for the Row SizedBox (), Row (),...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-16
Enter two Text widgets inside the first empty Row : The first Text widget contains the address 123 Main Street. The second Text widget contains the phone number (415) 555-0198. For the first empty Row, set the mainAxisAlignment property to MainAxisAlignment.spaceBetween. Part 3 Exercise: Add four icons Enter ...
https://docs.flutter.dev/codelabs/layout-basics/index.html
770dd48484f7-17
What’s next? Congratulations, you’ve finished this codelab! If you’d like to know more about Flutter, here are a few suggestions for resources worth exploring: Learn more about layouts in Flutter by visiting the Building layouts page. Check out the sample apps. Visit Flutter’s YouTube channel, where you can watch a...
https://docs.flutter.dev/codelabs/layout-basics/index.html
e3783a92f014-0
Using Flutter in China Configuring Flutter to use a mirror site Community-run mirror sites The Flutter community has made a Simplified Chinese version of the Flutter website available at https://flutter.cn. If you’d like to install Flutter using an installation bundle, you can replace the domain of the original UR...
https://docs.flutter.dev/community/china/index.html
e3783a92f014-1
Important: Use mirror sites only if you trust the provider. The Flutter team cannot verify their reliability or security. Configuring Flutter to use a mirror site If you’re installing or using Flutter in China, it may be helpful to use a trustworthy local mirror site that hosts Flutter’s dependencies. To instruct...
https://docs.flutter.dev/community/china/index.html
e3783a92f014-2
export FLUTTER_STORAGE_BASE_URL =https://storage.flutter-io.cn git clone b dev https://github.com/flutter/flutter.git export PATH $PWD /flutter/bin: $PATH cd ./flutter flutter doctor After these steps, you should be able to continue setting up Flutter normally. From here on, packages fetched by flutter pub ...
https://docs.flutter.dev/community/china/index.html
e3783a92f014-3
The flutter-io.cn server is a provisional mirror for Flutter dependencies and packages maintained by GDG China. The Flutter team cannot guarantee long-term availability of this service. You’re free to use other mirrors if they become available. If you’re interested in setting up your own mirror in China, contact flutte...
https://docs.flutter.dev/community/china/index.html
59721f97162f-0
Animate a widget using a physics simulation Fade a widget in and out Animate the properties of a container Cookbook Animation Animate the properties of a container 1. Create a StatefulWidget with default properties 2. Build an AnimatedContainer using the properties 3. Start the animation by rebuilding with new ...
https://docs.flutter.dev/cookbook/animation/animated-container/index.html
59721f97162f-1
To animate these properties, Flutter provides the AnimatedContainer widget. Like the Container widget, AnimatedContainer allows you to define the width, height, background colors, and more. However, when the AnimatedContainer is rebuilt with new properties, it automatically animates between the old and new values. In F...
https://docs.flutter.dev/cookbook/animation/animated-container/index.html
59721f97162f-2
These properties belong to a custom State class so they can be updated when the user taps a button. 2. Build an AnimatedContainer using the properties Next, build the AnimatedContainer using the properties defined in the previous step. Furthermore, provide a duration that defines how long the animation should run. 3...
https://docs.flutter.dev/cookbook/animation/animated-container/index.html
59721f97162f-3
Interactive example Animate a widget using a physics simulation Fade a widget in and out
https://docs.flutter.dev/cookbook/animation/animated-container/index.html
1295cc44d657-0
Animation Cookbook Animation Animate a page route transition Animate a widget using a physics simulation Animate the properties of a container Fade a widget in and out
https://docs.flutter.dev/cookbook/animation/index.html
5d3b34bf6dd4-0
Animate the properties of a container Add a drawer to a screen Fade a widget in and out Cookbook Animation Fade a widget in and out 1. Create a box to fade in and out 2. Define a StatefulWidget 3. Display a button that toggles the visibility 4. Fade the box in and out Interactive example UI developers often ...
https://docs.flutter.dev/cookbook/animation/opacity-animation/index.html
5d3b34bf6dd4-1
Define a StatefulWidget. Display a button that toggles the visibility. Fade the box in and out. 1. Create a box to fade in and out First, create something to fade in and out. For this example, draw a green box on screen. 2. Define a StatefulWidget Now that you have a green box to animate, you need a way to know w...
https://docs.flutter.dev/cookbook/animation/opacity-animation/index.html
5d3b34bf6dd4-2
To construct a StatefulWidget, create two classes: A StatefulWidget and a corresponding State class. Pro tip: The Flutter plugins for Android Studio and VSCode include the stful snippet to quickly generate this code. 3. Display a button that toggles the visibility Now that you have some data to determine whether the ...
https://docs.flutter.dev/cookbook/animation/opacity-animation/index.html
5d3b34bf6dd4-3
4. Fade the box in and out You have a green box on screen and a button to toggle the visibility to true or false. How to fade the box in and out? With an AnimatedOpacity widget. The AnimatedOpacity widget requires three arguments: opacity: A value from 0.0 (invisible) to 1.0 (fully visible). duration: How long the ...
https://docs.flutter.dev/cookbook/animation/opacity-animation/index.html
edd81e24fde3-0
Animate a widget using a physics simulation Animate a page route transition Cookbook Animation Animate a page route transition 1. Set up a PageRouteBuilder 2. Create a Tween 3. Use an AnimatedWidget 4. Use a CurveTween 5. Combine the two Tweens Interactive example A design language, such as Material, defines...
https://docs.flutter.dev/cookbook/animation/page-route-animation/index.html
edd81e24fde3-1
To create a custom page route transition, this recipe uses the following steps: Set up a PageRouteBuilder Create a Tween Add an AnimatedWidget Use a CurveTween Combine the two Tweens 1. Set up a PageRouteBuilder To start, use a PageRouteBuilder to create a Route. PageRouteBuilder has two callbacks, one to build ...
https://docs.flutter.dev/cookbook/animation/page-route-animation/index.html
edd81e24fde3-2
2. Create a Tween To make the new page animate in from the bottom, it should animate from Offset(0,1) to Offset(0, 0) (usually defined using the Offset.zero constructor). In this case, the Offset is a 2D vector for the ‘FractionalTranslation’ widget. Setting the dy argument to 1 represents a vertical translation one f...
https://docs.flutter.dev/cookbook/animation/page-route-animation/index.html
edd81e24fde3-3
AnimatedWidget Return a SlideTransition with the Animation<Offset> and the child widget: 4. Use a CurveTween Flutter provides a selection of easing curves that adjust the rate of the animation over time. The Curves class provides a predefined set of commonly used curves. For example, Curves.easeOut makes the animatio...
https://docs.flutter.dev/cookbook/animation/page-route-animation/index.html
edd81e24fde3-4
This new Tween (or Animatable) produces Offset values by first evaluating the CurveTween, then evaluating the Tween<Offset>. When the animation runs, the values are computed in this order: The animation (provided to the transitionsBuilder callback) produces values from 0 to 1. The CurveTween maps those values to new ...
https://docs.flutter.dev/cookbook/animation/page-route-animation/index.html
d50b441773ec-0
Animate a page route transition Animate the properties of a container Animate a widget using a physics simulation Cookbook Animation Animate a widget using a physics simulation Step 1: Set up an animation controller Step 2: Move the widget using gestures Step 3: Animate the widget Step 4: Calculate the velocit...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-1
Move the widget using gestures Animate the widget Calculate the velocity to simulate a springing motion Step 1: Set up an animation controller Start with a stateful widget called DraggableCard: SingleTickerProviderStateMixin. Then construct an AnimationController in TickerProvider. lib/{starter.dart → step1.dar...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-2
32 + with SingleTickerProviderStateMixin { 33 + late AnimationController _controller; 34 32 35 @override 33 36 void initState() { 34 37 super.initState(); 38 + _controller = 39 + AnimationController(vsync: this, duration: const Duration(sec...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-3
43 + _controller.dispose(); 38 44 super.dispose(); 39 45 Step 2: Move the widget using gestures Make the widget move when it’s dragged, and add an Alignment field to the _DraggableCardState class: lib/{step1.dart (alignment) → step2.dart (alignment)} @@ -1,3 +1,4 @@ 1 1 class _DraggableCardSta...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-4
GestureDetector that handles the MediaQuery to get the size of the widget, and divide by 2. (This converts units of “pixels dragged” to coordinates that Align uses.) Then, set the lib/{step1.dart (build) → step2.dart (build)} @@ -1,8 +1,22 @@ 1 1 @override 2 2 Widget build(BuildContext context) { return Align(...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-5
+ setState(() { + _dragAlignment += Alignment( + details.delta.dx / (size.width / 2), 10 + details.delta.dy / (size.height / 2), 11 + ); 12 + }); 13 + }, 14 + ...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-6
18 + child: widget.child, 19 + ), 6 20 ), 7 21 ); 8 22 Step 3: Animate the widget When the widget is released, it should spring back to the center. Add an Animation<Alignment> field and an _runAnimation method. This method defines a Tween that interpolates between the po...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-7
2 2 with SingleTickerProviderStateMixin { 3 3 late AnimationController _controller; + late Animation<Alignment> _animation; 4 5 Alignment _dragAlignment = Alignment.center; Next, update _dragAlignment when the AnimationController produces a value: lib/{step2.dart (initState) → step3.dart (initStat...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-8
+ setState(() { + _dragAlignment = _animation.value; + }); 10 + }); 6 11 Next, make the Align widget use the _dragAlignment field: Finally, update the GestureDetector to manage the animation controller: lib/{step2.dart (gesture) → step3.dart (gestu...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-9
onPanUpdate: (details) { 4 6 setState(() { 5 7 _dragAlignment += Alignment( @@ -8,7 +10,9 @@ 8 10 ); 9 11 }); 10 12 }, 11 onPanEnd: (details) {}, 13 + onPanEnd: (details) { 14 + _runAnimation(); 15 + }, 12 16 child: Align( 13 17 alignment: _dragAlignmen...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-10
13 17 alignment: _dragAlignment, 14 18 child: Card( Step 4: Calculate the velocity to simulate a springing motion The last step is to do a little math, to calculate the velocity of the widget after it’s finished being dragged. This is so that the widget realistically continues at that speed before being snapped ba...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
d50b441773ec-11
First, import the physics package: The onPanEnd callback provides a DragEndDetails object. This object provides the velocity of the pointer when it stopped contacting the screen. The velocity is in pixels per second, but the Align widget doesn’t use pixels. It uses coordinate values between [-1.0, -1.0] and [1.0, 1.0]...
https://docs.flutter.dev/cookbook/animation/physics-simulation/index.html
3dd6cf292a00-0
Fade a widget in and out Display a snackbar Add a drawer to a screen Cookbook Design Add a drawer to a screen 1. Create a Scaffold 2. Add a drawer 3. Populate the drawer with items 4. Close the drawer programmatically Interactive example In apps that use Material Design, there are two primary options for nav...
https://docs.flutter.dev/cookbook/design/drawer/index.html
3dd6cf292a00-1
Add a drawer. Populate the drawer with items. Close the drawer programmatically. 1. Create a Scaffold To add a drawer to the app, wrap it in a Scaffold widget. The Scaffold widget provides a consistent visual structure to apps that follow the Material Design Guidelines. It also supports special Material Design comp...
https://docs.flutter.dev/cookbook/design/drawer/index.html
3dd6cf292a00-2
3. Populate the drawer with items Now that you have a Drawer in place, add content to it. For this example, use a ListView. While you could use a Column widget, ListView is handy because it allows users to scroll through the drawer if the content takes more space than the screen supports. Populate the ListView with a...
https://docs.flutter.dev/cookbook/design/drawer/index.html
b0995cd6c3a2-0
Update the UI based on orientation Use themes to share colors and font styles Use a custom font Cookbook Design Use a custom font 1. Import the font files Supported font formats 2. Declare the font in the pubspec pubspec.yaml option definitions 3. Set a font as the default 4. Use the font in a specific widge...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-1
Note: Check out the google_fonts package for direct access to over 1,000 open-sourced font families. Note: For another approach to using custom fonts, especially if you want to re-use one font over multiple projects, see Export fonts from a package. Flutter works with custom fonts and you can apply a cust...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-2
For example, to import the Raleway and Roboto Mono font files into a project, the folder structure might look like this: Supported font formats Flutter supports the following font formats: .ttc .ttf .otf Flutter does not support .woff and .woff2 fonts for all platforms. 2. Declare the font in the pubspec Once y...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-3
style italic family RobotoMono fonts asset fonts/RobotoMono-Regular.ttf asset fonts/RobotoMono-Bold.ttf weight 700 pubspec.yaml option definitions The family determines the name of the font, which you use in the fontFamily property of a TextStyle object. The asset is a path to the font file, relative to th...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-4
A single font can reference many different files with different outline weights and styles: The weight property specifies the weight of the outlines in the file as an integer multiple of 100, between 100 and 900. These values correspond to the FontWeight and can be used in the fontWeight property of a TextStyle object...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-5
The style property specifies whether the outlines in the file are italic or normal. These values correspond to the FontStyle and can be used in the fontStyle property of a TextStyle object. For example, if you want to use the Raleway-Italic font defined above, you would set fontStyle to FontStyle.italic in your Text...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-6
For more information on themes, see the Using Themes to share colors and font styles recipe. 4. Use the font in a specific widget If you want to apply the font to a specific widget, such as a Text widget, provide a TextStyle to the widget. In this example, apply the RobotoMono font to a single Text widget. Once agai...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-7
name custom_fonts description An example of how to use custom fonts with Flutter dependencies flutter sdk flutter dev_dependencies flutter_test sdk flutter flutter fonts family Raleway fonts asset fonts/Raleway-Regular.ttf asset fonts/Raleway-Italic.ttf style italic family RobotoMono fonts ass...
https://docs.flutter.dev/cookbook/design/fonts/index.html
b0995cd6c3a2-8
fonts/RobotoMono-Bold.ttf weight 700 uses-material-design true main.dart Update the UI based on orientation Use themes to share colors and font styles
https://docs.flutter.dev/cookbook/design/fonts/index.html
e160c5218499-0
Design Cookbook Design Add a drawer to a screen Display a snackbar Export fonts from a package Update the UI based on orientation Use a custom font Use themes to share colors and font styles Work with tabs
https://docs.flutter.dev/cookbook/design/index.html
e20ae02519c9-0
Export fonts from a package Use a custom font Update the UI based on orientation Cookbook Design Update the UI based on orientation 1. Build a GridView with two columns 2. Use an OrientationBuilder to change the number of columns Interactive example In some situations, you want to update the display of an app ...
https://docs.flutter.dev/cookbook/design/orientation/index.html
e20ae02519c9-1
Use an OrientationBuilder to change the number of columns. 1. Build a GridView with two columns First, create a list of items to work with. Rather than using a normal list, create a list that displays items in a grid. For now, create a grid with two columns. To learn more about working with GridViews, see the Creati...
https://docs.flutter.dev/cookbook/design/orientation/index.html
e20ae02519c9-2
Note: If you’re interested in the orientation of the screen, rather than the amount of space available to the parent, use MediaQuery.of(context).orientation instead of an OrientationBuilder widget. Interactive example Export fonts from a package Use a custom font
https://docs.flutter.dev/cookbook/design/orientation/index.html
1b44b7ec3972-0
Display a snackbar Update the UI based on orientation Export fonts from a package Cookbook Design Export fonts from a package 1. Add a font to a package 2. Add the package and fonts to the app Add the package to the app Declare the font assets 3. Use the font Complete example Fonts pubspec.yaml main.dart Ra...
https://docs.flutter.dev/cookbook/design/package-fonts/index.html
1b44b7ec3972-1
Add the package and font to the app. Use the font. Note: Check out the google_fonts package for direct access to almost 1000 open-sourced font families. 1. Add a font to a package To export a font from a package, you need to import the font files into the lib folder of the package project. You can place font fi...
https://docs.flutter.dev/cookbook/design/package-fonts/index.html
1b44b7ec3972-2
<latest_version> Declare the font assets Now that you’ve imported the package, tell Flutter where to find the fonts from the awesome_package. To declare package fonts, prefix the path to the font with packages/awesome_package. This tells Flutter to look in the lib folder of the package for the font. flutter fonts ...
https://docs.flutter.dev/cookbook/design/package-fonts/index.html
1b44b7ec3972-3
Complete example Fonts The Raleway and RobotoMono fonts were downloaded from Google Fonts. pubspec.yaml name package_fonts description An example of how to use package fonts with Flutter dependencies awesome_package flutter sdk flutter dev_dependencies flutter_test sdk flutter flutter fonts family R...
https://docs.flutter.dev/cookbook/design/package-fonts/index.html
1b44b7ec3972-4
style italic uses-material-design true main.dart Display a snackbar Update the UI based on orientation
https://docs.flutter.dev/cookbook/design/package-fonts/index.html
aa5b1b9aeab9-0
Add a drawer to a screen Export fonts from a package Display a snackbar Cookbook Design Display a snackbar 1. Create a Scaffold 2. Display a SnackBar 3. Provide an optional action Interactive example It can be useful to briefly inform your users when certain actions take place. For example, when a user swipes...
https://docs.flutter.dev/cookbook/design/snackbars/index.html
aa5b1b9aeab9-1
1. Create a Scaffold When creating apps that follow the Material Design guidelines, give your apps a consistent visual structure. In this example, display the SnackBar at the bottom of the screen, without overlapping other important widgets, such as the FloatingActionButton. The Scaffold widget, from the material lib...
https://docs.flutter.dev/cookbook/design/snackbars/index.html
aa5b1b9aeab9-2
3. Provide an optional action You might want to provide an action to the user when the SnackBar is displayed. For example, if the user accidentally deletes a message, they might use an optional action in the SnackBar to recover the message. Here’s an example of providing an additional action to the SnackBar widget: ...
https://docs.flutter.dev/cookbook/design/snackbars/index.html
61deba6fea6d-0
Use themes to share colors and font styles Create a download button Work with tabs Cookbook Design Work with tabs 1. Create a TabController 2. Create the tabs 3. Create content for each tab Interactive example Working with tabs is a common pattern in apps that follow the Material Design guidelines. Flutter in...
https://docs.flutter.dev/cookbook/design/tabs/index.html
61deba6fea6d-1
Create content for each tab. 1. Create a TabController For tabs to work, you need to keep the selected tab and content sections in sync. This is the job of the TabController. Either create a TabController manually, or automatically by using a DefaultTabController widget. Using DefaultTabController is the simplest o...
https://docs.flutter.dev/cookbook/design/tabs/index.html
61deba6fea6d-2
3. Create content for each tab Now that you have tabs, display content when a tab is selected. For this purpose, use the TabBarView widget. Note: Order is important and must correspond to the order of the tabs in the TabBar. Interactive example Use themes to share colors and font styles Create a download butto...
https://docs.flutter.dev/cookbook/design/tabs/index.html
b0159abcb281-0
Use a custom font Work with tabs Use themes to share colors and font styles Cookbook Design Themes Creating an app theme Themes for part of an application Creating unique ThemeData Extending the parent theme Using a Theme Interactive example To share colors and font styles throughout an app, use themes. You ...
https://docs.flutter.dev/cookbook/design/themes/index.html
b0159abcb281-1
Creating an app theme To share a Theme across an entire app, provide a ThemeData to the MaterialApp constructor. If no theme is provided, Flutter creates a default theme for you. See the ThemeData documentation to see all of the colors and fonts you can define. Themes for part of an application To override the app...
https://docs.flutter.dev/cookbook/design/themes/index.html
b0159abcb281-2
Extending the parent theme Rather than overriding everything, it often makes sense to extend the parent theme. You can handle this by using the copyWith() method. Using a Theme Now that you’ve defined a theme, use it within the widgets’ build() methods by using the Theme.of(context) method. The Theme.of(context) me...
https://docs.flutter.dev/cookbook/design/themes/index.html
f957251ff109-0
Work with tabs Create a nested navigation flow Create a download button Cookbook Effects Create a download button Define a new stateless widget Define the button’s possible visual states Display the button shape Display the button text Display a spinner while fetching download Display the progress and a stop...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
f957251ff109-1
The following animation shows the app’s behavior: Define a new stateless widget Your button widget needs to change its appearance over time. Therefore, you need to implement your button with a custom stateless widget. Define a new stateless widget called DownloadButton. Define the button’s possible visual states T...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
f957251ff109-2
documentation or in a dedicated video in the Flutter YouTube channel. For now, the AnimatedContainer child is just a SizedBox because we will come back at it in another step. You might wonder why you need a ShapeDecoration widget for a transparent circle, given that it’s invisible. The purpose of the invisible circl...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
f957251ff109-3
Add widgets to display text during each download phase, and animate the text’s opacity in between. Add the text widget tree as a child of the AnimatedContainer in the button wrapper widget. Display a spinner while fetching download During the fetchingDownload phase, the DownloadButton displays a radial spinner. This ...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
f957251ff109-4
Display the progress and a stop button while downloading After the fetchingDownload phase is the downloading phase. During the downloading phase, the DownloadButton replaces the radial progress spinner with a growing radial progress bar. The DownloadButton also displays a stop button icon so that the user can cancel ...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
f957251ff109-5
Congratulations! You have a button that changes its display depending on which phase the button is in: not downloaded, fetching download, downloading, and downloaded. Now, the user can tap to start a download, tap to cancel an in-progress download, and tap to open a completed download. Interactive example Run the ap...
https://docs.flutter.dev/cookbook/effects/download-button/index.html
d8b85c53c7c2-0
Create gradient chat bubbles Build a form with validation Drag a UI element Cookbook Effects Drag a UI element Press and drag Drop the draggable Add a menu item to a cart Interactive example Drag and drop is a common mobile app interaction. As the user long presses (sometimes called touch & hold) on a widget,...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-1
The following animation shows the app’s behavior: This recipe begins with a prebuilt list of menu items and a row of customers. The first step is to recognize a long press and display a draggable photo of a menu item. Press and drag Flutter provides a widget called LongPressDraggable that provides the exact behavior...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-2
Wrap the MenuListItem widget with a LongPressDraggable widget. In this case, when the user long presses on the MenuListItem widget, the LongPressDraggable widget displays a DraggingListItem. This DraggingListItem displays a photo of the selected food item, centered beneath the user’s finger. The dragAnchorStrategy p...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-3
The data associated with a LongPressDraggable is sent to a special widget called DragTarget, where the user releases the drag gesture. You’ll implement the drop behavior next. Drop the draggable The user can drop a LongPressDraggable wherever they choose, but dropping the draggable has no effect unless it’s dropped o...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-4
When the user drops a draggable on the DragTarget widget, the onAccept callback is invoked. This is when you get to decide whether or not to accept the data that was dropped. In this case, the item is always accepted and processed. You might choose to inspect the incoming item to make a different decision. Notice tha...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-5
The CustomerCart widget displays the customer’s photo, name, total, and item count based on a Customer instance. To update a customer’s cart when a menu item is dropped, add the dropped item to the associated Customer object. The _itemDroppedOnCustomerCart method is invoked in onAccept() when the user drops a menu it...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
d8b85c53c7c2-6
While holding, the food item’s image will appear above the list. Drag the image and drop it on one of the people at the bottom of the screen. The text under the image updates to reflect the charge for that person. You can continue to add food items and watch the charges accumulate. Create gradient chat bubbles Build...
https://docs.flutter.dev/cookbook/effects/drag-a-widget/index.html
a9e96c33aff5-0
Create a typing indicator Create gradient chat bubbles Create an expandable FAB Cookbook Effects Create an expandable FAB Create an ExpandableFab widget FAB cross-fade Create an ActionButton widget Expand and collapse the action buttons Interactive example A Floating Action Button (FAB) is a round button tha...
https://docs.flutter.dev/cookbook/effects/expandable-fab/index.html
a9e96c33aff5-1
The following animation shows the app’s behavior: Create an ExpandableFab widget Start by creating a new stateful widget called ExpandableFab. This widget displays the primary FAB and coordinates the expansion and collapse of the other action buttons. The widget takes in parameters for whether or not the ExpandedFab ...
https://docs.flutter.dev/cookbook/effects/expandable-fab/index.html
a9e96c33aff5-2
To achieve the cross-fade animation, the open button uses an AnimatedContainer with a scale transform and an AnimatedOpacity. The open button scales down and fades out when the ExpandableFab goes from collapsed to expanded. Then, the open button scales up and fades in when the ExpandableFab goes from expanded to collap...
https://docs.flutter.dev/cookbook/effects/expandable-fab/index.html
a9e96c33aff5-3
Define a new stateless widget called ActionButton to display these round buttons. Pass a few instances of this new ActionButton widget into your ExpandableFab. Expand and collapse the action buttons The child ActionButtons should fly out from under the open FAB when expanded. Then, the child ActionButtons should fly...
https://docs.flutter.dev/cookbook/effects/expandable-fab/index.html
a9e96c33aff5-4
Congratulations! You now have an expandable FAB. Interactive example Run the app: Click the FAB in the lower-right corner, represented with an Edit icon. It fans out to 3 buttons and is itself replaced by a close button, represented by an X. Click the close button to see the expanded buttons fly back to the origina...
https://docs.flutter.dev/cookbook/effects/expandable-fab/index.html
046373897162-0
Create an expandable FAB Drag a UI element Create gradient chat bubbles Cookbook Effects Create gradient chat bubbles Understand the challenge Replace original background widget Create a custom painter Provide access to scrolling information Paint a full-screen bubble gradient Recap Traditional chat apps di...
https://docs.flutter.dev/cookbook/effects/gradient-bubbles/index.html
046373897162-1
The following animation shows the app’s behavior: Understand the challenge The traditional chat bubble solution probably uses a DecoratedBox or a similar widget to paint a rounded rectangle behind each chat message. That approach is great for a solid color or even for a gradient that repeats in every chat bubble. Ho...
https://docs.flutter.dev/cookbook/effects/gradient-bubbles/index.html
046373897162-2
Each bubble’s gradient requires knowledge of the bubble’s location on the screen. This means that the painting behavior requires access to layout information. Such painting behavior isn’t possible with typical widgets because widgets like Container and DecoratedBox make decisions about background colors before layout ...
https://docs.flutter.dev/cookbook/effects/gradient-bubbles/index.html
046373897162-3
Replace original background widget Replace the widget responsible for drawing the background with a new stateless widget called BubbleBackground. Include a colors property to represent the full-screen gradient that should be applied to the bubble. Create a custom painter Provide access to scrolling information Pai...
https://docs.flutter.dev/cookbook/effects/gradient-bubbles/index.html
046373897162-4
Recap The fundamental challenge when painting based on the scroll position, or the screen position in general, is that the painting behavior must occur after the layout phase is complete. CustomPaint is a unique widget that allows you to execute custom painting behaviors after the layout phase is complete. If you exec...
https://docs.flutter.dev/cookbook/effects/gradient-bubbles/index.html