diff --git a/examples/address_book/lib/main.dart b/examples/address_book/lib/main.dart index 18359b60b6..c0694983d8 100644 --- a/examples/address_book/lib/main.dart +++ b/examples/address_book/lib/main.dart @@ -36,9 +36,8 @@ class Field extends StatelessComponent { class AddressBookHome extends StatelessComponent { Widget buildToolBar(BuildContext context) { return new ToolBar( - left: new IconButton(icon: "navigation/arrow_back"), - right: [new IconButton(icon: "navigation/check")] - ); + right: [new IconButton(icon: "navigation/check")] + ); } Widget buildFloatingActionButton(BuildContext context) { diff --git a/examples/fitness/lib/feed.dart b/examples/fitness/lib/feed.dart index 1389cd98a9..558f035b81 100644 --- a/examples/fitness/lib/feed.dart +++ b/examples/fitness/lib/feed.dart @@ -55,7 +55,6 @@ class FeedFragment extends StatefulComponent { class FeedFragmentState extends State { FitnessMode _fitnessMode = FitnessMode.feed; - final GlobalKey _scaffoldKey = new GlobalKey(); void _handleFitnessModeChange(FitnessMode value) { setState(() { @@ -104,9 +103,6 @@ class FeedFragmentState extends State { Widget buildToolBar() { return new ToolBar( - left: new IconButton( - icon: "navigation/menu", - onPressed: () => _scaffoldKey.currentState?.openDrawer()), center: new Text(fitnessModeTitle) ); } @@ -207,7 +203,6 @@ class FeedFragmentState extends State { Widget build(BuildContext context) { return new Scaffold( - key: _scaffoldKey, toolBar: buildToolBar(), body: buildBody(), floatingActionButton: buildFloatingActionButton(), diff --git a/examples/fitness/lib/settings.dart b/examples/fitness/lib/settings.dart index 35e30008ca..5115f9d220 100644 --- a/examples/fitness/lib/settings.dart +++ b/examples/fitness/lib/settings.dart @@ -26,10 +26,6 @@ class SettingsFragmentState extends State { Widget buildToolBar() { return new ToolBar( - left: new IconButton( - icon: "navigation/arrow_back", - onPressed: () => Navigator.pop(context) - ), center: new Text('Settings') ); } diff --git a/examples/material_gallery/lib/gallery_page.dart b/examples/material_gallery/lib/gallery_page.dart index d5ae8c64ed..0d56461b01 100644 --- a/examples/material_gallery/lib/gallery_page.dart +++ b/examples/material_gallery/lib/gallery_page.dart @@ -17,8 +17,6 @@ class GalleryPage extends StatefulComponent { } class _GalleryPageState extends State { - final GlobalKey _scaffoldKey = new GlobalKey(); - Widget _buildDrawer() { List items = [ new DrawerHeader(child: new Text('Material demos')), @@ -53,12 +51,7 @@ class _GalleryPageState extends State { Widget build(BuildContext context) { return new Scaffold( - key: _scaffoldKey, toolBar: new ToolBar( - left: new IconButton( - icon: 'navigation/menu', - onPressed: () { _scaffoldKey.currentState?.openDrawer(); } - ), center: new Text(config.active?.title ?? 'Material gallery'), tabBar: _buildTabBar() ), diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index 0676f498c6..ccc5ee2805 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -147,10 +147,6 @@ class StockHomeState extends State { Widget buildToolBar() { return new ToolBar( elevation: 0, - left: new IconButton( - icon: "navigation/menu", - onPressed: () => _scaffoldKey.currentState?.openDrawer() - ), center: new Text('Stocks'), right: [ new IconButton( @@ -230,7 +226,7 @@ class StockHomeState extends State { Widget buildSearchBar() { return new ToolBar( left: new IconButton( - icon: "navigation/arrow_back", + icon: 'navigation/arrow_back', colorFilter: new ColorFilter.mode(Theme.of(context).accentColor, ui.TransferMode.srcATop), onPressed: _handleSearchEnd ), diff --git a/examples/stocks/lib/stock_settings.dart b/examples/stocks/lib/stock_settings.dart index 68b4793810..1fe46e5009 100644 --- a/examples/stocks/lib/stock_settings.dart +++ b/examples/stocks/lib/stock_settings.dart @@ -70,10 +70,6 @@ class StockSettingsState extends State { Widget buildToolBar(BuildContext context) { return new ToolBar( - left: new IconButton( - icon: 'navigation/arrow_back', - onPressed: () => Navigator.pop(context) - ), center: new Text('Settings') ); } diff --git a/examples/stocks/lib/stock_symbol_viewer.dart b/examples/stocks/lib/stock_symbol_viewer.dart index b6cae7ce9c..c98d873caa 100644 --- a/examples/stocks/lib/stock_symbol_viewer.dart +++ b/examples/stocks/lib/stock_symbol_viewer.dart @@ -55,12 +55,6 @@ class StockSymbolPage extends StatelessComponent { Widget build(BuildContext context) { return new Scaffold( toolBar: new ToolBar( - left: new IconButton( - icon: 'navigation/arrow_back', - onPressed: () { - Navigator.pop(context); - } - ), center: new Text(stock.name) ), body: new Block([ diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index 3c855a93c6..ce81b53e0e 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -46,8 +46,6 @@ class CardCollectionState extends State { InvalidatorCallback _invalidator; Size _cardCollectionSize = new Size(200.0, 200.0); - GlobalKey _scaffoldKey = new GlobalKey(); - void _initVariableSizedCardModels() { List cardHeights = [ 48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0, @@ -268,7 +266,6 @@ class CardCollectionState extends State { Widget _buildToolBar() { return new ToolBar( - left: new IconButton(icon: "navigation/menu", onPressed: () => _scaffoldKey.currentState?.openDrawer()), right: [ new Text(_dismissDirectionText(_dismissDirection)) ], diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 68b6855acd..fd7a5fcf75 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -41,8 +41,6 @@ class PageableListAppState extends State { ScrollDirection scrollDirection = ScrollDirection.horizontal; bool itemsWrap = false; - GlobalKey _scaffoldKey = new GlobalKey(); - void updatePageSize(Size newSize) { setState(() { pageSize = newSize; @@ -114,7 +112,6 @@ class PageableListAppState extends State { Widget _buildToolBar() { return new ToolBar( - left: new IconButton(icon: "navigation/menu", onPressed: () => _scaffoldKey.currentState?.openDrawer()), center: new Text('PageableList'), right: [ new Text(scrollDirection == ScrollDirection.horizontal ? "horizontal" : "vertical") diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index b9a0ce9bd5..6bfc5b6b1a 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -16,6 +16,7 @@ import 'material.dart'; import 'snack_bar.dart'; import 'tool_bar.dart'; import 'drawer.dart'; +import 'icon_button.dart'; const double _kFloatingActionButtonMargin = 16.0; // TODO(hmuller): should be device dependent @@ -257,8 +258,37 @@ class ScaffoldState extends State { children.add(new LayoutId(child: child, id: childId)); } + bool _shouldShowBackArrow; + + Widget get _modifiedToolBar { + ToolBar toolBar = config.toolBar; + if (toolBar == null) + return null; + EdgeDims padding = new EdgeDims.only(top: ui.window.padding.top); + Widget left = toolBar.left; + if (left == null) { + if (config.drawer != null) { + left = new IconButton( + icon: 'navigation/menu', + onPressed: openDrawer + ); + } else { + _shouldShowBackArrow ??= Navigator.canPop(context); + if (_shouldShowBackArrow) { + left = new IconButton( + icon: 'navigation/arrow_back', + onPressed: () => Navigator.pop(context) + ); + } + } + } + return toolBar.copyWith( + padding: padding, + left: left + ); + } + Widget build(BuildContext context) { - final Widget paddedToolBar = config.toolBar?.withPadding(new EdgeDims.only(top: ui.window.padding.top)); final Widget materialBody = config.body != null ? new Material(child: config.body) : null; if (_snackBars.length > 0) { @@ -274,7 +304,7 @@ class ScaffoldState extends State { final Listchildren = new List(); _addIfNonNull(children, materialBody, _Child.body); - _addIfNonNull(children, paddedToolBar, _Child.toolBar); + _addIfNonNull(children, _modifiedToolBar, _Child.toolBar); if (_currentBottomSheet != null || (_dismissedBottomSheets != null && _dismissedBottomSheets.isNotEmpty)) { diff --git a/packages/flutter/lib/src/material/tool_bar.dart b/packages/flutter/lib/src/material/tool_bar.dart index 08c4ac707f..f0a682977c 100644 --- a/packages/flutter/lib/src/material/tool_bar.dart +++ b/packages/flutter/lib/src/material/tool_bar.dart @@ -36,18 +36,28 @@ class ToolBar extends StatelessComponent { final TextTheme textTheme; final EdgeDims padding; - ToolBar withPadding(EdgeDims newPadding, { Key fallbackKey }) { + ToolBar copyWith({ + Key key, + Widget left, + Widget center, + List right, + Widget bottom, + int elevation, + Color backgroundColor, + TextTheme textTheme, + EdgeDims padding + }) { return new ToolBar( - key: key ?? fallbackKey, - left: left, - center: center, - right: right, - bottom: bottom, - tabBar: tabBar, - elevation: elevation, - backgroundColor: backgroundColor, - textTheme: textTheme, - padding: newPadding + key: key ?? this.key, + left: left ?? this.left, + center: center ?? this.center, + right: right ?? this.right, + bottom: bottom ?? this.bottom, + tabBar: tabBar ?? this.tabBar, + elevation: elevation ?? this.elevation, + backgroundColor: backgroundColor ?? this.backgroundColor, + textTheme: textTheme ?? this.textTheme, + padding: padding ?? this.padding ); }