From 70b405ee183b4945990e9fbfbeb4c2c98e6e9344 Mon Sep 17 00:00:00 2001 From: Brian Egan Date: Mon, 22 Jul 2019 18:34:56 +0200 Subject: [PATCH] Add images and update examples for top widgets: (#36460) * Add images and update examples for top widgets: - scaffold - text field - image - text - row - column - stack --- .../flutter/lib/src/material/scaffold.dart | 64 ++++++++++++++++++- .../flutter/lib/src/material/text_field.dart | 2 + packages/flutter/lib/src/widgets/basic.dart | 19 +++++- packages/flutter/lib/src/widgets/image.dart | 25 ++++++++ packages/flutter/lib/src/widgets/text.dart | 9 +++ 5 files changed, 115 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 99a9544c68..ba5442103d 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -776,13 +776,74 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr /// [ScaffoldState.showSnackBar] and [ScaffoldState.showBottomSheet] functions. /// /// {@tool snippet --template=stateful_widget_material} +/// This example shows a [Scaffold] with a [body] and [FloatingActionButton]. +/// The [body] is a [Text] placed in a [Center] in order to center the text +/// within the [Scaffold]. The [FloatingActionButton] is connected to a +/// 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) +/// +/// ```dart +/// int _count = 0; +/// +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: const Text('Sample Code'), +/// ), +/// body: Center( +/// child: Text('You have pressed the button $_count times.') +/// ), +/// floatingActionButton: FloatingActionButton( +/// onPressed: () => setState(() => _count++), +/// tooltip: 'Increment Counter', +/// child: const Icon(Icons.add), +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet --template=stateful_widget_material} +/// This example shows a [Scaffold] with a [backgroundColor], [body] and +/// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order +/// to center the text within the [Scaffold]. The [FloatingActionButton] 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) +/// +/// ```dart +/// int _count = 0; +/// +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: const Text('Sample Code'), +/// ), +/// body: Center( +/// child: Text('You have pressed the button $_count times.') +/// ), +/// backgroundColor: Colors.blueGrey.shade200, +/// floatingActionButton: FloatingActionButton( +/// onPressed: () => setState(() => _count++), +/// tooltip: 'Increment Counter', +/// child: const Icon(Icons.add), +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// +/// {@tool snippet --template=stateful_widget_material} /// This example shows a [Scaffold] with an [AppBar], a [BottomAppBar] and a /// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order -/// to center the text within the [Scaffold] and the [FloatingActionButton] is +/// to center the text within the [Scaffold]. The [FloatingActionButton] is /// centered and docked within the [BottomAppBar] using /// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is /// 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) +/// /// ```dart /// int _count = 0; /// @@ -795,6 +856,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr /// child: Text('You have pressed the button $_count times.'), /// ), /// bottomNavigationBar: BottomAppBar( +/// shape: const CircularNotchedRectangle(), /// child: Container(height: 50.0,), /// ), /// floatingActionButton: FloatingActionButton( diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 88fee77e0b..fd75788eb2 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -175,6 +175,8 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete /// [InputDecoration] surrounds the field in a border using [OutlineInputBorder] /// and adds a label. /// +/// ![A screenshot of the TextField widget](https://flutter.github.io/assets-for-api-docs/assets/material/text_field.png) +/// /// ```dart /// TextField( /// obscureText: true, diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 183ca3fffe..57a728b38e 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -3028,6 +3028,8 @@ class ListBody extends MultiChildRenderObjectWidget { /// /// 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) +/// /// ```dart /// Stack( /// children: [ @@ -3056,6 +3058,8 @@ class ListBody extends MultiChildRenderObjectWidget { /// This example shows how [Stack] can be used to enhance text visibility /// 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) +/// /// ```dart /// SizedBox( /// width: 250, @@ -3880,6 +3884,8 @@ class Flex extends MultiChildRenderObjectWidget { /// places text centered in the first two cells and the Flutter logo centered in /// the third: /// +/// ![A screenshot of the Row widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/row.png) +/// /// ```dart /// Row( /// children: [ @@ -3912,8 +3918,6 @@ class Flex extends MultiChildRenderObjectWidget { /// warning box on the edge that is overflowing. If there is room on the outside /// of the row, the amount of overflow is printed in red lettering. /// -/// {@tool sample} -/// /// #### Story time /// /// Suppose, for instance, that you had this code: @@ -3927,7 +3931,10 @@ class Flex extends MultiChildRenderObjectWidget { /// ], /// ) /// ``` -/// {@end-tool} +/// +/// You will see this issue when you run the app: +/// +/// ![A screenshot of the error using the Row widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/row_error.png) /// /// The row first asks its first child, the [FlutterLogo], to lay out, at /// whatever size the logo would like. The logo is friendly and happily decides @@ -3945,6 +3952,8 @@ class Flex extends MultiChildRenderObjectWidget { /// The fix is to wrap the second child in an [Expanded] widget, which tells the /// row that the child should be given the remaining room: /// +/// ![A screenshot of the Row widget after applying the fix](https://flutter.github.io/assets-for-api-docs/assets/widgets/row_fixed.png) +/// /// ```dart /// Row( /// children: [ @@ -4068,6 +4077,8 @@ class Row extends Flex { /// This example uses a [Column] to arrange three widgets vertically, the last /// 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) +/// /// ```dart /// Column( /// children: [ @@ -4091,6 +4102,8 @@ class Row extends Flex { /// [mainAxisSize] is set to [MainAxisSize.min], so that the column shrinks to /// 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) +/// /// ```dart /// Column( /// crossAxisAlignment: CrossAxisAlignment.start, diff --git a/packages/flutter/lib/src/widgets/image.dart b/packages/flutter/lib/src/widgets/image.dart index 1c12c8ffb6..208cbc8100 100644 --- a/packages/flutter/lib/src/widgets/image.dart +++ b/packages/flutter/lib/src/widgets/image.dart @@ -207,6 +207,31 @@ typedef ImageLoadingBuilder = Widget Function( /// The image is painted using [paintImage], which describes the meanings of the /// various fields on this class in more detail. /// +/// {@tool sample} +/// The default constructor can be used with any [ImageProvider], such as a +/// [NetworkImage], to display an image from the internet. +/// +/// ![An image of an owl displayed by the image widget](https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg) +/// +/// ```dart +/// const Image( +/// image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'), +/// ) +/// ``` +/// {@end-tool} +/// +/// {@tool sample} +/// The [Image] Widget also provides several constructors to display different +/// types of images for convenience. In this example, use the [Image.network] +/// constructor to display an image from the internet. +/// +/// ![An image of an owl displayed by the image widget using the shortcut constructor](https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg) +/// +/// ```dart +/// Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg') +/// ``` +/// {@end-tool} +/// /// See also: /// /// * [Icon], which shows an image from a font. diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index 18637dd8e9..ce8bbec27e 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -181,6 +181,13 @@ class DefaultTextStyle extends InheritedWidget { /// /// {@tool sample} /// +/// This example shows how to display text using the [Text] widget. If the text +/// overflows, it truncates the text with an ellipsis. +/// +/// ![A screenshot of the Text widget](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) +/// /// ```dart /// Text( /// 'Hello, $_name! How are you?', @@ -198,6 +205,8 @@ class DefaultTextStyle extends InheritedWidget { /// /// {@tool sample} /// +/// ![A screenshot of the following rich text example](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_rich.png) +/// /// ```dart /// const Text.rich( /// TextSpan(