Commit de395582 authored by Adam Barth's avatar Adam Barth

Add Navigator.of

Now you don't need to pass the navigator around everywhere.
parent 35bd448b
...@@ -34,10 +34,6 @@ class Field extends StatelessComponent { ...@@ -34,10 +34,6 @@ class Field extends StatelessComponent {
} }
class AddressBookHome extends StatelessComponent { class AddressBookHome extends StatelessComponent {
AddressBookHome({ this.navigator });
final NavigatorState navigator;
Widget buildToolBar(BuildContext context) { Widget buildToolBar(BuildContext context) {
return new ToolBar( return new ToolBar(
left: new IconButton(icon: "navigation/arrow_back"), left: new IconButton(icon: "navigation/arrow_back"),
...@@ -96,7 +92,7 @@ void main() { ...@@ -96,7 +92,7 @@ void main() {
title: 'Address Book', title: 'Address Book',
theme: theme, theme: theme,
routes: <String, RouteBuilder>{ routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new AddressBookHome(navigator: args.navigator) '/': (RouteArguments args) => new AddressBookHome()
} }
)); ));
} }
...@@ -67,7 +67,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -67,7 +67,7 @@ class FeedFragmentState extends State<FeedFragment> {
void _showDrawer() { void _showDrawer() {
showDrawer( showDrawer(
navigator: config.navigator, context: context,
child: new Block([ child: new Block([
new DrawerHeader(child: new Text('Fitness')), new DrawerHeader(child: new Text('Fitness')),
new DrawerItem( new DrawerItem(
...@@ -117,7 +117,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -117,7 +117,7 @@ class FeedFragmentState extends State<FeedFragment> {
void _handleItemDismissed(FitnessItem item) { void _handleItemDismissed(FitnessItem item) {
config.onItemDeleted(item); config.onItemDeleted(item);
showSnackBar( showSnackBar(
navigator: config.navigator, context: context,
placeholderKey: _snackBarPlaceholderKey, placeholderKey: _snackBarPlaceholderKey,
content: new Text("Item deleted."), content: new Text("Item deleted."),
actions: [new SnackBarAction(label: "UNDO", onPressed: () { actions: [new SnackBarAction(label: "UNDO", onPressed: () {
...@@ -191,7 +191,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -191,7 +191,7 @@ class FeedFragmentState extends State<FeedFragment> {
} }
void _handleActionButtonPressed() { void _handleActionButtonPressed() {
showDialog(config.navigator, (NavigatorState navigator) => new AddItemDialog(navigator)).then((routeName) { showDialog(context: context, child: new AddItemDialog()).then((routeName) {
if (routeName != null) if (routeName != null)
config.navigator.pushNamed(routeName); config.navigator.pushNamed(routeName);
}); });
...@@ -220,10 +220,6 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -220,10 +220,6 @@ class FeedFragmentState extends State<FeedFragment> {
} }
class AddItemDialog extends StatefulComponent { class AddItemDialog extends StatefulComponent {
AddItemDialog(this.navigator);
final NavigatorState navigator;
AddItemDialogState createState() => new AddItemDialogState(); AddItemDialogState createState() => new AddItemDialogState();
} }
...@@ -253,16 +249,20 @@ class AddItemDialogState extends State<AddItemDialog> { ...@@ -253,16 +249,20 @@ class AddItemDialogState extends State<AddItemDialog> {
return new Dialog( return new Dialog(
title: new Text("What are you doing?"), title: new Text("What are you doing?"),
content: new Block(menuItems), content: new Block(menuItems),
onDismiss: config.navigator.pop, onDismiss: () {
Navigator.of(context).pop();
},
actions: [ actions: [
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: config.navigator.pop onPressed: () {
Navigator.of(context).pop();
}
), ),
new FlatButton( new FlatButton(
child: new Text('ADD'), child: new Text('ADD'),
onPressed: () { onPressed: () {
config.navigator.pop(_addItemRoute); Navigator.of(context).pop(_addItemRoute);
} }
), ),
] ]
......
...@@ -55,9 +55,8 @@ class MeasurementRow extends FitnessItemRow { ...@@ -55,9 +55,8 @@ class MeasurementRow extends FitnessItemRow {
} }
class MeasurementDateDialog extends StatefulComponent { class MeasurementDateDialog extends StatefulComponent {
MeasurementDateDialog({ this.navigator, this.previousDate }); MeasurementDateDialog({ this.previousDate });
final NavigatorState navigator;
final DateTime previousDate; final DateTime previousDate;
MeasurementDateDialogState createState() => new MeasurementDateDialogState(); MeasurementDateDialogState createState() => new MeasurementDateDialogState();
...@@ -89,12 +88,14 @@ class MeasurementDateDialogState extends State<MeasurementDateDialog> { ...@@ -89,12 +88,14 @@ class MeasurementDateDialogState extends State<MeasurementDateDialog> {
actions: [ actions: [
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: config.navigator.pop onPressed: () {
Navigator.of(context).pop();
}
), ),
new FlatButton( new FlatButton(
child: new Text('OK'), child: new Text('OK'),
onPressed: () { onPressed: () {
config.navigator.pop(_selectedDate); Navigator.of(context).pop(_selectedDate);
} }
), ),
] ]
...@@ -124,7 +125,7 @@ class MeasurementFragmentState extends State<MeasurementFragment> { ...@@ -124,7 +125,7 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
} on FormatException catch(e) { } on FormatException catch(e) {
print("Exception $e"); print("Exception $e");
showSnackBar( showSnackBar(
navigator: config.navigator, context: context,
placeholderKey: _snackBarPlaceholderKey, placeholderKey: _snackBarPlaceholderKey,
content: new Text('Save failed') content: new Text('Save failed')
); );
...@@ -157,16 +158,16 @@ class MeasurementFragmentState extends State<MeasurementFragment> { ...@@ -157,16 +158,16 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
static final GlobalKey weightKey = new GlobalKey(); static final GlobalKey weightKey = new GlobalKey();
void _handleDatePressed() { Future _handleDatePressed() async {
showDialog(config.navigator, (NavigatorState navigator) { DateTime value = await showDialog(
return new MeasurementDateDialog(navigator: navigator, previousDate: _when); context: context,
}).then((DateTime value) { child: new MeasurementDateDialog(previousDate: _when)
if (value == null) );
return; if (value != null) {
setState(() { setState(() {
_when = value; _when = value;
}); });
}); }
} }
Widget buildBody(BuildContext context) { Widget buildBody(BuildContext context) {
......
...@@ -60,9 +60,10 @@ class SettingsFragmentState extends State<SettingsFragment> { ...@@ -60,9 +60,10 @@ class SettingsFragmentState extends State<SettingsFragment> {
} }
} }
void _handleGoalWeightPressed() { Future _handleGoalWeightPressed() async {
showDialog(config.navigator, (NavigatorState navigator) { double goalWeight = await showDialog(
return new Dialog( context: context,
child: new Dialog(
title: new Text("Goal Weight"), title: new Text("Goal Weight"),
content: new Input( content: new Input(
key: weightGoalKey, key: weightGoalKey,
...@@ -71,24 +72,25 @@ class SettingsFragmentState extends State<SettingsFragment> { ...@@ -71,24 +72,25 @@ class SettingsFragmentState extends State<SettingsFragment> {
onChanged: _handleGoalWeightChanged onChanged: _handleGoalWeightChanged
), ),
onDismiss: () { onDismiss: () {
navigator.pop(); Navigator.of(context).pop();
}, },
actions: [ actions: [
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: () { onPressed: () {
navigator.pop(); Navigator.of(context).pop();
} }
), ),
new FlatButton( new FlatButton(
child: new Text('SAVE'), child: new Text('SAVE'),
onPressed: () { onPressed: () {
navigator.pop(_goalWeight); Navigator.of(context).pop(_goalWeight);
} }
), ),
] ]
)
); );
}).then((double goalWeight) => config.updater(goalWeight: goalWeight)); config.updater(goalWeight: goalWeight);
} }
Widget buildSettingsPane(BuildContext context) { Widget buildSettingsPane(BuildContext context) {
......
...@@ -81,7 +81,7 @@ class StocksAppState extends State<StocksApp> { ...@@ -81,7 +81,7 @@ class StocksAppState extends State<StocksApp> {
if (path.length != 3) if (path.length != 3)
return null; return null;
if (_stocks.containsKey(path[2])) 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;
} }
return null; return null;
......
...@@ -67,7 +67,8 @@ class StockHomeState extends State<StockHome> { ...@@ -67,7 +67,8 @@ class StockHomeState extends State<StockHome> {
} }
void _handleMenuShow() { void _handleMenuShow() {
showStockMenu(config.navigator, showStockMenu(
context: context,
autorefresh: _autorefresh, autorefresh: _autorefresh,
onAutorefreshChanged: _handleAutorefreshChanged onAutorefreshChanged: _handleAutorefreshChanged
); );
...@@ -75,7 +76,7 @@ class StockHomeState extends State<StockHome> { ...@@ -75,7 +76,7 @@ class StockHomeState extends State<StockHome> {
void _showDrawer() { void _showDrawer() {
showDrawer( showDrawer(
navigator: config.navigator, context: context,
child: new Block(<Widget>[ child: new Block(<Widget>[
new DrawerHeader(child: new Text('Stocks')), new DrawerHeader(child: new Text('Stocks')),
new DrawerItem( new DrawerItem(
...@@ -86,8 +87,9 @@ class StockHomeState extends State<StockHome> { ...@@ -86,8 +87,9 @@ class StockHomeState extends State<StockHome> {
new DrawerItem( new DrawerItem(
icon: 'action/account_balance', icon: 'action/account_balance',
onPressed: () { onPressed: () {
showDialog(config.navigator, (NavigatorState navigator) { showDialog(
return new Dialog( context: context,
child: new Dialog(
title: new Text('Not Implemented'), title: new Text('Not Implemented'),
content: new Text('This feature has not yet been implemented.'), content: new Text('This feature has not yet been implemented.'),
actions: <Widget>[ actions: <Widget>[
...@@ -95,18 +97,18 @@ class StockHomeState extends State<StockHome> { ...@@ -95,18 +97,18 @@ class StockHomeState extends State<StockHome> {
child: new Text('USE IT'), child: new Text('USE IT'),
enabled: false, enabled: false,
onPressed: () { onPressed: () {
navigator.pop(false); config.navigator.pop(false);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('OH WELL'), child: new Text('OH WELL'),
onPressed: () { onPressed: () {
navigator.pop(false); config.navigator.pop(false);
} }
), ),
] ]
)
); );
});
}, },
child: new Text('Account Balance') child: new Text('Account Balance')
), ),
...@@ -246,7 +248,7 @@ class StockHomeState extends State<StockHome> { ...@@ -246,7 +248,7 @@ class StockHomeState extends State<StockHome> {
void _handleStockPurchased() { void _handleStockPurchased() {
showSnackBar( showSnackBar(
navigator: config.navigator, context: context,
placeholderKey: _snackBarPlaceholderKey, placeholderKey: _snackBarPlaceholderKey,
content: new Text("Stock purchased!"), content: new Text("Stock purchased!"),
actions: <SnackBarAction>[ actions: <SnackBarAction>[
......
...@@ -8,15 +8,14 @@ enum _MenuItems { autorefresh, autorefreshCheckbox, add, remove } ...@@ -8,15 +8,14 @@ enum _MenuItems { autorefresh, autorefreshCheckbox, add, remove }
const double _kMenuMargin = 16.0; // 24.0 on tablet 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( switch (await showMenu(
navigator: navigator, context: context,
position: new MenuPosition( position: new MenuPosition(
right: ui.view.paddingRight + _kMenuMargin, right: ui.view.paddingRight + _kMenuMargin,
top: ui.view.paddingTop + _kMenuMargin top: ui.view.paddingTop + _kMenuMargin
), ),
builder: (NavigatorState navigator) { items: <PopupMenuItem>[
return <PopupMenuItem>[
new PopupMenuItem( new PopupMenuItem(
value: _MenuItems.autorefresh, value: _MenuItems.autorefresh,
child: new Row(<Widget>[ child: new Row(<Widget>[
...@@ -24,10 +23,10 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged ...@@ -24,10 +23,10 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
new Checkbox( new Checkbox(
value: autorefresh, value: autorefresh,
onChanged: (bool value) { onChanged: (bool value) {
navigator.setState(() { Navigator.of(context).setState(() {
autorefresh = value; autorefresh = value;
}); });
navigator.pop(_MenuItems.autorefreshCheckbox); Navigator.of(context).pop(_MenuItems.autorefreshCheckbox);
} }
) )
] ]
...@@ -41,11 +40,10 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged ...@@ -41,11 +40,10 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
value: _MenuItems.remove, value: _MenuItems.remove,
child: new Text('Remove stock') child: new Text('Remove stock')
), ),
]; ]
}
)) { )) {
case _MenuItems.autorefresh: case _MenuItems.autorefresh:
navigator.setState(() { Navigator.of(context).setState(() {
autorefresh = !autorefresh; autorefresh = !autorefresh;
}); });
continue autorefreshNotify; continue autorefreshNotify;
...@@ -55,8 +53,9 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged ...@@ -55,8 +53,9 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
break; break;
case _MenuItems.add: case _MenuItems.add:
case _MenuItems.remove: case _MenuItems.remove:
await showDialog(navigator, (NavigatorState navigator) { await showDialog(
return new Dialog( context: context,
child: new Dialog(
title: new Text('Not Implemented'), title: new Text('Not Implemented'),
content: new Text('This feature has not yet been implemented.'), content: new Text('This feature has not yet been implemented.'),
actions: <Widget>[ actions: <Widget>[
...@@ -76,12 +75,12 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged ...@@ -76,12 +75,12 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
new FlatButton( new FlatButton(
child: new Text('OH WELL'), child: new Text('OH WELL'),
onPressed: () { onPressed: () {
navigator.pop(false); Navigator.of(context).pop(false);
} }
), ),
] ]
)
); );
});
break; break;
default: default:
// menu was canceled. // menu was canceled.
......
...@@ -35,29 +35,30 @@ class StockSettingsState extends State<StockSettings> { ...@@ -35,29 +35,30 @@ class StockSettingsState extends State<StockSettings> {
_handleOptimismChanged(false); _handleOptimismChanged(false);
break; break;
case StockMode.pessimistic: case StockMode.pessimistic:
showDialog(config.navigator, (NavigatorState navigator) { showDialog(
return new Dialog( context: context,
child: new Dialog(
title: new Text("Change mode?"), title: new Text("Change mode?"),
content: new Text("Optimistic mode means everything is awesome. Are you sure you can handle that?"), content: new Text("Optimistic mode means everything is awesome. Are you sure you can handle that?"),
onDismiss: () { onDismiss: () {
navigator.pop(false); config.navigator.pop(false);
}, },
actions: <Widget>[ actions: <Widget>[
new FlatButton( new FlatButton(
child: new Text('NO THANKS'), child: new Text('NO THANKS'),
onPressed: () { onPressed: () {
navigator.pop(false); config.navigator.pop(false);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('AGREE'), child: new Text('AGREE'),
onPressed: () { onPressed: () {
navigator.pop(true); config.navigator.pop(true);
} }
), ),
] ]
); )
}).then(_handleOptimismChanged); ).then(_handleOptimismChanged);
break; break;
} }
} }
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
part of stocks; part of stocks;
class StockSymbolViewer extends StatelessComponent { class StockSymbolViewer extends StatelessComponent {
StockSymbolViewer(this.navigator, this.stock); StockSymbolViewer(this.stock);
final NavigatorState navigator;
final Stock stock; final Stock stock;
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -20,7 +19,9 @@ class StockSymbolViewer extends StatelessComponent { ...@@ -20,7 +19,9 @@ class StockSymbolViewer extends StatelessComponent {
toolBar: new ToolBar( toolBar: new ToolBar(
left: new IconButton( left: new IconButton(
icon: 'navigation/arrow_back', icon: 'navigation/arrow_back',
onPressed: navigator.pop onPressed: () {
Navigator.of(context).pop();
}
), ),
center: new Text(stock.name) center: new Text(stock.name)
), ),
......
...@@ -19,10 +19,6 @@ class CardModel { ...@@ -19,10 +19,6 @@ class CardModel {
} }
class CardCollection extends StatefulComponent { class CardCollection extends StatefulComponent {
CardCollection({ this.navigator });
final NavigatorState navigator;
CardCollectionState createState() => new CardCollectionState(); CardCollectionState createState() => new CardCollectionState();
} }
...@@ -113,7 +109,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -113,7 +109,7 @@ class CardCollectionState extends State<CardCollection> {
void _showDrawer() { void _showDrawer() {
showDrawer( showDrawer(
navigator: config.navigator, context: context,
child: new IconTheme( child: new IconTheme(
data: const IconThemeData(color: IconThemeColor.black), data: const IconThemeData(color: IconThemeColor.black),
child: new Block([ child: new Block([
...@@ -169,7 +165,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -169,7 +165,7 @@ class CardCollectionState extends State<CardCollection> {
setState(() { setState(() {
_dismissDirection = newDismissDirection; _dismissDirection = newDismissDirection;
}); });
config.navigator.pop(); Navigator.of(context).pop();
} }
Widget buildDrawerCheckbox(String label, bool value, Function callback) { Widget buildDrawerCheckbox(String label, bool value, Function callback) {
...@@ -374,7 +370,7 @@ void main() { ...@@ -374,7 +370,7 @@ void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: 'Cards', title: 'Cards',
routes: { routes: {
'/': (RouteArguments args) => new CardCollection(navigator: args.navigator), '/': (RouteArguments args) => new CardCollection(),
} }
)); ));
} }
...@@ -6,10 +6,6 @@ import 'package:flutter/material.dart'; ...@@ -6,10 +6,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
class IndexedStackDemo extends StatefulComponent { class IndexedStackDemo extends StatefulComponent {
IndexedStackDemo({ this.navigator });
final NavigatorState navigator;
IndexedStackDemoState createState() => new IndexedStackDemoState(); IndexedStackDemoState createState() => new IndexedStackDemoState();
} }
...@@ -23,7 +19,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> { ...@@ -23,7 +19,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> {
}); });
} }
List <PopupMenuItem> _buildMenu(NavigatorState navigator) { List <PopupMenuItem> _buildMenu() {
TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold); TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold);
String pad = ''; String pad = '';
return new List.generate(_itemCount, (int i) { return new List.generate(_itemCount, (int i) {
...@@ -33,7 +29,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> { ...@@ -33,7 +29,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> {
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
List <PopupMenuItem> items = _buildMenu(config.navigator); List <PopupMenuItem> items = _buildMenu();
IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5); IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5);
return new Scaffold( return new Scaffold(
...@@ -61,7 +57,7 @@ void main() { ...@@ -61,7 +57,7 @@ void main() {
accentColor: Colors.redAccent[200] accentColor: Colors.redAccent[200]
), ),
routes: { routes: {
'/': (RouteArguments args) => new IndexedStackDemo(navigator: args.navigator), '/': (RouteArguments args) => new IndexedStackDemo(),
} }
)); ));
} }
...@@ -15,10 +15,6 @@ class CardModel { ...@@ -15,10 +15,6 @@ class CardModel {
} }
class PageableListApp extends StatefulComponent { class PageableListApp extends StatefulComponent {
PageableListApp({ this.navigator });
final NavigatorState navigator;
PageableListAppState createState() => new PageableListAppState(); PageableListAppState createState() => new PageableListAppState();
} }
...@@ -89,7 +85,7 @@ class PageableListAppState extends State<PageableListApp> { ...@@ -89,7 +85,7 @@ class PageableListAppState extends State<PageableListApp> {
void _showDrawer() { void _showDrawer() {
showDrawer( showDrawer(
navigator: config.navigator, context: context,
child: new Block([ child: new Block([
new DrawerHeader(child: new Text('Options')), new DrawerHeader(child: new Text('Options')),
new DrawerItem( new DrawerItem(
...@@ -161,7 +157,7 @@ void main() { ...@@ -161,7 +157,7 @@ void main() {
accentColor: Colors.redAccent[200] accentColor: Colors.redAccent[200]
), ),
routes: { routes: {
'/': (RouteArguments args) => new PageableListApp(navigator: args.navigator), '/': (RouteArguments args) => new PageableListApp(),
} }
)); ));
} }
...@@ -6,10 +6,6 @@ import 'package:intl/intl.dart'; ...@@ -6,10 +6,6 @@ import 'package:intl/intl.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ScrollbarApp extends StatefulComponent { class ScrollbarApp extends StatefulComponent {
ScrollbarApp({ this.navigator });
final NavigatorState navigator;
ScrollbarAppState createState() => new ScrollbarAppState(); ScrollbarAppState createState() => new ScrollbarAppState();
} }
...@@ -65,7 +61,7 @@ void main() { ...@@ -65,7 +61,7 @@ void main() {
accentColor: Colors.redAccent[200] accentColor: Colors.redAccent[200]
), ),
routes: { routes: {
'/': (RouteArguments args) => new ScrollbarApp(navigator: args.navigator), '/': (RouteArguments args) => new ScrollbarApp(),
} }
)); ));
} }
...@@ -153,15 +153,15 @@ class _DialogRoute extends PerformanceRoute { ...@@ -153,15 +153,15 @@ class _DialogRoute extends PerformanceRoute {
} }
} }
Future showDialog(NavigatorState navigator, DialogBuilder builder) { Future showDialog({ BuildContext context, Widget child }) {
Completer completer = new Completer(); Completer completer = new Completer();
navigator.push(new _DialogRoute( Navigator.of(context).push(new _DialogRoute(
completer: completer, completer: completer,
builder: (RouteArguments args) { builder: (RouteArguments args) {
return new Focus( return new Focus(
key: new GlobalObjectKey(completer), key: new GlobalObjectKey(completer),
autofocus: true, autofocus: true,
child: builder(args.navigator) child: child
); );
} }
)); ));
......
...@@ -169,7 +169,6 @@ class _DrawerRoute extends Route { ...@@ -169,7 +169,6 @@ class _DrawerRoute extends Route {
} }
} }
void showDrawer({ NavigatorState navigator, Widget child, int level: 3 }) { void showDrawer({ BuildContext context, Widget child, int level: 3 }) {
assert(navigator != null); Navigator.of(context).push(new _DrawerRoute(child: child, level: level));
navigator.push(new _DrawerRoute(child: child, level: level));
} }
...@@ -22,14 +22,11 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep; ...@@ -22,14 +22,11 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep;
const double _kMenuHorizontalPadding = 16.0; const double _kMenuHorizontalPadding = 16.0;
const double _kMenuVerticalPadding = 8.0; const double _kMenuVerticalPadding = 8.0;
typedef List<PopupMenuItem> PopupMenuItemsBuilder(NavigatorState navigator);
class PopupMenu extends StatelessComponent { class PopupMenu extends StatelessComponent {
PopupMenu({ PopupMenu({
Key key, Key key,
this.items, this.items,
this.level: 4, this.level: 4,
this.navigator,
this.performance this.performance
}) : super(key: key) { }) : super(key: key) {
assert(items != null); assert(items != null);
...@@ -38,7 +35,6 @@ class PopupMenu extends StatelessComponent { ...@@ -38,7 +35,6 @@ class PopupMenu extends StatelessComponent {
final List<PopupMenuItem> items; final List<PopupMenuItem> items;
final int level; final int level;
final NavigatorState navigator;
final PerformanceView performance; final PerformanceView performance;
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -58,7 +54,7 @@ class PopupMenu extends StatelessComponent { ...@@ -58,7 +54,7 @@ class PopupMenu extends StatelessComponent {
performance: performance, performance: performance,
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(start, end)), opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(start, end)),
child: new InkWell( child: new InkWell(
onTap: () { navigator.pop(items[i].value); }, onTap: () { Navigator.of(context).pop(items[i].value); },
child: items[i] child: items[i]
)) ))
); );
...@@ -114,11 +110,11 @@ class MenuPosition { ...@@ -114,11 +110,11 @@ class MenuPosition {
} }
class _MenuRoute extends PerformanceRoute { 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 Completer completer;
final MenuPosition position; final MenuPosition position;
final PopupMenuItemsBuilder builder; final List<PopupMenuItem> items;
final int level; final int level;
Performance createPerformance() { Performance createPerformance() {
...@@ -144,9 +140,8 @@ class _MenuRoute extends PerformanceRoute { ...@@ -144,9 +140,8 @@ class _MenuRoute extends PerformanceRoute {
key: new GlobalObjectKey(this), key: new GlobalObjectKey(this),
autofocus: true, autofocus: true,
child: new PopupMenu( child: new PopupMenu(
items: builder != null ? builder(navigator) : const <PopupMenuItem>[], items: items,
level: level, level: level,
navigator: navigator,
performance: performance performance: performance
) )
) )
...@@ -159,12 +154,12 @@ class _MenuRoute extends PerformanceRoute { ...@@ -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<PopupMenuItem> items, int level: 4 }) {
Completer completer = new Completer(); Completer completer = new Completer();
navigator.push(new _MenuRoute( Navigator.of(context).push(new _MenuRoute(
completer: completer, completer: completer,
position: position, position: position,
builder: builder, items: items,
level: level level: level
)); ));
return completer.future; return completer.future;
......
...@@ -105,7 +105,7 @@ class _SnackBarRoute extends PerformanceRoute { ...@@ -105,7 +105,7 @@ class _SnackBarRoute extends PerformanceRoute {
Widget build(RouteArguments args) => null; Widget build(RouteArguments args) => null;
} }
void showSnackBar({ NavigatorState navigator, GlobalKey<PlaceholderState> placeholderKey, Widget content, List<SnackBarAction> actions }) { void showSnackBar({ BuildContext context, GlobalKey<PlaceholderState> placeholderKey, Widget content, List<SnackBarAction> actions }) {
Route route = new _SnackBarRoute(); Route route = new _SnackBarRoute();
SnackBar snackBar = new SnackBar( SnackBar snackBar = new SnackBar(
content: content, content: content,
...@@ -113,5 +113,5 @@ void showSnackBar({ NavigatorState navigator, GlobalKey<PlaceholderState> placeh ...@@ -113,5 +113,5 @@ void showSnackBar({ NavigatorState navigator, GlobalKey<PlaceholderState> placeh
performance: route.performance performance: route.performance
); );
placeholderKey.currentState.child = snackBar; placeholderKey.currentState.child = snackBar;
navigator.push(route); Navigator.of(context).push(route);
} }
...@@ -7,7 +7,6 @@ import 'package:flutter/rendering.dart'; ...@@ -7,7 +7,6 @@ import 'package:flutter/rendering.dart';
import 'basic.dart'; import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
import 'navigator.dart';
import 'transitions.dart'; import 'transitions.dart';
// Heroes are the parts of an application's screen-to-screen transitions where a // Heroes are the parts of an application's screen-to-screen transitions where a
...@@ -77,7 +76,6 @@ abstract class HeroHandle { ...@@ -77,7 +76,6 @@ abstract class HeroHandle {
class Hero extends StatefulComponent { class Hero extends StatefulComponent {
Hero({ Hero({
Key key, Key key,
this.navigator,
this.tag, this.tag,
this.child, this.child,
this.turns: 1 this.turns: 1
...@@ -85,7 +83,6 @@ class Hero extends StatefulComponent { ...@@ -85,7 +83,6 @@ class Hero extends StatefulComponent {
assert(tag != null); assert(tag != null);
} }
final NavigatorState navigator;
final Object tag; final Object tag;
final Widget child; final Widget child;
final int turns; final int turns;
......
...@@ -47,6 +47,22 @@ class Navigator extends StatefulComponent { ...@@ -47,6 +47,22 @@ class Navigator extends StatefulComponent {
final RouteGenerator onGenerateRoute; final RouteGenerator onGenerateRoute;
final RouteBuilder onUnknownRoute; 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(); NavigatorState createState() => new NavigatorState();
} }
......
...@@ -21,7 +21,7 @@ void main() { ...@@ -21,7 +21,7 @@ void main() {
); );
tester.pump(); // no effect tester.pump(); // no effect
expect(tester.findText('drawer'), isNull); 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 tester.pump(); // drawer should be starting to animate in
expect(tester.findText('drawer'), isNotNull); expect(tester.findText('drawer'), isNotNull);
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
...@@ -50,7 +50,7 @@ void main() { ...@@ -50,7 +50,7 @@ void main() {
); );
tester.pump(); // no effect tester.pump(); // no effect
expect(tester.findText('drawer'), isNull); 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 tester.pump(); // drawer should be starting to animate in
expect(tester.findText('drawer'), isNotNull); expect(tester.findText('drawer'), isNotNull);
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
......
...@@ -16,7 +16,7 @@ void main() { ...@@ -16,7 +16,7 @@ void main() {
return new GestureDetector( return new GestureDetector(
onTap: () { onTap: () {
showSnackBar( showSnackBar(
navigator: args.navigator, context: args.navigator.context,
placeholderKey: placeholderKey, placeholderKey: placeholderKey,
content: new Text(helloSnackBar) content: new Text(helloSnackBar)
); );
......
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