Commit a50eda8f authored by Brian Egan's avatar Brian Egan Committed by Kate Lovett

Diagrams and samples for Rank 20-30 popular api docs (#40089)

parent 6d18c20a
...@@ -81,7 +81,7 @@ enum ThemeMode { ...@@ -81,7 +81,7 @@ enum ThemeMode {
/// This example shows how to create a [MaterialApp] that disables the "debug" /// This example shows how to create a [MaterialApp] that disables the "debug"
/// banner with a [home] route that will be displayed when the app is launched. /// banner with a [home] route that will be displayed when the app is launched.
/// ///
/// ![A screenshot of the MaterialApp class with a home Scaffold](https://flutter.github.io/assets-for-api-docs/assets/material/basic_material_app.png) /// ![The MaterialApp displays a Scaffold ](https://flutter.github.io/assets-for-api-docs/assets/material/basic_material_app.png)
/// ///
/// ```dart /// ```dart
/// MaterialApp( /// MaterialApp(
...@@ -125,7 +125,7 @@ enum ThemeMode { ...@@ -125,7 +125,7 @@ enum ThemeMode {
/// This example shows how to create a [MaterialApp] that defines a [theme] that /// This example shows how to create a [MaterialApp] that defines a [theme] that
/// will be used for material widgets in the app. /// will be used for material widgets in the app.
/// ///
/// ![A screenshot of the MaterialApp class with a custom theme](https://flutter.github.io/assets-for-api-docs/assets/material/theme_material_app.png) /// ![The MaterialApp displays a Scaffold with a dark background and a blue / grey AppBar at the top](https://flutter.github.io/assets-for-api-docs/assets/material/theme_material_app.png)
/// ///
/// ```dart /// ```dart
/// MaterialApp( /// MaterialApp(
......
...@@ -55,6 +55,59 @@ const Duration _kBaseSettleDuration = Duration(milliseconds: 246); ...@@ -55,6 +55,59 @@ const Duration _kBaseSettleDuration = Duration(milliseconds: 246);
/// drawer children are often constructed with [ListTile]s, often concluding /// drawer children are often constructed with [ListTile]s, often concluding
/// with an [AboutListTile]. /// with an [AboutListTile].
/// ///
/// The [AppBar] automatically displays an appropriate [IconButton] to show the
/// [Drawer] when a [Drawer] is available in the [Scaffold]. The [Scaffold]
/// automatically handles the edge-swipe gesture to show the drawer.
///
/// {@animation 350 622 https://flutter.github.io/assets-for-api-docs/assets/material/drawer.mp4}
///
/// {@tool sample}
/// This example shows how to create a [Scaffold] that contains an [AppBar] and
/// a [Drawer]. A user taps the "menu" icon in the [AppBar] to open the
/// [Drawer]. The [Drawer] displays four items: A header and three menu items.
/// The [Drawer] displays the four items using a [ListView], which allows the
/// user to scroll through the items if need be.
///
/// ```dart
/// Scaffold(
/// appBar: AppBar(
/// title: const Text('Drawer Demo'),
/// ),
/// drawer: Drawer(
/// child: ListView(
/// padding: EdgeInsets.zero,
/// children: const <Widget>[
/// DrawerHeader(
/// decoration: BoxDecoration(
/// color: Colors.blue,
/// ),
/// child: Text(
/// 'Drawer Header',
/// style: TextStyle(
/// color: Colors.white,
/// fontSize: 24,
/// ),
/// ),
/// ),
/// ListTile(
/// leading: Icon(Icons.message),
/// title: Text('Messages'),
/// ),
/// ListTile(
/// leading: Icon(Icons.account_circle),
/// title: Text('Profile'),
/// ),
/// ListTile(
/// leading: Icon(Icons.settings),
/// title: Text('Settings'),
/// ),
/// ],
/// ),
/// ),
/// )
/// ```
/// {@end-tool}
///
/// An open drawer can be closed by calling [Navigator.pop]. For example /// An open drawer can be closed by calling [Navigator.pop]. For example
/// a drawer item might close the drawer when tapped: /// a drawer item might close the drawer when tapped:
/// ///
...@@ -69,10 +122,6 @@ const Duration _kBaseSettleDuration = Duration(milliseconds: 246); ...@@ -69,10 +122,6 @@ const Duration _kBaseSettleDuration = Duration(milliseconds: 246);
/// ); /// );
/// ``` /// ```
/// ///
/// The [AppBar] automatically displays an appropriate [IconButton] to show the
/// [Drawer] when a [Drawer] is available in the [Scaffold]. The [Scaffold]
/// automatically handles the edge-swipe gesture to show the drawer.
///
/// See also: /// See also:
/// ///
/// * [Scaffold.drawer], where one specifies a [Drawer] so that it can be /// * [Scaffold.drawer], where one specifies a [Drawer] so that it can be
......
...@@ -534,10 +534,11 @@ class DropdownButtonHideUnderline extends InheritedWidget { ...@@ -534,10 +534,11 @@ class DropdownButtonHideUnderline extends InheritedWidget {
/// ///
/// {@tool snippet --template=stateful_widget_scaffold_center} /// {@tool snippet --template=stateful_widget_scaffold_center}
/// ///
/// This sample shows a `DropdownButton` with a customized icon, text style, /// This sample shows a `DropdownButton` with a large arrow icon,
/// and underline and whose value is one of "One", "Two", "Free", or "Four". /// purple text style, and bold purple underline, whose value is one of "One",
/// "Two", "Free", or "Four".
/// ///
/// ![A screenshot of the dropdown button](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png)
/// ///
/// ```dart /// ```dart
/// String dropdownValue = 'One'; /// String dropdownValue = 'One';
......
...@@ -58,10 +58,10 @@ class _DefaultHeroTag { ...@@ -58,10 +58,10 @@ class _DefaultHeroTag {
/// action button. /// action button.
/// ///
/// {@tool snippet --template=stateless_widget_material} /// {@tool snippet --template=stateless_widget_material}
/// This example shows how to make a simple [FloatingActionButton] in a /// This example shows how to display a [FloatingActionButton] in a
/// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon]. /// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon].
/// ///
/// ![A screenshot of a green floating action button with a navigation icon](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button.png)
/// ///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
...@@ -87,9 +87,9 @@ class _DefaultHeroTag { ...@@ -87,9 +87,9 @@ class _DefaultHeroTag {
/// {@tool snippet --template=stateless_widget_material} /// {@tool snippet --template=stateless_widget_material}
/// This example shows how to make an extended [FloatingActionButton] in a /// This example shows how to make an extended [FloatingActionButton] in a
/// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a /// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a
/// [Text] label. /// [Text] label that reads "Approve".
/// ///
/// ![A screenshot of a pink floating action button with a thumbs up icon and a label that reads "Approve"](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_label.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_label.png)
/// ///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
......
...@@ -43,6 +43,8 @@ const double _kMinButtonSize = kMinInteractiveDimension; ...@@ -43,6 +43,8 @@ const double _kMinButtonSize = kMinInteractiveDimension;
/// This sample shows an `IconButton` that uses the Material icon "volume_up" to /// This sample shows an `IconButton` that uses the Material icon "volume_up" to
/// increase the volume. /// increase the volume.
/// ///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button.png)
///
/// ```dart preamble /// ```dart preamble
/// double _volume = 0.0; /// double _volume = 0.0;
/// ``` /// ```
...@@ -87,21 +89,22 @@ const double _kMinButtonSize = kMinInteractiveDimension; ...@@ -87,21 +89,22 @@ const double _kMinButtonSize = kMinInteractiveDimension;
/// is a light shade of blue, it's a filled circle, and it's as big as the /// is a light shade of blue, it's a filled circle, and it's as big as the
/// button is. /// button is.
/// ///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button_background.png)
///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
/// return Center( /// return Material(
/// child: Container( /// color: Colors.white,
/// child: Center(
/// child: Ink( /// child: Ink(
/// decoration: ShapeDecoration( /// decoration: const ShapeDecoration(
/// color: Colors.lightBlue, /// color: Colors.lightBlue,
/// shape: CircleBorder(), /// shape: CircleBorder(),
/// ), /// ),
/// child: IconButton( /// child: IconButton(
/// icon: Icon(Icons.android), /// icon: Icon(Icons.android),
/// color: Colors.white, /// color: Colors.white,
/// onPressed: () { /// onPressed: () {},
/// print("filled background");
/// },
/// ), /// ),
/// ), /// ),
/// ), /// ),
......
...@@ -811,7 +811,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr ...@@ -811,7 +811,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// within the [Scaffold]. The [FloatingActionButton] is connected to a /// within the [Scaffold]. The [FloatingActionButton] is connected to a
/// callback that increments a counter. /// callback that increments a counter.
/// ///
/// ![A screenshot of the Scaffold widget with a body and floating action button](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold.png) /// ![The Scaffold has a white background with a blue AppBar at the top. A blue FloatingActionButton is positioned at the bottom right corner of the Scaffold.](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold.png)
/// ///
/// ```dart /// ```dart
/// int _count = 0; /// int _count = 0;
...@@ -835,12 +835,12 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr ...@@ -835,12 +835,12 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// {@end-tool} /// {@end-tool}
/// ///
/// {@tool snippet --template=stateful_widget_material} /// {@tool snippet --template=stateful_widget_material}
/// This example shows a [Scaffold] with a [backgroundColor], [body] and /// This example shows a [Scaffold] with a blueGrey [backgroundColor], [body]
/// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order /// and [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in
/// to center the text within the [Scaffold]. The [FloatingActionButton] is /// order to center the text within the [Scaffold]. The [FloatingActionButton]
/// connected to a callback that increments a counter. /// is connected to a callback that increments a counter.
/// ///
/// ![A screenshot of the Scaffold widget example with a background color](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_background_color.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_background_color.png)
/// ///
/// ```dart /// ```dart
/// int _count = 0; /// int _count = 0;
...@@ -872,7 +872,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr ...@@ -872,7 +872,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
/// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is /// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is
/// connected to a callback that increments a counter. /// connected to a callback that increments a counter.
/// ///
/// ![A screenshot of the Scaffold widget with a bottom navigation bar and docked floating action button](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_bottom_app_bar.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_bottom_app_bar.png)
/// ///
/// ```dart /// ```dart
/// int _count = 0; /// int _count = 0;
......
...@@ -175,7 +175,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete ...@@ -175,7 +175,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
/// [InputDecoration] surrounds the field in a border using [OutlineInputBorder] /// [InputDecoration] surrounds the field in a border using [OutlineInputBorder]
/// and adds a label. /// and adds a label.
/// ///
/// ![A screenshot of the TextField widget](https://flutter.github.io/assets-for-api-docs/assets/material/text_field.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/text_field.png)
/// ///
/// ```dart /// ```dart
/// TextField( /// TextField(
......
...@@ -38,6 +38,10 @@ import 'theme.dart'; ...@@ -38,6 +38,10 @@ import 'theme.dart';
/// ///
/// Creates a [TextFormField] with an [InputDecoration] and validator function. /// Creates a [TextFormField] with an [InputDecoration] and validator function.
/// ///
/// ![If the user enters valid text, the TextField appears normally without any warnings to the user](https://flutter.github.io/assets-for-api-docs/assets/material/text_form_field.png)
///
/// ![If the user enters invalid text, the error message returned from the validator function is displayed in dark red underneath the input](https://flutter.github.io/assets-for-api-docs/assets/material/text_form_field_error.png)
///
/// ```dart /// ```dart
/// TextFormField( /// TextFormField(
/// decoration: const InputDecoration( /// decoration: const InputDecoration(
......
...@@ -92,9 +92,76 @@ enum MaterialTapTargetSize { ...@@ -92,9 +92,76 @@ enum MaterialTapTargetSize {
/// Holds the color and typography values for a material design theme. /// Holds the color and typography values for a material design theme.
/// ///
/// Use this class to configure a [Theme] widget. /// Use this class to configure a [Theme] or [MaterialApp] widget.
/// ///
/// To obtain the current theme, use [Theme.of]. /// To obtain the current theme, use [Theme.of].
///
/// {@tool sample}
///
/// This sample creates a [Theme] widget that stores the `ThemeData`. The
/// `ThemeData` can be accessed by descendant Widgets that use the correct
/// `context`. This example uses the [Builder] widget to gain access to a
/// descendant `context` that contains the `ThemeData`.
///
/// The [Container] widget uses [Theme.of] to retrieve the [primaryColor] from
/// the `ThemeData` to draw an amber square.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/theme_data.png)
///
/// ```dart
/// Theme(
/// data: ThemeData(primaryColor: Colors.amber),
/// child: Builder(
/// builder: (BuildContext context) {
/// return Container(
/// width: 100,
/// height: 100,
/// color: Theme.of(context).primaryColor,
/// );
/// },
/// ),
/// )
/// ```
/// {@end-tool}
///
/// In addition to using the [Theme] widget, you can provide `ThemeData` to a
/// [MaterialApp]. The `ThemeData` will be used throughout the app to style
/// material design widgets.
///
/// {@tool sample}
///
/// This sample creates a [MaterialApp] widget that stores `ThemeData` and
/// passes the `ThemeData` to descendant widgets. The [AppBar] widget uses the
/// [primaryColor] to create a blue background. The [Text] widget uses the
/// [TextTheme.body1] to create purple text. The [FloatingActionButton] widget
/// uses the [accentColor] to create a green background.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/material_app_theme_data.png)
///
/// ```dart
/// MaterialApp(
/// theme: ThemeData(
/// primaryColor: Colors.blue,
/// accentColor: Colors.green,
/// textTheme: TextTheme(body1: TextStyle(color: Colors.purple)),
/// ),
/// home: Scaffold(
/// appBar: AppBar(
/// title: const Text('ThemeData Demo'),
/// ),
/// floatingActionButton: FloatingActionButton(
/// child: const Icon(Icons.add),
/// onPressed: () {},
/// ),
/// body: Center(
/// child: Text(
/// 'Button pressed 0 times',
/// ),
/// ),
/// ),
/// )
/// ```
/// {@end-tool}
@immutable @immutable
class ThemeData extends Diagnosticable { class ThemeData extends Diagnosticable {
/// Create a [ThemeData] given a set of preferred values. /// Create a [ThemeData] given a set of preferred values.
......
...@@ -35,21 +35,24 @@ import 'image_provider.dart'; ...@@ -35,21 +35,24 @@ import 'image_provider.dart';
/// ///
/// {@tool sample} /// {@tool sample}
/// ///
/// The following example uses the [Container] widget from the widgets layer to /// The following applies a [BoxDecoration] to a [Container] widget to draw an
/// draw an image with a border: /// [image] of an owl with a thick black [border] and rounded corners.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/box_decoration.png)
/// ///
/// ```dart /// ```dart
/// Container( /// Container(
/// decoration: BoxDecoration( /// decoration: BoxDecoration(
/// color: const Color(0xff7c94b6), /// color: const Color(0xff7c94b6),
/// image: DecorationImage( /// image: const DecorationImage(
/// image: ExactAssetImage('images/flowers.jpeg'), /// image: NetworkImage('https:///flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'),
/// fit: BoxFit.cover, /// fit: BoxFit.cover,
/// ), /// ),
/// border: Border.all( /// border: Border.all(
/// color: Colors.black, /// color: Colors.black,
/// width: 8.0, /// width: 8,
/// ), /// ),
/// borderRadius: BorderRadius.circular(12),
/// ), /// ),
/// ) /// )
/// ``` /// ```
......
...@@ -30,7 +30,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -30,7 +30,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// override. The style is mixed with the ambient [DefaultTextStyle] by the /// override. The style is mixed with the ambient [DefaultTextStyle] by the
/// [Text] widget. /// [Text] widget.
/// ///
/// ![An example using TextStyle to create bold text](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_bold.png) /// ![Applying the style in this way creates bold text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_bold.png)
/// ///
/// ```dart /// ```dart
/// Text( /// Text(
...@@ -46,7 +46,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -46,7 +46,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// As in the previous example, the [Text] widget is given a specific style /// As in the previous example, the [Text] widget is given a specific style
/// override which is implicitly mixed with the ambient [DefaultTextStyle]. /// override which is implicitly mixed with the ambient [DefaultTextStyle].
/// ///
/// ![An example using TextStyle to create italic text](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_italics.png) /// ![This results in italicized text.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_italics.png)
/// ///
/// ```dart /// ```dart
/// Text( /// Text(
...@@ -72,7 +72,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -72,7 +72,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// The [backgroundColor] is treated as a shorthand for /// The [backgroundColor] is treated as a shorthand for
/// `background: Paint()..color = backgroundColor`. /// `background: Paint()..color = backgroundColor`.
/// ///
/// ![An example using TextStyle to change the text opacity and color](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_opacity_and_color.png) /// ![This results in three lines of text that go from lighter to darker in color.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_opacity_and_color.png)
/// ///
/// ```dart /// ```dart
/// RichText( /// RichText(
...@@ -102,7 +102,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -102,7 +102,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// In this example, the ambient [DefaultTextStyle] is explicitly manipulated to /// In this example, the ambient [DefaultTextStyle] is explicitly manipulated to
/// obtain a [TextStyle] that doubles the default font size. /// obtain a [TextStyle] that doubles the default font size.
/// ///
/// ![An example using TextStyle to change the text size](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_size.png) /// ![This results in text that is twice as large as normal.](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_size.png)
/// ///
/// ```dart /// ```dart
/// Text( /// Text(
...@@ -147,13 +147,13 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -147,13 +147,13 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// ### Wavy red underline with black text /// ### Wavy red underline with black text
/// ///
/// {@tool sample} /// {@tool sample}
/// Styles can be combined. In this example, the misspelt word is drawn in black /// Styles can be combined. In this example, the misspelled word is drawn in
/// text and underlined with a wavy red line to indicate a spelling error. (The /// black text and underlined with a wavy red line to indicate a spelling error.
/// remainder is styled according to the Flutter default text styles, not the /// (The remainder is styled according to the Flutter default text styles, not
/// ambient [DefaultTextStyle], since no explicit style is given and [RichText] /// the ambient [DefaultTextStyle], since no explicit style is given and
/// does not automatically use the ambient [DefaultTextStyle].) /// [RichText] does not automatically use the ambient [DefaultTextStyle].)
/// ///
/// ![An example using TextStyle to highlight a word with a red wavy underline](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_wavy_red_underline.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_wavy_red_underline.png)
/// ///
/// ```dart /// ```dart
/// RichText( /// RichText(
...@@ -276,7 +276,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a ...@@ -276,7 +276,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
/// argument as shown in the example below: /// argument as shown in the example below:
/// ///
/// {@tool sample} /// {@tool sample}
/// ![An example using TextStyle to change the font family](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_custom_fonts.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/painting/text_style_custom_fonts.png)
/// ///
/// ```dart /// ```dart
/// const TextStyle(fontFamily: 'Raleway') /// const TextStyle(fontFamily: 'Raleway')
......
...@@ -489,30 +489,77 @@ class StreamBuilder<T> extends StreamBuilderBase<T, AsyncSnapshot<T>> { ...@@ -489,30 +489,77 @@ class StreamBuilder<T> extends StreamBuilderBase<T, AsyncSnapshot<T>> {
/// `future?.asStream()`, except that snapshots with `ConnectionState.active` /// `future?.asStream()`, except that snapshots with `ConnectionState.active`
/// may appear for the latter, depending on how the stream is implemented. /// may appear for the latter, depending on how the stream is implemented.
/// ///
/// {@tool sample} /// {@animation 200 150 https://flutter.github.io/assets-for-api-docs/assets/widgets/future_builder.mp4}
///
/// {@animation 200 150 https://flutter.github.io/assets-for-api-docs/assets/widgets/future_builder_error.mp4}
/// ///
/// This sample shows a [FutureBuilder] configuring a text label to show the /// {@tool snippet --template=stateful_widget_material}
/// state of an asynchronous calculation returning a string. Assume the ///
/// `_calculation` field is set by pressing a button elsewhere in the UI. /// This sample shows a [FutureBuilder] that displays a loading spinner while it
/// loads data. It displays a success icon and text if the [Future] completes
/// with a result, or an error icon and text if the [Future] completes with an
/// error. Assume the `_calculation` field is set by pressing a button elsewhere
/// in the UI.
/// ///
/// ```dart /// ```dart
/// FutureBuilder<String>( /// Future<String> _calculation = Future<String>.delayed(
/// future: _calculation, // a previously-obtained Future<String> or null /// Duration(seconds: 2),
/// builder: (BuildContext context, AsyncSnapshot<String> snapshot) { /// () => 'Data Loaded',
/// switch (snapshot.connectionState) { /// );
/// case ConnectionState.none: ///
/// return Text('Press button to start.'); /// Widget build(BuildContext context) {
/// case ConnectionState.active: /// return FutureBuilder<String>(
/// case ConnectionState.waiting: /// future: _calculation, // a previously-obtained Future<String> or null
/// return Text('Awaiting result...'); /// builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
/// case ConnectionState.done: /// List<Widget> children;
/// if (snapshot.hasError) ///
/// return Text('Error: ${snapshot.error}'); /// if (snapshot.hasData) {
/// return Text('Result: ${snapshot.data}'); /// children = <Widget>[
/// } /// Icon(
/// return null; // unreachable /// Icons.check_circle_outline,
/// }, /// color: Colors.green,
/// ) /// size: 60,
/// ),
/// Padding(
/// padding: const EdgeInsets.only(top: 16),
/// child: Text('Result: ${snapshot.data}'),
/// )
/// ];
/// } else if (snapshot.hasError) {
/// children = <Widget>[
/// Icon(
/// Icons.error_outline,
/// color: Colors.red,
/// size: 60,
/// ),
/// Padding(
/// padding: const EdgeInsets.only(top: 16),
/// child: Text('Error: ${snapshot.error}'),
/// )
/// ];
/// } else {
/// children = <Widget>[
/// SizedBox(
/// child: CircularProgressIndicator(),
/// width: 60,
/// height: 60,
/// ),
/// const Padding(
/// padding: EdgeInsets.only(top: 16),
/// child: Text('Awaiting result...'),
/// )
/// ];
/// }
/// return Center(
/// child: Column(
/// mainAxisAlignment: MainAxisAlignment.center,
/// crossAxisAlignment: CrossAxisAlignment.center,
/// children: children,
/// ),
/// );
/// },
/// );
/// }
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
// TODO(ianh): remove unreachable code above once https://github.com/dart-lang/linter/issues/1141 is fixed // TODO(ianh): remove unreachable code above once https://github.com/dart-lang/linter/issues/1141 is fixed
......
...@@ -1563,13 +1563,17 @@ class RotatedBox extends SingleChildRenderObjectWidget { ...@@ -1563,13 +1563,17 @@ class RotatedBox extends SingleChildRenderObjectWidget {
/// ///
/// {@tool sample} /// {@tool sample}
/// ///
/// This snippet indents the child (a [Card] with some [Text]) by eight pixels /// This snippet creates "Hello World!" [Text] inside a [Card] that is indented
/// in each direction: /// by sixteen pixels in each direction.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/padding.png)
/// ///
/// ```dart /// ```dart
/// Padding( /// const Card(
/// padding: EdgeInsets.all(8.0), /// child: Padding(
/// child: const Card(child: Text('Hello World!')), /// padding: EdgeInsets.all(16.0),
/// child: Text('Hello World!'),
/// ),
/// ) /// )
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
...@@ -3088,7 +3092,7 @@ class ListBody extends MultiChildRenderObjectWidget { ...@@ -3088,7 +3092,7 @@ class ListBody extends MultiChildRenderObjectWidget {
/// ///
/// Using a [Stack] you can position widgets over one another. /// Using a [Stack] you can position widgets over one another.
/// ///
/// ![A screenshot of the Stack widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack.png) /// ![The sample creates a blue box that overlaps a larger green box, which itself overlaps an even larger red box.](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack.png)
/// ///
/// ```dart /// ```dart
/// Stack( /// Stack(
...@@ -3118,7 +3122,7 @@ class ListBody extends MultiChildRenderObjectWidget { ...@@ -3118,7 +3122,7 @@ class ListBody extends MultiChildRenderObjectWidget {
/// This example shows how [Stack] can be used to enhance text visibility /// This example shows how [Stack] can be used to enhance text visibility
/// by adding gradient backdrops. /// by adding gradient backdrops.
/// ///
/// ![A screenshot of the Stack widget using a gradient to enhance text visibility](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack_with_gradient.png) /// ![The gradient fades from transparent to dark grey at the bottom, with white text on top of the darker portion.](https://flutter.github.io/assets-for-api-docs/assets/widgets/stack_with_gradient.png)
/// ///
/// ```dart /// ```dart
/// SizedBox( /// SizedBox(
...@@ -3951,7 +3955,7 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -3951,7 +3955,7 @@ class Flex extends MultiChildRenderObjectWidget {
/// places text centered in the first two cells and the Flutter logo centered in /// places text centered in the first two cells and the Flutter logo centered in
/// the third: /// the third:
/// ///
/// ![A screenshot of the Row widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/row.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/row.png)
/// ///
/// ```dart /// ```dart
/// Row( /// Row(
...@@ -4140,7 +4144,7 @@ class Row extends Flex { ...@@ -4140,7 +4144,7 @@ class Row extends Flex {
/// This example uses a [Column] to arrange three widgets vertically, the last /// This example uses a [Column] to arrange three widgets vertically, the last
/// being made to fill all the remaining space. /// being made to fill all the remaining space.
/// ///
/// ![A screenshot of the Column widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/column.png) /// ![Using the Column in this way creates two short lines of text with a large Flutter underneath.](https://flutter.github.io/assets-for-api-docs/assets/widgets/column.png)
/// ///
/// ```dart /// ```dart
/// Column( /// Column(
...@@ -4165,7 +4169,7 @@ class Row extends Flex { ...@@ -4165,7 +4169,7 @@ class Row extends Flex {
/// [mainAxisSize] is set to [MainAxisSize.min], so that the column shrinks to /// [mainAxisSize] is set to [MainAxisSize.min], so that the column shrinks to
/// fit the children. /// fit the children.
/// ///
/// ![A screenshot of the Column widget with a customized crossAxisAlignment and mainAxisSize](https://flutter.github.io/assets-for-api-docs/assets/widgets/column_properties.png) /// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/column_properties.png)
/// ///
/// ```dart /// ```dart
/// Column( /// Column(
...@@ -4416,7 +4420,7 @@ class Flexible extends ParentDataWidget<Flex> { ...@@ -4416,7 +4420,7 @@ class Flexible extends ParentDataWidget<Flex> {
/// This example shows how to use an [Expanded] widget in a [Column] so that /// This example shows how to use an [Expanded] widget in a [Column] so that
/// it's middle child, a [Container] here, expands to fill the space. /// it's middle child, a [Container] here, expands to fill the space.
/// ///
/// ![An example using Expanded widget in a Column](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_column.png) /// ![This results in two thin blue boxes with a larger amber box in between.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_column.png)
/// ///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
...@@ -4455,7 +4459,7 @@ class Flexible extends ParentDataWidget<Flex> { ...@@ -4455,7 +4459,7 @@ class Flexible extends ParentDataWidget<Flex> {
/// This example shows how to use an [Expanded] widget in a [Row] with multiple /// This example shows how to use an [Expanded] widget in a [Row] with multiple
/// children expanded, utilizing the [flex] factor to prioritize available space. /// children expanded, utilizing the [flex] factor to prioritize available space.
/// ///
/// ![An example using Expanded widget in a Row](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_row.png) /// ![This results in a wide amber box, followed by a thin blue box, with a medium width amber box at the end.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_row.png)
/// ///
/// ```dart /// ```dart
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
......
...@@ -17,8 +17,11 @@ import 'will_pop_scope.dart'; ...@@ -17,8 +17,11 @@ import 'will_pop_scope.dart';
/// [Form] constructor and call [GlobalKey.currentState]. /// [Form] constructor and call [GlobalKey.currentState].
/// ///
/// {@tool snippet --template=stateful_widget_scaffold} /// {@tool snippet --template=stateful_widget_scaffold}
/// This example shows a [Form] with one [TextFormField] and a [RaisedButton]. A /// This example shows a [Form] with one [TextFormField] to enter an email
/// [GlobalKey] is used here to identify the [Form] and validate input. /// address and a [RaisedButton] to submit the form. A [GlobalKey] is used here
/// to identify the [Form] and validate input.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/form.png)
/// ///
/// ```dart /// ```dart
/// final _formKey = GlobalKey<FormState>(); /// final _formKey = GlobalKey<FormState>();
...@@ -31,6 +34,9 @@ import 'will_pop_scope.dart'; ...@@ -31,6 +34,9 @@ import 'will_pop_scope.dart';
/// crossAxisAlignment: CrossAxisAlignment.start, /// crossAxisAlignment: CrossAxisAlignment.start,
/// children: <Widget>[ /// children: <Widget>[
/// TextFormField( /// TextFormField(
/// decoration: const InputDecoration(
/// hintText: 'Enter your email',
/// ),
/// validator: (value) { /// validator: (value) {
/// if (value.isEmpty) { /// if (value.isEmpty) {
/// return 'Please enter some text'; /// return 'Please enter some text';
......
...@@ -126,19 +126,41 @@ class GestureRecognizerFactoryWithHandlers<T extends GestureRecognizer> extends ...@@ -126,19 +126,41 @@ class GestureRecognizerFactoryWithHandlers<T extends GestureRecognizer> extends
/// effects. The [InkWell] class implements this effect and can be used in place /// effects. The [InkWell] class implements this effect and can be used in place
/// of a [GestureDetector] for handling taps. /// of a [GestureDetector] for handling taps.
/// ///
/// {@animation 200 150 https://flutter.github.io/assets-for-api-docs/assets/widgets/gesture_detector.mp4}
///
/// {@tool sample} /// {@tool sample}
/// ///
/// This example makes a rectangle react to being tapped by setting the /// This example turns the light bulb yellow when the "turn lights on" button is
/// `_lights` field: /// tapped by setting the `_lights` field:
/// ///
/// ```dart /// ```dart
/// GestureDetector( /// Container(
/// onTap: () { /// alignment: FractionalOffset.center,
/// setState(() { _lights = true; }); /// color: Colors.white,
/// }, /// child: Column(
/// child: Container( /// mainAxisAlignment: MainAxisAlignment.center,
/// color: Colors.yellow, /// children: <Widget>[
/// child: Text('TURN LIGHTS ON'), /// Padding(
/// padding: const EdgeInsets.all(8.0),
/// child: Icon(
/// Icons.lightbulb_outline,
/// color: _lights ? Colors.yellow.shade600 : Colors.black,
/// size: 60,
/// ),
/// ),
/// GestureDetector(
/// onTap: () {
/// setState(() {
/// _lights = true;
/// });
/// },
/// child: Container(
/// color: Colors.yellow.shade600,
/// padding: const EdgeInsets.all(8),
/// child: const Text('TURN LIGHTS ON'),
/// ),
/// ),
/// ],
/// ), /// ),
/// ) /// )
/// ``` /// ```
......
...@@ -1290,7 +1290,7 @@ class ListView extends BoxScrollView { ...@@ -1290,7 +1290,7 @@ class ListView extends BoxScrollView {
/// children are spaced apart using the [crossAxisSpacing] and [mainAxisSpacing] /// children are spaced apart using the [crossAxisSpacing] and [mainAxisSpacing]
/// properties. /// properties.
/// ///
/// ![A screenshot of a GridView](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view.png) /// ![The GridView displays six children with different background colors arranged in two columns](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view.png)
/// ///
/// ```dart /// ```dart
/// GridView.count( /// GridView.count(
...@@ -1339,7 +1339,7 @@ class ListView extends BoxScrollView { ...@@ -1339,7 +1339,7 @@ class ListView extends BoxScrollView {
/// This example shows how to create the same grid as the previous example /// This example shows how to create the same grid as the previous example
/// using a [CustomScrollView] and a [SliverGrid]. /// using a [CustomScrollView] and a [SliverGrid].
/// ///
/// ![A screenshot of a CustomScrollView with a SliverGrid](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view_custom_scroll.png) /// ![The CustomScrollView contains a SliverGrid that displays six children with different background colors arranged in two columns](https://flutter.github.io/assets-for-api-docs/assets/widgets/grid_view_custom_scroll.png)
/// ///
/// ```dart /// ```dart
/// CustomScrollView( /// CustomScrollView(
......
...@@ -204,12 +204,12 @@ class DefaultTextStyle extends InheritedTheme { ...@@ -204,12 +204,12 @@ class DefaultTextStyle extends InheritedTheme {
/// ///
/// {@tool sample} /// {@tool sample}
/// ///
/// This example shows how to display text using the [Text] widget. If the text /// This example shows how to display text using the [Text] widget with the
/// overflows, it truncates the text with an ellipsis. /// [overflow] set to [TextOverflow.ellipsis].
/// ///
/// ![A screenshot of the Text widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/text.png) /// ![If the text is shorter than the available space, it is displayed in full without an ellipsis.](https://flutter.github.io/assets-for-api-docs/assets/widgets/text.png)
/// ///
/// ![A screenshot of the Text widget displaying an ellipsis to trim the overflowing text](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_ellipsis.png) /// ![If the text overflows, the Text widget displays an ellipsis to trim the overflowing text](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_ellipsis.png)
/// ///
/// ```dart /// ```dart
/// Text( /// Text(
...@@ -228,7 +228,7 @@ class DefaultTextStyle extends InheritedTheme { ...@@ -228,7 +228,7 @@ class DefaultTextStyle extends InheritedTheme {
/// ///
/// {@tool sample} /// {@tool sample}
/// ///
/// ![A screenshot of the following rich text example](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_rich.png) /// ![The word "Hello" is shown with the default text styles. The word "beautiful" is italicized. The word "world" is bold.](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_rich.png)
/// ///
/// ```dart /// ```dart
/// const Text.rich( /// const Text.rich(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment