@@ -5,10 +5,8 @@ import 'package:flutter/services.dart';
55import 'package:flutter/widgets.dart' ;
66import 'package:flutter/material.dart' ;
77
8- const double _kLeadingWidth =
9- kToolbarHeight; // So the leading button is square.
8+ const double _kLeadingWidth = kToolbarHeight;
109
11- // Bottom justify the kToolbarHeight child which may overflow the top.
1210class _ToolbarContainerLayout extends SingleChildLayoutDelegate {
1311 const _ToolbarContainerLayout ();
1412
@@ -31,115 +29,11 @@ class _ToolbarContainerLayout extends SingleChildLayoutDelegate {
3129 bool shouldRelayout (_ToolbarContainerLayout oldDelegate) => false ;
3230}
3331
34- /// A material design app bar.
35- ///
3632/// An app bar consists of a toolbar and potentially other widgets, such as a
37- /// [TabBar] and a [FlexibleSpaceBar] . App bars typically expose one or more
38- /// common [actions] with [IconButton] s which are optionally followed by a
39- /// [PopupMenuButton] for less common operations (sometimes called the "overflow
40- /// menu").
41- ///
42- /// App bars are typically used in the [Scaffold.appBar] property, which places
43- /// the app bar as a fixed-height widget at the top of the screen. For a scrollable
44- /// app bar, see [SliverGFAppBar] , which embeds an [GFAppBar] in a sliver for use in
45- /// a [CustomScrollView] .
46- ///
47- /// When not used as [Scaffold.appBar] , or when wrapped in a [Hero] , place the app
48- /// bar in a [MediaQuery] to take care of the padding around the content of the
49- /// app bar if needed, as the padding will not be handled by [Scaffold] .
50- ///
33+ /// [GFTabBar][TabBar] and a [FlexibleSpaceBar] .
5134/// The GFAppBar displays the toolbar widgets, [leading] , [title] , and [actions] ,
52- /// above the [bottom] (if any). The [bottom] is usually used for a [TabBar] . If
53- /// a [flexibleSpace] widget is specified then it is stacked behind the toolbar
54- /// and the bottom widget. The following diagram shows where each of these slots
55- /// appears in the toolbar when the writing language is left-to-right (e.g.
56- /// English):
57- ///
58- /// 
61- ///
62- /// If the [leading] widget is omitted, but the [GFAppBar] is in a [Scaffold] with
63- /// a [Drawer] , then a button will be inserted to open the drawer. Otherwise, if
64- /// the nearest [Navigator] has any previous routes, a [BackButton] is inserted
65- /// instead. This behavior can be turned off by setting the [automaticallyImplyLeading]
66- /// to false. In that case a null leading widget will result in the middle/title widget
67- /// stretching to start.
68- ///
69- /// {@tool dartpad --template=stateless_widget_material}
70- ///
71- /// This sample shows an [GFAppBar] with two simple actions. The first action
72- /// opens a [SnackBar] , while the second action navigates to a new page.
73- ///
74- /// ```dart preamble
75- /// final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
76- /// final SnackBar snackBar = const SnackBar(content: Text('Showing Snackbar'));
77- ///
78- /// void openPage(BuildContext context) {
79- /// Navigator.push(context, MaterialPageRoute(
80- /// builder: (BuildContext context) {
81- /// return Scaffold(
82- /// appBar: GFAppBar(
83- /// title: const Text('Next page'),
84- /// ),
85- /// body: const Center(
86- /// child: Text(
87- /// 'This is the next page',
88- /// style: TextStyle(fontSize: 24),
89- /// ),
90- /// ),
91- /// );
92- /// },
93- /// ));
94- /// }
95- /// ```
96- ///
97- /// ```dart
98- /// Widget build(BuildContext context) {
99- /// return Scaffold(
100- /// key: scaffoldKey,
101- /// appBar: GFAppBar(
102- /// title: const Text('GFAppBar Demo'),
103- /// actions: <Widget>[
104- /// IconButton(
105- /// icon: const Icon(Icons.add_alert),
106- /// tooltip: 'Show Snackbar',
107- /// onPressed: () {
108- /// scaffoldKey.currentState.showSnackBar(snackBar);
109- /// },
110- /// ),
111- /// IconButton(
112- /// icon: const Icon(Icons.navigate_next),
113- /// tooltip: 'Next page',
114- /// onPressed: () {
115- /// openPage(context);
116- /// },
117- /// ),
118- /// ],
119- /// ),
120- /// body: const Center(
121- /// child: Text(
122- /// 'This is the home page',
123- /// style: TextStyle(fontSize: 24),
124- /// ),
125- /// ),
126- /// );
127- /// }
128- /// ```
129- /// {@end-tool}
130- ///
131- /// See also:
132- ///
133- /// * [Scaffold] , which displays the [GFAppBar] in its [Scaffold.appBar] slot.
134- /// * [SliverGFAppBar] , which uses [GFAppBar] to provide a flexible app bar that
135- /// can be used in a [CustomScrollView].
136- /// * [TabBar] , which is typically placed in the [bottom] slot of the [GFAppBar]
137- /// if the screen has multiple pages arranged in tabs.
138- /// * [IconButton] , which is used with [actions] to show buttons on the app bar.
139- /// * [PopupMenuButton] , to show a popup menu on the app bar, via [actions] .
140- /// * [FlexibleSpaceBar] , which is used with [flexibleSpace] when the app bar
141- /// can expand and collapse.
142- /// * <https://material.io/design/components/app-bars-top.html>
35+ /// above the [bottom] (if any). The [bottom] is usually used for a [TabBar] .
36+
14337class GFAppBar extends StatefulWidget implements PreferredSizeWidget {
14438 /// Creates a material design app bar.
14539 ///
@@ -184,44 +78,6 @@ class GFAppBar extends StatefulWidget implements PreferredSizeWidget {
18478 super (key: key);
18579
18680 /// A widget to display before the [title] .
187- ///
188- /// If this is null and [automaticallyImplyLeading] is set to true, the
189- /// [GFAppBar] will imply an appropriate widget. For example, if the [GFAppBar] is
190- /// in a [Scaffold] that also has a [Drawer] , the [Scaffold] will fill this
191- /// widget with an [IconButton] that opens the drawer (using [Icons.menu] ). If
192- /// there's no [Drawer] and the parent [Navigator] can go back, the [GFAppBar]
193- /// will use a [BackButton] that calls [Navigator.maybePop] .
194- ///
195- /// {@tool sample}
196- ///
197- /// The following code shows how the drawer button could be manually specified
198- /// instead of relying on [automaticallyImplyLeading] :
199- ///
200- /// ```dart
201- /// GFAppBar(
202- /// leading: Builder(
203- /// builder: (BuildContext context) {
204- /// return IconButton(
205- /// icon: const Icon(Icons.menu),
206- /// onPressed: () { Scaffold.of(context).openDrawer(); },
207- /// tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
208- /// );
209- /// },
210- /// ),
211- /// )
212- /// ```
213- /// {@end-tool}
214- ///
215- /// The [Builder] is used in this example to ensure that the `context` refers
216- /// to that part of the subtree. That way this code snippet can be used even
217- /// inside the very code that is creating the [Scaffold] (in which case,
218- /// without the [Builder] , the `context` wouldn't be able to see the
219- /// [Scaffold] , since it would refer to an ancestor of that widget).
220- ///
221- /// See also:
222- ///
223- /// * [Scaffold.appBar] , in which an [GFAppBar] is usually placed.
224- /// * [Scaffold.drawer] , in which the [Drawer] is usually placed.
22581 final Widget leading;
22682
22783 /// Controls whether we should try to imply the leading widget if null.
@@ -817,65 +673,6 @@ class _SliverGFAppBarDelegate extends SliverPersistentHeaderDelegate {
817673/// [actions] , above the [bottom] (if any). If a [flexibleSpace] widget is
818674/// specified then it is stacked behind the toolbar and the bottom widget.
819675///
820- /// {@tool sample}
821- ///
822- /// This is an example that could be included in a [CustomScrollView] 's
823- /// [CustomScrollView.slivers] list:
824- ///
825- /// ```dart
826- /// SliverGFAppBar(
827- /// expandedHeight: 150.0,
828- /// flexibleSpace: const FlexibleSpaceBar(
829- /// title: Text('Available seats'),
830- /// ),
831- /// actions: <Widget>[
832- /// IconButton(
833- /// icon: const Icon(Icons.add_circle),
834- /// tooltip: 'Add new entry',
835- /// onPressed: () { /* ... */ },
836- /// ),
837- /// ]
838- /// )
839- /// ```
840- /// {@end-tool}
841- ///
842- /// ## Animated Examples
843- ///
844- /// The following animations show how app bars with different configurations
845- /// behave when a user scrolls up and then down again.
846- ///
847- /// * App bar with [floating] : false, [pinned] : false, [snap] : false:
848- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar.mp4}
849- ///
850- /// * App bar with [floating] : true, [pinned] : false, [snap] : false:
851- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating.mp4}
852- ///
853- /// * App bar with [floating] : true, [pinned] : false, [snap] : true:
854- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating_snap.mp4}
855- ///
856- /// * App bar with [floating] : true, [pinned] : true, [snap] : false:
857- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned_floating.mp4}
858- ///
859- /// * App bar with [floating] : true, [pinned] : true, [snap] : true:
860- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned_floating_snap.mp4}
861- ///
862- /// * App bar with [floating] : false, [pinned] : true, [snap] : false:
863- /// {@animation 476 400 https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_pinned.mp4}
864- ///
865- /// The property [snap] can only be set to true if [floating] is also true.
866- ///
867- /// See also:
868- ///
869- /// * [CustomScrollView] , which integrates the [SliverGFAppBar] into its
870- /// scrolling.
871- /// * [GFAppBar] , which is a fixed-height app bar for use in [Scaffold.appBar] .
872- /// * [TabBar] , which is typically placed in the [bottom] slot of the [GFAppBar]
873- /// if the screen has multiple pages arranged in tabs.
874- /// * [IconButton] , which is used with [actions] to show buttons on the app bar.
875- /// * [PopupMenuButton] , to show a popup menu on the app bar, via [actions] .
876- /// * [FlexibleSpaceBar] , which is used with [flexibleSpace] when the app bar
877- /// can expand and collapse.
878- /// * <https://material.io/design/components/app-bars-top.html>
879676class SliverGFAppBar extends StatefulWidget {
880677 /// Creates a material design app bar that can be placed in a [CustomScrollView] .
881678 ///
0 commit comments