From 95e1e5703319316aec23d804bf899652a623ce01 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 22 Oct 2015 11:17:20 -0700 Subject: [PATCH] Add Navigator.of Now you don't need to pass the navigator around everywhere. --- examples/address_book/lib/main.dart | 6 +- examples/fitness/lib/feed.dart | 20 ++--- examples/fitness/lib/measurement.dart | 25 ++++--- examples/fitness/lib/settings.dart | 18 +++-- examples/stocks/lib/main.dart | 2 +- examples/stocks/lib/stock_home.dart | 20 ++--- examples/stocks/lib/stock_menu.dart | 73 +++++++++---------- examples/stocks/lib/stock_settings.dart | 15 ++-- examples/stocks/lib/stock_symbol_viewer.dart | 7 +- examples/widgets/card_collection.dart | 10 +-- examples/widgets/indexed_stack.dart | 10 +-- examples/widgets/pageable_list.dart | 8 +- examples/widgets/scrollbar.dart | 6 +- sky/packages/sky/lib/src/material/dialog.dart | 6 +- sky/packages/sky/lib/src/material/drawer.dart | 5 +- .../sky/lib/src/material/popup_menu.dart | 19 ++--- .../sky/lib/src/material/snack_bar.dart | 4 +- sky/packages/sky/lib/src/widgets/heroes.dart | 7 +- .../sky/lib/src/widgets/navigator.dart | 18 ++++- sky/unit/test/widget/drawer_test.dart | 4 +- sky/unit/test/widget/snack_bar_test.dart | 2 +- 21 files changed, 139 insertions(+), 146 deletions(-) diff --git a/examples/address_book/lib/main.dart b/examples/address_book/lib/main.dart index 9f79aeeb00f..8bc9a8ea9b1 100644 --- a/examples/address_book/lib/main.dart +++ b/examples/address_book/lib/main.dart @@ -34,10 +34,6 @@ class Field extends StatelessComponent { } class AddressBookHome extends StatelessComponent { - AddressBookHome({ this.navigator }); - - final NavigatorState navigator; - Widget buildToolBar(BuildContext context) { return new ToolBar( left: new IconButton(icon: "navigation/arrow_back"), @@ -96,7 +92,7 @@ void main() { title: 'Address Book', theme: theme, routes: { - '/': (RouteArguments args) => new AddressBookHome(navigator: args.navigator) + '/': (RouteArguments args) => new AddressBookHome() } )); } diff --git a/examples/fitness/lib/feed.dart b/examples/fitness/lib/feed.dart index 4208a112fba..e49473ccf88 100644 --- a/examples/fitness/lib/feed.dart +++ b/examples/fitness/lib/feed.dart @@ -67,7 +67,7 @@ class FeedFragmentState extends State { void _showDrawer() { showDrawer( - navigator: config.navigator, + context: context, child: new Block([ new DrawerHeader(child: new Text('Fitness')), new DrawerItem( @@ -117,7 +117,7 @@ class FeedFragmentState extends State { void _handleItemDismissed(FitnessItem item) { config.onItemDeleted(item); showSnackBar( - navigator: config.navigator, + context: context, placeholderKey: _snackBarPlaceholderKey, content: new Text("Item deleted."), actions: [new SnackBarAction(label: "UNDO", onPressed: () { @@ -191,7 +191,7 @@ class FeedFragmentState extends State { } void _handleActionButtonPressed() { - showDialog(config.navigator, (NavigatorState navigator) => new AddItemDialog(navigator)).then((routeName) { + showDialog(context: context, child: new AddItemDialog()).then((routeName) { if (routeName != null) config.navigator.pushNamed(routeName); }); @@ -220,10 +220,6 @@ class FeedFragmentState extends State { } class AddItemDialog extends StatefulComponent { - AddItemDialog(this.navigator); - - final NavigatorState navigator; - AddItemDialogState createState() => new AddItemDialogState(); } @@ -253,16 +249,20 @@ class AddItemDialogState extends State { return new Dialog( title: new Text("What are you doing?"), content: new Block(menuItems), - onDismiss: config.navigator.pop, + onDismiss: () { + Navigator.of(context).pop(); + }, actions: [ new FlatButton( child: new Text('CANCEL'), - onPressed: config.navigator.pop + onPressed: () { + Navigator.of(context).pop(); + } ), new FlatButton( child: new Text('ADD'), onPressed: () { - config.navigator.pop(_addItemRoute); + Navigator.of(context).pop(_addItemRoute); } ), ] diff --git a/examples/fitness/lib/measurement.dart b/examples/fitness/lib/measurement.dart index 394d86c5070..eba6746a92c 100644 --- a/examples/fitness/lib/measurement.dart +++ b/examples/fitness/lib/measurement.dart @@ -55,9 +55,8 @@ class MeasurementRow extends FitnessItemRow { } class MeasurementDateDialog extends StatefulComponent { - MeasurementDateDialog({ this.navigator, this.previousDate }); + MeasurementDateDialog({ this.previousDate }); - final NavigatorState navigator; final DateTime previousDate; MeasurementDateDialogState createState() => new MeasurementDateDialogState(); @@ -89,12 +88,14 @@ class MeasurementDateDialogState extends State { actions: [ new FlatButton( child: new Text('CANCEL'), - onPressed: config.navigator.pop + onPressed: () { + Navigator.of(context).pop(); + } ), new FlatButton( child: new Text('OK'), onPressed: () { - config.navigator.pop(_selectedDate); + Navigator.of(context).pop(_selectedDate); } ), ] @@ -124,7 +125,7 @@ class MeasurementFragmentState extends State { } on FormatException catch(e) { print("Exception $e"); showSnackBar( - navigator: config.navigator, + context: context, placeholderKey: _snackBarPlaceholderKey, content: new Text('Save failed') ); @@ -157,16 +158,16 @@ class MeasurementFragmentState extends State { static final GlobalKey weightKey = new GlobalKey(); - void _handleDatePressed() { - showDialog(config.navigator, (NavigatorState navigator) { - return new MeasurementDateDialog(navigator: navigator, previousDate: _when); - }).then((DateTime value) { - if (value == null) - return; + Future _handleDatePressed() async { + DateTime value = await showDialog( + context: context, + child: new MeasurementDateDialog(previousDate: _when) + ); + if (value != null) { setState(() { _when = value; }); - }); + } } Widget buildBody(BuildContext context) { diff --git a/examples/fitness/lib/settings.dart b/examples/fitness/lib/settings.dart index f33b6f0c9c1..144ba29ac7f 100644 --- a/examples/fitness/lib/settings.dart +++ b/examples/fitness/lib/settings.dart @@ -60,9 +60,10 @@ class SettingsFragmentState extends State { } } - void _handleGoalWeightPressed() { - showDialog(config.navigator, (NavigatorState navigator) { - return new Dialog( + Future _handleGoalWeightPressed() async { + double goalWeight = await showDialog( + context: context, + child: new Dialog( title: new Text("Goal Weight"), content: new Input( key: weightGoalKey, @@ -71,24 +72,25 @@ class SettingsFragmentState extends State { onChanged: _handleGoalWeightChanged ), onDismiss: () { - navigator.pop(); + Navigator.of(context).pop(); }, actions: [ new FlatButton( child: new Text('CANCEL'), onPressed: () { - navigator.pop(); + Navigator.of(context).pop(); } ), new FlatButton( child: new Text('SAVE'), onPressed: () { - navigator.pop(_goalWeight); + Navigator.of(context).pop(_goalWeight); } ), ] - ); - }).then((double goalWeight) => config.updater(goalWeight: goalWeight)); + ) + ); + config.updater(goalWeight: goalWeight); } Widget buildSettingsPane(BuildContext context) { diff --git a/examples/stocks/lib/main.dart b/examples/stocks/lib/main.dart index 61e7d5d4d91..be7b9762956 100644 --- a/examples/stocks/lib/main.dart +++ b/examples/stocks/lib/main.dart @@ -81,7 +81,7 @@ class StocksAppState extends State { if (path.length != 3) return null; if (_stocks.containsKey(path[2])) - return (RouteArguments args) => new StockSymbolViewer(args.navigator, _stocks[path[2]]); + return (RouteArguments args) => new StockSymbolViewer(_stocks[path[2]]); return null; } return null; diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index e8b143ef39b..42d5db4776e 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -67,7 +67,8 @@ class StockHomeState extends State { } void _handleMenuShow() { - showStockMenu(config.navigator, + showStockMenu( + context: context, autorefresh: _autorefresh, onAutorefreshChanged: _handleAutorefreshChanged ); @@ -75,7 +76,7 @@ class StockHomeState extends State { void _showDrawer() { showDrawer( - navigator: config.navigator, + context: context, child: new Block([ new DrawerHeader(child: new Text('Stocks')), new DrawerItem( @@ -86,8 +87,9 @@ class StockHomeState extends State { new DrawerItem( icon: 'action/account_balance', onPressed: () { - showDialog(config.navigator, (NavigatorState navigator) { - return new Dialog( + showDialog( + context: context, + child: new Dialog( title: new Text('Not Implemented'), content: new Text('This feature has not yet been implemented.'), actions: [ @@ -95,18 +97,18 @@ class StockHomeState extends State { child: new Text('USE IT'), enabled: false, onPressed: () { - navigator.pop(false); + config.navigator.pop(false); } ), new FlatButton( child: new Text('OH WELL'), onPressed: () { - navigator.pop(false); + config.navigator.pop(false); } ), ] - ); - }); + ) + ); }, child: new Text('Account Balance') ), @@ -246,7 +248,7 @@ class StockHomeState extends State { void _handleStockPurchased() { showSnackBar( - navigator: config.navigator, + context: context, placeholderKey: _snackBarPlaceholderKey, content: new Text("Stock purchased!"), actions: [ diff --git a/examples/stocks/lib/stock_menu.dart b/examples/stocks/lib/stock_menu.dart index d6ab8b998fa..7d976ef19ec 100644 --- a/examples/stocks/lib/stock_menu.dart +++ b/examples/stocks/lib/stock_menu.dart @@ -8,44 +8,42 @@ enum _MenuItems { autorefresh, autorefreshCheckbox, add, remove } const double _kMenuMargin = 16.0; // 24.0 on tablet -Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged onAutorefreshChanged }) async { +Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged onAutorefreshChanged }) async { switch (await showMenu( - navigator: navigator, + context: context, position: new MenuPosition( right: ui.view.paddingRight + _kMenuMargin, top: ui.view.paddingTop + _kMenuMargin ), - builder: (NavigatorState navigator) { - return [ - new PopupMenuItem( - value: _MenuItems.autorefresh, - child: new Row([ - new Flexible(child: new Text('Autorefresh')), - new Checkbox( - value: autorefresh, - onChanged: (bool value) { - navigator.setState(() { - autorefresh = value; - }); - navigator.pop(_MenuItems.autorefreshCheckbox); - } - ) - ] - ) - ), - new PopupMenuItem( - value: _MenuItems.add, - child: new Text('Add stock') - ), - new PopupMenuItem( - value: _MenuItems.remove, - child: new Text('Remove stock') - ), - ]; - } + items: [ + new PopupMenuItem( + value: _MenuItems.autorefresh, + child: new Row([ + new Flexible(child: new Text('Autorefresh')), + new Checkbox( + value: autorefresh, + onChanged: (bool value) { + Navigator.of(context).setState(() { + autorefresh = value; + }); + Navigator.of(context).pop(_MenuItems.autorefreshCheckbox); + } + ) + ] + ) + ), + new PopupMenuItem( + value: _MenuItems.add, + child: new Text('Add stock') + ), + new PopupMenuItem( + value: _MenuItems.remove, + child: new Text('Remove stock') + ), + ] )) { case _MenuItems.autorefresh: - navigator.setState(() { + Navigator.of(context).setState(() { autorefresh = !autorefresh; }); continue autorefreshNotify; @@ -55,8 +53,9 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged break; case _MenuItems.add: case _MenuItems.remove: - await showDialog(navigator, (NavigatorState navigator) { - return new Dialog( + await showDialog( + context: context, + child: new Dialog( title: new Text('Not Implemented'), content: new Text('This feature has not yet been implemented.'), actions: [ @@ -76,14 +75,14 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged new FlatButton( child: new Text('OH WELL'), onPressed: () { - navigator.pop(false); + Navigator.of(context).pop(false); } ), ] - ); - }); + ) + ); break; default: // menu was canceled. } -} \ No newline at end of file +} diff --git a/examples/stocks/lib/stock_settings.dart b/examples/stocks/lib/stock_settings.dart index d618bae8cb6..c4acd403775 100644 --- a/examples/stocks/lib/stock_settings.dart +++ b/examples/stocks/lib/stock_settings.dart @@ -35,29 +35,30 @@ class StockSettingsState extends State { _handleOptimismChanged(false); break; case StockMode.pessimistic: - showDialog(config.navigator, (NavigatorState navigator) { - return new Dialog( + showDialog( + context: context, + child: new Dialog( title: new Text("Change mode?"), content: new Text("Optimistic mode means everything is awesome. Are you sure you can handle that?"), onDismiss: () { - navigator.pop(false); + config.navigator.pop(false); }, actions: [ new FlatButton( child: new Text('NO THANKS'), onPressed: () { - navigator.pop(false); + config.navigator.pop(false); } ), new FlatButton( child: new Text('AGREE'), onPressed: () { - navigator.pop(true); + config.navigator.pop(true); } ), ] - ); - }).then(_handleOptimismChanged); + ) + ).then(_handleOptimismChanged); break; } } diff --git a/examples/stocks/lib/stock_symbol_viewer.dart b/examples/stocks/lib/stock_symbol_viewer.dart index bef0c27f529..4ef3eb697b8 100644 --- a/examples/stocks/lib/stock_symbol_viewer.dart +++ b/examples/stocks/lib/stock_symbol_viewer.dart @@ -5,9 +5,8 @@ part of stocks; class StockSymbolViewer extends StatelessComponent { - StockSymbolViewer(this.navigator, this.stock); + StockSymbolViewer(this.stock); - final NavigatorState navigator; final Stock stock; Widget build(BuildContext context) { @@ -20,7 +19,9 @@ class StockSymbolViewer extends StatelessComponent { toolBar: new ToolBar( left: new IconButton( icon: 'navigation/arrow_back', - onPressed: navigator.pop + onPressed: () { + Navigator.of(context).pop(); + } ), center: new Text(stock.name) ), diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index 756e0fc6d5a..4e4619681d4 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -19,10 +19,6 @@ class CardModel { } class CardCollection extends StatefulComponent { - CardCollection({ this.navigator }); - - final NavigatorState navigator; - CardCollectionState createState() => new CardCollectionState(); } @@ -113,7 +109,7 @@ class CardCollectionState extends State { void _showDrawer() { showDrawer( - navigator: config.navigator, + context: context, child: new IconTheme( data: const IconThemeData(color: IconThemeColor.black), child: new Block([ @@ -169,7 +165,7 @@ class CardCollectionState extends State { setState(() { _dismissDirection = newDismissDirection; }); - config.navigator.pop(); + Navigator.of(context).pop(); } Widget buildDrawerCheckbox(String label, bool value, Function callback) { @@ -374,7 +370,7 @@ void main() { runApp(new MaterialApp( title: 'Cards', routes: { - '/': (RouteArguments args) => new CardCollection(navigator: args.navigator), + '/': (RouteArguments args) => new CardCollection(), } )); } diff --git a/examples/widgets/indexed_stack.dart b/examples/widgets/indexed_stack.dart index a4e6a25de19..7ee88bd0748 100644 --- a/examples/widgets/indexed_stack.dart +++ b/examples/widgets/indexed_stack.dart @@ -6,10 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; class IndexedStackDemo extends StatefulComponent { - IndexedStackDemo({ this.navigator }); - - final NavigatorState navigator; - IndexedStackDemoState createState() => new IndexedStackDemoState(); } @@ -23,7 +19,7 @@ class IndexedStackDemoState extends State { }); } - List _buildMenu(NavigatorState navigator) { + List _buildMenu() { TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold); String pad = ''; return new List.generate(_itemCount, (int i) { @@ -33,7 +29,7 @@ class IndexedStackDemoState extends State { } Widget build(BuildContext context) { - List items = _buildMenu(config.navigator); + List items = _buildMenu(); IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5); return new Scaffold( @@ -61,7 +57,7 @@ void main() { accentColor: Colors.redAccent[200] ), routes: { - '/': (RouteArguments args) => new IndexedStackDemo(navigator: args.navigator), + '/': (RouteArguments args) => new IndexedStackDemo(), } )); } diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 98a5e0fdb54..2ee218b78b6 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -15,10 +15,6 @@ class CardModel { } class PageableListApp extends StatefulComponent { - PageableListApp({ this.navigator }); - - final NavigatorState navigator; - PageableListAppState createState() => new PageableListAppState(); } @@ -89,7 +85,7 @@ class PageableListAppState extends State { void _showDrawer() { showDrawer( - navigator: config.navigator, + context: context, child: new Block([ new DrawerHeader(child: new Text('Options')), new DrawerItem( @@ -161,7 +157,7 @@ void main() { accentColor: Colors.redAccent[200] ), routes: { - '/': (RouteArguments args) => new PageableListApp(navigator: args.navigator), + '/': (RouteArguments args) => new PageableListApp(), } )); } diff --git a/examples/widgets/scrollbar.dart b/examples/widgets/scrollbar.dart index 66893bc7bdc..31a9d0f72ef 100644 --- a/examples/widgets/scrollbar.dart +++ b/examples/widgets/scrollbar.dart @@ -6,10 +6,6 @@ import 'package:intl/intl.dart'; import 'package:flutter/material.dart'; class ScrollbarApp extends StatefulComponent { - ScrollbarApp({ this.navigator }); - - final NavigatorState navigator; - ScrollbarAppState createState() => new ScrollbarAppState(); } @@ -65,7 +61,7 @@ void main() { accentColor: Colors.redAccent[200] ), routes: { - '/': (RouteArguments args) => new ScrollbarApp(navigator: args.navigator), + '/': (RouteArguments args) => new ScrollbarApp(), } )); } diff --git a/sky/packages/sky/lib/src/material/dialog.dart b/sky/packages/sky/lib/src/material/dialog.dart index e31b2f5f07d..934b672b340 100644 --- a/sky/packages/sky/lib/src/material/dialog.dart +++ b/sky/packages/sky/lib/src/material/dialog.dart @@ -153,15 +153,15 @@ class _DialogRoute extends PerformanceRoute { } } -Future showDialog(NavigatorState navigator, DialogBuilder builder) { +Future showDialog({ BuildContext context, Widget child }) { Completer completer = new Completer(); - navigator.push(new _DialogRoute( + Navigator.of(context).push(new _DialogRoute( completer: completer, builder: (RouteArguments args) { return new Focus( key: new GlobalObjectKey(completer), autofocus: true, - child: builder(args.navigator) + child: child ); } )); diff --git a/sky/packages/sky/lib/src/material/drawer.dart b/sky/packages/sky/lib/src/material/drawer.dart index 4f9151cacf0..bfc7796ac1d 100644 --- a/sky/packages/sky/lib/src/material/drawer.dart +++ b/sky/packages/sky/lib/src/material/drawer.dart @@ -169,7 +169,6 @@ class _DrawerRoute extends Route { } } -void showDrawer({ NavigatorState navigator, Widget child, int level: 3 }) { - assert(navigator != null); - navigator.push(new _DrawerRoute(child: child, level: level)); +void showDrawer({ BuildContext context, Widget child, int level: 3 }) { + Navigator.of(context).push(new _DrawerRoute(child: child, level: level)); } diff --git a/sky/packages/sky/lib/src/material/popup_menu.dart b/sky/packages/sky/lib/src/material/popup_menu.dart index 38dd1651494..8954fe4f94f 100644 --- a/sky/packages/sky/lib/src/material/popup_menu.dart +++ b/sky/packages/sky/lib/src/material/popup_menu.dart @@ -22,14 +22,11 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep; const double _kMenuHorizontalPadding = 16.0; const double _kMenuVerticalPadding = 8.0; -typedef List PopupMenuItemsBuilder(NavigatorState navigator); - class PopupMenu extends StatelessComponent { PopupMenu({ Key key, this.items, this.level: 4, - this.navigator, this.performance }) : super(key: key) { assert(items != null); @@ -38,7 +35,6 @@ class PopupMenu extends StatelessComponent { final List items; final int level; - final NavigatorState navigator; final PerformanceView performance; Widget build(BuildContext context) { @@ -58,7 +54,7 @@ class PopupMenu extends StatelessComponent { performance: performance, opacity: new AnimatedValue(0.0, end: 1.0, curve: new Interval(start, end)), child: new InkWell( - onTap: () { navigator.pop(items[i].value); }, + onTap: () { Navigator.of(context).pop(items[i].value); }, child: items[i] )) ); @@ -114,11 +110,11 @@ class MenuPosition { } class _MenuRoute extends PerformanceRoute { - _MenuRoute({ this.completer, this.position, this.builder, this.level }); + _MenuRoute({ this.completer, this.position, this.items, this.level }); final Completer completer; final MenuPosition position; - final PopupMenuItemsBuilder builder; + final List items; final int level; Performance createPerformance() { @@ -144,9 +140,8 @@ class _MenuRoute extends PerformanceRoute { key: new GlobalObjectKey(this), autofocus: true, child: new PopupMenu( - items: builder != null ? builder(navigator) : const [], + items: items, level: level, - navigator: navigator, performance: performance ) ) @@ -159,12 +154,12 @@ class _MenuRoute extends PerformanceRoute { } } -Future showMenu({ NavigatorState navigator, MenuPosition position, PopupMenuItemsBuilder builder, int level: 4 }) { +Future showMenu({ BuildContext context, MenuPosition position, List items, int level: 4 }) { Completer completer = new Completer(); - navigator.push(new _MenuRoute( + Navigator.of(context).push(new _MenuRoute( completer: completer, position: position, - builder: builder, + items: items, level: level )); return completer.future; diff --git a/sky/packages/sky/lib/src/material/snack_bar.dart b/sky/packages/sky/lib/src/material/snack_bar.dart index 7a0683e06aa..67838365558 100644 --- a/sky/packages/sky/lib/src/material/snack_bar.dart +++ b/sky/packages/sky/lib/src/material/snack_bar.dart @@ -105,7 +105,7 @@ class _SnackBarRoute extends PerformanceRoute { Widget build(RouteArguments args) => null; } -void showSnackBar({ NavigatorState navigator, GlobalKey placeholderKey, Widget content, List actions }) { +void showSnackBar({ BuildContext context, GlobalKey placeholderKey, Widget content, List actions }) { Route route = new _SnackBarRoute(); SnackBar snackBar = new SnackBar( content: content, @@ -113,5 +113,5 @@ void showSnackBar({ NavigatorState navigator, GlobalKey placeh performance: route.performance ); placeholderKey.currentState.child = snackBar; - navigator.push(route); + Navigator.of(context).push(route); } diff --git a/sky/packages/sky/lib/src/widgets/heroes.dart b/sky/packages/sky/lib/src/widgets/heroes.dart index cb0465c7129..49723869aba 100644 --- a/sky/packages/sky/lib/src/widgets/heroes.dart +++ b/sky/packages/sky/lib/src/widgets/heroes.dart @@ -7,7 +7,6 @@ import 'package:flutter/rendering.dart'; import 'basic.dart'; import 'framework.dart'; -import 'navigator.dart'; import 'transitions.dart'; // Heroes are the parts of an application's screen-to-screen transitions where a @@ -51,7 +50,7 @@ import 'transitions.dart'; // TODO(ianh): If the widgets use Inherited properties, they are taken from the // Navigator's position in the widget hierarchy, not the source or target. We // should interpolate the inherited properties from their value at the source to -// their value at the target. See: https://github.com/flutter/engine/issues/1698 +// their value at the target. See: https://github.com/flutter/engine/issues/1698 final Object centerOfAttentionHeroTag = new Object(); @@ -77,7 +76,6 @@ abstract class HeroHandle { class Hero extends StatefulComponent { Hero({ Key key, - this.navigator, this.tag, this.child, this.turns: 1 @@ -85,7 +83,6 @@ class Hero extends StatefulComponent { assert(tag != null); } - final NavigatorState navigator; final Object tag; final Widget child; final int turns; @@ -205,7 +202,7 @@ class HeroState extends State implements HeroHandle { child: config.child ) ); - case _HeroMode.taken: + case _HeroMode.taken: return new SizedBox(width: _size.width, height: _size.height); } } diff --git a/sky/packages/sky/lib/src/widgets/navigator.dart b/sky/packages/sky/lib/src/widgets/navigator.dart index df59effe94e..b8c072a77aa 100644 --- a/sky/packages/sky/lib/src/widgets/navigator.dart +++ b/sky/packages/sky/lib/src/widgets/navigator.dart @@ -47,6 +47,22 @@ class Navigator extends StatefulComponent { final RouteGenerator onGenerateRoute; final RouteBuilder onUnknownRoute; + static NavigatorState of(BuildContext context) { + NavigatorState result; + bool visitor(Element element) { + if (element is StatefulComponentElement) { + if (element.state is NavigatorState) { + result = element.state; + return false; + } + } + return true; + } + if (visitor(context)) + context.visitAncestorElements(visitor); + return result; + } + NavigatorState createState() => new NavigatorState(); } @@ -54,7 +70,7 @@ class Navigator extends StatefulComponent { // It also animates between these pages. // Pages can have "heroes", which are UI elements that animate from point to point. // These animations are called journeys. -// +// // Journeys can start in two conditions: // - Everything is calm, and we have no heroes in flight. In this case, we will // have to collect the heroes from the route we're starting at and the route diff --git a/sky/unit/test/widget/drawer_test.dart b/sky/unit/test/widget/drawer_test.dart index cc5fe28eae4..0406bf5d4ce 100644 --- a/sky/unit/test/widget/drawer_test.dart +++ b/sky/unit/test/widget/drawer_test.dart @@ -21,7 +21,7 @@ void main() { ); tester.pump(); // no effect expect(tester.findText('drawer'), isNull); - showDrawer(navigator: navigator, child: new Text('drawer')); + showDrawer(context: navigator.context, child: new Text('drawer')); tester.pump(); // drawer should be starting to animate in expect(tester.findText('drawer'), isNotNull); tester.pump(new Duration(seconds: 1)); // animation done @@ -50,7 +50,7 @@ void main() { ); tester.pump(); // no effect expect(tester.findText('drawer'), isNull); - showDrawer(navigator: navigator, child: new Text('drawer')); + showDrawer(context: navigator.context, child: new Text('drawer')); tester.pump(); // drawer should be starting to animate in expect(tester.findText('drawer'), isNotNull); tester.pump(new Duration(seconds: 1)); // animation done diff --git a/sky/unit/test/widget/snack_bar_test.dart b/sky/unit/test/widget/snack_bar_test.dart index 606a5b16287..3b431385035 100644 --- a/sky/unit/test/widget/snack_bar_test.dart +++ b/sky/unit/test/widget/snack_bar_test.dart @@ -16,7 +16,7 @@ void main() { return new GestureDetector( onTap: () { showSnackBar( - navigator: args.navigator, + context: args.navigator.context, placeholderKey: placeholderKey, content: new Text(helloSnackBar) );