NavigatorTransaction
To make it easier to avoid pushing twice in one frame, provide a transaction mechanism for the navigator.
This commit is contained in:
@@ -60,7 +60,7 @@ class FeedFragmentState extends State<FeedFragment> {
|
||||
setState(() {
|
||||
_fitnessMode = value;
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
void _showDrawer() {
|
||||
@@ -91,8 +91,7 @@ class FeedFragmentState extends State<FeedFragment> {
|
||||
}
|
||||
|
||||
void _handleShowSettings() {
|
||||
Navigator.of(context)..pop()
|
||||
..pushNamed('/settings');
|
||||
Navigator.popAndPushNamed(context, '/settings');
|
||||
}
|
||||
|
||||
// TODO(jackson): We should be localizing
|
||||
@@ -190,7 +189,7 @@ class FeedFragmentState extends State<FeedFragment> {
|
||||
void _handleActionButtonPressed() {
|
||||
showDialog(context: context, child: new AddItemDialog()).then((routeName) {
|
||||
if (routeName != null)
|
||||
Navigator.of(context).pushNamed(routeName);
|
||||
Navigator.pushNamed(context, routeName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -249,13 +248,13 @@ class AddItemDialogState extends State<AddItemDialog> {
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('ADD'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_addItemRoute);
|
||||
Navigator.pop(context, _addItemRoute);
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@@ -55,14 +55,15 @@ class MealFragmentState extends State<MealFragment> {
|
||||
|
||||
void _handleSave() {
|
||||
config.onCreated(new Meal(when: new DateTime.now(), description: _description));
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/close",
|
||||
onPressed: Navigator.of(context).pop),
|
||||
onPressed: () => Navigator.pop(context)
|
||||
),
|
||||
center: new Text('New Meal'),
|
||||
right: <Widget>[
|
||||
// TODO(abarth): Should this be a FlatButton?
|
||||
|
||||
@@ -77,14 +77,15 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
|
||||
));
|
||||
}
|
||||
config.onCreated(new Measurement(when: _when, weight: parsedWeight));
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/close",
|
||||
onPressed: Navigator.of(context).pop),
|
||||
onPressed: () => Navigator.pop(context)
|
||||
),
|
||||
center: new Text('New Measurement'),
|
||||
right: <Widget>[
|
||||
// TODO(abarth): Should this be a FlatButton?
|
||||
|
||||
@@ -28,7 +28,7 @@ class SettingsFragmentState extends State<SettingsFragment> {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: "navigation/arrow_back",
|
||||
onPressed: () => Navigator.of(context).pop()
|
||||
onPressed: () => Navigator.pop(context)
|
||||
),
|
||||
center: new Text('Settings')
|
||||
);
|
||||
@@ -47,7 +47,7 @@ class SettingsFragmentState extends State<SettingsFragment> {
|
||||
void _handleGoalWeightChanged(String goalWeight) {
|
||||
// TODO(jackson): Looking for null characters to detect enter key is a hack
|
||||
if (goalWeight.endsWith("\u{0}")) {
|
||||
Navigator.of(context).pop(double.parse(goalWeight.replaceAll("\u{0}", "")));
|
||||
Navigator.pop(context, double.parse(goalWeight.replaceAll("\u{0}", "")));
|
||||
} else {
|
||||
setState(() {
|
||||
try {
|
||||
@@ -74,13 +74,13 @@ class SettingsFragmentState extends State<SettingsFragment> {
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('SAVE'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_goalWeight);
|
||||
Navigator.pop(context, _goalWeight);
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@@ -21,7 +21,7 @@ class GalleryPage extends StatelessComponent {
|
||||
for (WidgetDemo demo in demos) {
|
||||
items.add(new DrawerItem(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(demo.routeName);
|
||||
Navigator.pushNamed(context, demo.routeName);
|
||||
},
|
||||
child: new Text(demo.title)
|
||||
));
|
||||
|
||||
@@ -41,7 +41,7 @@ class StockHomeState extends State<StockHome> {
|
||||
}
|
||||
|
||||
void _handleSearchEnd() {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
void _handleSearchQueryChanged(String query) {
|
||||
@@ -92,13 +92,13 @@ class StockHomeState extends State<StockHome> {
|
||||
new FlatButton(
|
||||
child: new Text('USE IT'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('OH WELL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
),
|
||||
]
|
||||
@@ -142,8 +142,7 @@ class StockHomeState extends State<StockHome> {
|
||||
}
|
||||
|
||||
void _handleShowSettings() {
|
||||
Navigator.of(context)..pop()
|
||||
..pushNamed('/settings');
|
||||
Navigator.popAndPushNamed(context, '/settings');
|
||||
}
|
||||
|
||||
Widget buildToolBar() {
|
||||
@@ -207,7 +206,7 @@ class StockHomeState extends State<StockHome> {
|
||||
onOpen: (Stock stock, Key arrowKey) {
|
||||
Set<Key> mostValuableKeys = new Set<Key>();
|
||||
mostValuableKeys.add(arrowKey);
|
||||
Navigator.of(context).pushNamed('/stock/${stock.symbol}', mostValuableKeys: mostValuableKeys);
|
||||
Navigator.pushNamed(context, '/stock/${stock.symbol}', mostValuableKeys: mostValuableKeys);
|
||||
},
|
||||
onShow: (Stock stock, Key arrowKey) {
|
||||
scaffoldKey.currentState.showBottomSheet((BuildContext context) => new StockSymbolBottomSheet(stock: stock));
|
||||
|
||||
@@ -23,10 +23,9 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
|
||||
new Checkbox(
|
||||
value: autorefresh,
|
||||
onChanged: (bool value) {
|
||||
Navigator.of(context).setState(() {
|
||||
autorefresh = value;
|
||||
});
|
||||
Navigator.of(context).pop(_MenuItems.autorefreshCheckbox);
|
||||
// TODO(ianh): https://github.com/flutter/flutter/issues/187
|
||||
autorefresh = value;
|
||||
Navigator.pop(context, _MenuItems.autorefreshCheckbox);
|
||||
}
|
||||
)
|
||||
]
|
||||
@@ -43,9 +42,8 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
|
||||
]
|
||||
)) {
|
||||
case _MenuItems.autorefresh:
|
||||
Navigator.of(context).setState(() {
|
||||
autorefresh = !autorefresh;
|
||||
});
|
||||
// TODO(ianh): https://github.com/flutter/flutter/issues/187
|
||||
autorefresh = !autorefresh;
|
||||
continue autorefreshNotify;
|
||||
autorefreshNotify:
|
||||
case _MenuItems.autorefreshCheckbox:
|
||||
@@ -75,7 +73,7 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
|
||||
new FlatButton(
|
||||
child: new Text('OH WELL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@@ -44,13 +44,13 @@ class StockSettingsState extends State<StockSettings> {
|
||||
new FlatButton(
|
||||
child: new Text('NO THANKS'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('AGREE'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
),
|
||||
]
|
||||
@@ -72,7 +72,7 @@ class StockSettingsState extends State<StockSettings> {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
icon: 'navigation/arrow_back',
|
||||
onPressed: () => Navigator.of(context).pop()
|
||||
onPressed: () => Navigator.pop(context)
|
||||
),
|
||||
center: new Text('Settings')
|
||||
);
|
||||
|
||||
@@ -58,7 +58,7 @@ class StockSymbolPage extends StatelessComponent {
|
||||
left: new IconButton(
|
||||
icon: 'navigation/arrow_back',
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
),
|
||||
center: new Text(stock.name)
|
||||
|
||||
@@ -15,11 +15,11 @@ class Home extends StatelessComponent {
|
||||
),
|
||||
new RaisedButton(
|
||||
child: new Text('GO SHOPPING'),
|
||||
onPressed: () => Navigator.of(context).pushNamed('/shopping')
|
||||
onPressed: () => Navigator.pushNamed(context, '/shopping')
|
||||
),
|
||||
new RaisedButton(
|
||||
child: new Text('START ADVENTURE'),
|
||||
onPressed: () => Navigator.of(context).pushNamed('/adventure')
|
||||
onPressed: () => Navigator.pushNamed(context, '/adventure')
|
||||
)
|
||||
],
|
||||
padding: const EdgeDims.all(30.0)
|
||||
@@ -41,11 +41,11 @@ class Shopping extends StatelessComponent {
|
||||
),
|
||||
new RaisedButton(
|
||||
child: new Text('RETURN HOME'),
|
||||
onPressed: () => Navigator.of(context).pop()
|
||||
onPressed: () => Navigator.pop(context)
|
||||
),
|
||||
new RaisedButton(
|
||||
child: new Text('GO TO DUNGEON'),
|
||||
onPressed: () => Navigator.of(context).pushNamed('/adventure')
|
||||
onPressed: () => Navigator.pushNamed(context, '/adventure')
|
||||
)
|
||||
],
|
||||
padding: const EdgeDims.all(30.0)
|
||||
@@ -67,7 +67,7 @@ class Adventure extends StatelessComponent {
|
||||
),
|
||||
new RaisedButton(
|
||||
child: new Text('RUN!!!'),
|
||||
onPressed: () => Navigator.of(context).pop()
|
||||
onPressed: () => Navigator.pop(context)
|
||||
)
|
||||
],
|
||||
padding: const EdgeDims.all(30.0)
|
||||
|
||||
Reference in New Issue
Block a user