Commit f9ea1ce8 authored by Hixie's avatar Hixie

NavigatorTransaction

To make it easier to avoid pushing twice in one frame, provide a
transaction mechanism for the navigator.
parent 97cca4d4
...@@ -60,7 +60,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -60,7 +60,7 @@ class FeedFragmentState extends State<FeedFragment> {
setState(() { setState(() {
_fitnessMode = value; _fitnessMode = value;
}); });
Navigator.of(context).pop(); Navigator.pop(context);
} }
void _showDrawer() { void _showDrawer() {
...@@ -91,8 +91,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -91,8 +91,7 @@ class FeedFragmentState extends State<FeedFragment> {
} }
void _handleShowSettings() { void _handleShowSettings() {
Navigator.of(context)..pop() Navigator.popAndPushNamed(context, '/settings');
..pushNamed('/settings');
} }
// TODO(jackson): We should be localizing // TODO(jackson): We should be localizing
...@@ -190,7 +189,7 @@ class FeedFragmentState extends State<FeedFragment> { ...@@ -190,7 +189,7 @@ class FeedFragmentState extends State<FeedFragment> {
void _handleActionButtonPressed() { void _handleActionButtonPressed() {
showDialog(context: context, child: new AddItemDialog()).then((routeName) { showDialog(context: context, child: new AddItemDialog()).then((routeName) {
if (routeName != null) if (routeName != null)
Navigator.of(context).pushNamed(routeName); Navigator.pushNamed(context, routeName);
}); });
} }
...@@ -249,13 +248,13 @@ class AddItemDialogState extends State<AddItemDialog> { ...@@ -249,13 +248,13 @@ class AddItemDialogState extends State<AddItemDialog> {
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.pop(context);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('ADD'), child: new Text('ADD'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(_addItemRoute); Navigator.pop(context, _addItemRoute);
} }
), ),
] ]
......
...@@ -55,14 +55,15 @@ class MealFragmentState extends State<MealFragment> { ...@@ -55,14 +55,15 @@ class MealFragmentState extends State<MealFragment> {
void _handleSave() { void _handleSave() {
config.onCreated(new Meal(when: new DateTime.now(), description: _description)); config.onCreated(new Meal(when: new DateTime.now(), description: _description));
Navigator.of(context).pop(); Navigator.pop(context);
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/close", icon: "navigation/close",
onPressed: Navigator.of(context).pop), onPressed: () => Navigator.pop(context)
),
center: new Text('New Meal'), center: new Text('New Meal'),
right: <Widget>[ right: <Widget>[
// TODO(abarth): Should this be a FlatButton? // TODO(abarth): Should this be a FlatButton?
......
...@@ -77,14 +77,15 @@ class MeasurementFragmentState extends State<MeasurementFragment> { ...@@ -77,14 +77,15 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
)); ));
} }
config.onCreated(new Measurement(when: _when, weight: parsedWeight)); config.onCreated(new Measurement(when: _when, weight: parsedWeight));
Navigator.of(context).pop(); Navigator.pop(context);
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/close", icon: "navigation/close",
onPressed: Navigator.of(context).pop), onPressed: () => Navigator.pop(context)
),
center: new Text('New Measurement'), center: new Text('New Measurement'),
right: <Widget>[ right: <Widget>[
// TODO(abarth): Should this be a FlatButton? // TODO(abarth): Should this be a FlatButton?
......
...@@ -28,7 +28,7 @@ class SettingsFragmentState extends State<SettingsFragment> { ...@@ -28,7 +28,7 @@ class SettingsFragmentState extends State<SettingsFragment> {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: "navigation/arrow_back", icon: "navigation/arrow_back",
onPressed: () => Navigator.of(context).pop() onPressed: () => Navigator.pop(context)
), ),
center: new Text('Settings') center: new Text('Settings')
); );
...@@ -47,7 +47,7 @@ class SettingsFragmentState extends State<SettingsFragment> { ...@@ -47,7 +47,7 @@ class SettingsFragmentState extends State<SettingsFragment> {
void _handleGoalWeightChanged(String goalWeight) { void _handleGoalWeightChanged(String goalWeight) {
// TODO(jackson): Looking for null characters to detect enter key is a hack // TODO(jackson): Looking for null characters to detect enter key is a hack
if (goalWeight.endsWith("\u{0}")) { 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 { } else {
setState(() { setState(() {
try { try {
...@@ -74,13 +74,13 @@ class SettingsFragmentState extends State<SettingsFragment> { ...@@ -74,13 +74,13 @@ class SettingsFragmentState extends State<SettingsFragment> {
new FlatButton( new FlatButton(
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.pop(context);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('SAVE'), child: new Text('SAVE'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(_goalWeight); Navigator.pop(context, _goalWeight);
} }
), ),
] ]
......
...@@ -21,7 +21,7 @@ class GalleryPage extends StatelessComponent { ...@@ -21,7 +21,7 @@ class GalleryPage extends StatelessComponent {
for (WidgetDemo demo in demos) { for (WidgetDemo demo in demos) {
items.add(new DrawerItem( items.add(new DrawerItem(
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed(demo.routeName); Navigator.pushNamed(context, demo.routeName);
}, },
child: new Text(demo.title) child: new Text(demo.title)
)); ));
......
...@@ -41,7 +41,7 @@ class StockHomeState extends State<StockHome> { ...@@ -41,7 +41,7 @@ class StockHomeState extends State<StockHome> {
} }
void _handleSearchEnd() { void _handleSearchEnd() {
Navigator.of(context).pop(); Navigator.pop(context);
} }
void _handleSearchQueryChanged(String query) { void _handleSearchQueryChanged(String query) {
...@@ -92,13 +92,13 @@ class StockHomeState extends State<StockHome> { ...@@ -92,13 +92,13 @@ class StockHomeState extends State<StockHome> {
new FlatButton( new FlatButton(
child: new Text('USE IT'), child: new Text('USE IT'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(false); Navigator.pop(context, false);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('OH WELL'), child: new Text('OH WELL'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(false); Navigator.pop(context, false);
} }
), ),
] ]
...@@ -142,8 +142,7 @@ class StockHomeState extends State<StockHome> { ...@@ -142,8 +142,7 @@ class StockHomeState extends State<StockHome> {
} }
void _handleShowSettings() { void _handleShowSettings() {
Navigator.of(context)..pop() Navigator.popAndPushNamed(context, '/settings');
..pushNamed('/settings');
} }
Widget buildToolBar() { Widget buildToolBar() {
...@@ -207,7 +206,7 @@ class StockHomeState extends State<StockHome> { ...@@ -207,7 +206,7 @@ class StockHomeState extends State<StockHome> {
onOpen: (Stock stock, Key arrowKey) { onOpen: (Stock stock, Key arrowKey) {
Set<Key> mostValuableKeys = new Set<Key>(); Set<Key> mostValuableKeys = new Set<Key>();
mostValuableKeys.add(arrowKey); 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) { onShow: (Stock stock, Key arrowKey) {
scaffoldKey.currentState.showBottomSheet((BuildContext context) => new StockSymbolBottomSheet(stock: stock)); scaffoldKey.currentState.showBottomSheet((BuildContext context) => new StockSymbolBottomSheet(stock: stock));
......
...@@ -23,10 +23,9 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool> ...@@ -23,10 +23,9 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
new Checkbox( new Checkbox(
value: autorefresh, value: autorefresh,
onChanged: (bool value) { onChanged: (bool value) {
Navigator.of(context).setState(() { // TODO(ianh): https://github.com/flutter/flutter/issues/187
autorefresh = value; autorefresh = value;
}); Navigator.pop(context, _MenuItems.autorefreshCheckbox);
Navigator.of(context).pop(_MenuItems.autorefreshCheckbox);
} }
) )
] ]
...@@ -43,9 +42,8 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool> ...@@ -43,9 +42,8 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
] ]
)) { )) {
case _MenuItems.autorefresh: case _MenuItems.autorefresh:
Navigator.of(context).setState(() { // TODO(ianh): https://github.com/flutter/flutter/issues/187
autorefresh = !autorefresh; autorefresh = !autorefresh;
});
continue autorefreshNotify; continue autorefreshNotify;
autorefreshNotify: autorefreshNotify:
case _MenuItems.autorefreshCheckbox: case _MenuItems.autorefreshCheckbox:
...@@ -75,7 +73,7 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool> ...@@ -75,7 +73,7 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
new FlatButton( new FlatButton(
child: new Text('OH WELL'), child: new Text('OH WELL'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(false); Navigator.pop(context, false);
} }
), ),
] ]
......
...@@ -44,13 +44,13 @@ class StockSettingsState extends State<StockSettings> { ...@@ -44,13 +44,13 @@ class StockSettingsState extends State<StockSettings> {
new FlatButton( new FlatButton(
child: new Text('NO THANKS'), child: new Text('NO THANKS'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(false); Navigator.pop(context, false);
} }
), ),
new FlatButton( new FlatButton(
child: new Text('AGREE'), child: new Text('AGREE'),
onPressed: () { onPressed: () {
Navigator.of(context).pop(true); Navigator.pop(context, true);
} }
), ),
] ]
...@@ -72,7 +72,7 @@ class StockSettingsState extends State<StockSettings> { ...@@ -72,7 +72,7 @@ class StockSettingsState extends State<StockSettings> {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
icon: 'navigation/arrow_back', icon: 'navigation/arrow_back',
onPressed: () => Navigator.of(context).pop() onPressed: () => Navigator.pop(context)
), ),
center: new Text('Settings') center: new Text('Settings')
); );
......
...@@ -58,7 +58,7 @@ class StockSymbolPage extends StatelessComponent { ...@@ -58,7 +58,7 @@ class StockSymbolPage extends StatelessComponent {
left: new IconButton( left: new IconButton(
icon: 'navigation/arrow_back', icon: 'navigation/arrow_back',
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.pop(context);
} }
), ),
center: new Text(stock.name) center: new Text(stock.name)
......
...@@ -15,11 +15,11 @@ class Home extends StatelessComponent { ...@@ -15,11 +15,11 @@ class Home extends StatelessComponent {
), ),
new RaisedButton( new RaisedButton(
child: new Text('GO SHOPPING'), child: new Text('GO SHOPPING'),
onPressed: () => Navigator.of(context).pushNamed('/shopping') onPressed: () => Navigator.pushNamed(context, '/shopping')
), ),
new RaisedButton( new RaisedButton(
child: new Text('START ADVENTURE'), child: new Text('START ADVENTURE'),
onPressed: () => Navigator.of(context).pushNamed('/adventure') onPressed: () => Navigator.pushNamed(context, '/adventure')
) )
], ],
padding: const EdgeDims.all(30.0) padding: const EdgeDims.all(30.0)
...@@ -41,11 +41,11 @@ class Shopping extends StatelessComponent { ...@@ -41,11 +41,11 @@ class Shopping extends StatelessComponent {
), ),
new RaisedButton( new RaisedButton(
child: new Text('RETURN HOME'), child: new Text('RETURN HOME'),
onPressed: () => Navigator.of(context).pop() onPressed: () => Navigator.pop(context)
), ),
new RaisedButton( new RaisedButton(
child: new Text('GO TO DUNGEON'), child: new Text('GO TO DUNGEON'),
onPressed: () => Navigator.of(context).pushNamed('/adventure') onPressed: () => Navigator.pushNamed(context, '/adventure')
) )
], ],
padding: const EdgeDims.all(30.0) padding: const EdgeDims.all(30.0)
...@@ -67,7 +67,7 @@ class Adventure extends StatelessComponent { ...@@ -67,7 +67,7 @@ class Adventure extends StatelessComponent {
), ),
new RaisedButton( new RaisedButton(
child: new Text('RUN!!!'), child: new Text('RUN!!!'),
onPressed: () => Navigator.of(context).pop() onPressed: () => Navigator.pop(context)
) )
], ],
padding: const EdgeDims.all(30.0) padding: const EdgeDims.all(30.0)
......
...@@ -119,7 +119,7 @@ class _ModalBottomSheetState extends State<_ModalBottomSheet> { ...@@ -119,7 +119,7 @@ class _ModalBottomSheetState extends State<_ModalBottomSheet> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new GestureDetector( return new GestureDetector(
onTap: () { Navigator.of(context).pop(); }, onTap: () => Navigator.pop(context),
child: new BuilderTransition( child: new BuilderTransition(
performance: config.route.performance, performance: config.route.performance,
variables: <AnimatedValue<double>>[_layout.childTop], variables: <AnimatedValue<double>>[_layout.childTop],
...@@ -130,7 +130,7 @@ class _ModalBottomSheetState extends State<_ModalBottomSheet> { ...@@ -130,7 +130,7 @@ class _ModalBottomSheetState extends State<_ModalBottomSheet> {
token: _layout.childTop.value, token: _layout.childTop.value,
child: new BottomSheet( child: new BottomSheet(
performance: config.route.performance, performance: config.route.performance,
onClosing: () { Navigator.of(context).pop(); }, onClosing: () => Navigator.pop(context),
childHeight: _layout.childTop.end, childHeight: _layout.childTop.end,
builder: config.route.builder builder: config.route.builder
) )
...@@ -167,7 +167,7 @@ Future showModalBottomSheet({ BuildContext context, WidgetBuilder builder }) { ...@@ -167,7 +167,7 @@ Future showModalBottomSheet({ BuildContext context, WidgetBuilder builder }) {
assert(context != null); assert(context != null);
assert(builder != null); assert(builder != null);
final Completer completer = new Completer(); final Completer completer = new Completer();
Navigator.of(context).push(new _ModalBottomSheetRoute( Navigator.push(context, new _ModalBottomSheetRoute(
completer: completer, completer: completer,
builder: builder builder: builder
)); ));
......
...@@ -40,11 +40,11 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -40,11 +40,11 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
} }
void _handleCancel() { void _handleCancel() {
Navigator.of(context).pop(); Navigator.pop(context);
} }
void _handleOk() { void _handleOk() {
Navigator.of(context).pop(_selectedDate); Navigator.pop(context, _selectedDate);
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -140,6 +140,6 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -140,6 +140,6 @@ class _DialogRoute<T> extends PopupRoute<T> {
Future showDialog({ BuildContext context, Widget child }) { Future showDialog({ BuildContext context, Widget child }) {
Completer completer = new Completer(); Completer completer = new Completer();
Navigator.of(context).push(new _DialogRoute(completer: completer, child: child)); Navigator.push(context, new _DialogRoute(completer: completer, child: child));
return completer.future; return completer.future;
} }
...@@ -71,7 +71,7 @@ class _DrawerRoute extends OverlayRoute { ...@@ -71,7 +71,7 @@ class _DrawerRoute extends OverlayRoute {
_state = _DrawerState.closed; _state = _DrawerState.closed;
switch (previousState) { switch (previousState) {
case _DrawerState.showing: case _DrawerState.showing:
Navigator.of(context).pop(); Navigator.pop(context);
break; break;
case _DrawerState.popped: case _DrawerState.popped:
finished(); finished();
...@@ -220,5 +220,5 @@ class _DrawerControllerState extends State<_DrawerController> { ...@@ -220,5 +220,5 @@ class _DrawerControllerState extends State<_DrawerController> {
} }
void showDrawer({ BuildContext context, Widget child, int elevation: 16 }) { void showDrawer({ BuildContext context, Widget child, int elevation: 16 }) {
Navigator.of(context).push(new _DrawerRoute(child: child, elevation: elevation)); Navigator.push(context, new _DrawerRoute(child: child, elevation: elevation));
} }
...@@ -93,9 +93,7 @@ class _DropDownMenu<T> extends StatusTransitionComponent { ...@@ -93,9 +93,7 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
padding: _kMenuHorizontalPadding, padding: _kMenuHorizontalPadding,
child: route.items[itemIndex] child: route.items[itemIndex]
), ),
onTap: () { onTap: () => Navigator.pop(context, route.items[itemIndex].value)
Navigator.of(context).pop(route.items[itemIndex].value);
}
) )
)); ));
} }
...@@ -117,7 +115,7 @@ class _DropDownMenu<T> extends StatusTransitionComponent { ...@@ -117,7 +115,7 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
reverseCurve: const Interval(0.0, 0.001) reverseCurve: const Interval(0.0, 0.001)
); );
final RenderBox renderBox = Navigator.of(context).context.findRenderObject(); final RenderBox renderBox = route.navigator.context.findRenderObject();
final Size navigatorSize = renderBox.size; final Size navigatorSize = renderBox.size;
final RelativeRect menuRect = new RelativeRect.fromSize(route.rect, navigatorSize); final RelativeRect menuRect = new RelativeRect.fromSize(route.rect, navigatorSize);
...@@ -216,7 +214,7 @@ class DropDownButton<T> extends StatelessComponent { ...@@ -216,7 +214,7 @@ class DropDownButton<T> extends StatelessComponent {
final RenderBox renderBox = indexedStackKey.currentContext.findRenderObject(); final RenderBox renderBox = indexedStackKey.currentContext.findRenderObject();
final Rect rect = renderBox.localToGlobal(Point.origin) & renderBox.size; final Rect rect = renderBox.localToGlobal(Point.origin) & renderBox.size;
final Completer completer = new Completer<T>(); final Completer completer = new Completer<T>();
Navigator.of(context).push(new _DropDownRoute<T>( Navigator.push(context, new _DropDownRoute<T>(
completer: completer, completer: completer,
items: items, items: items,
selectedIndex: selectedIndex, selectedIndex: selectedIndex,
......
...@@ -81,8 +81,10 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver { ...@@ -81,8 +81,10 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
assert(mounted); assert(mounted);
NavigatorState navigator = _navigator.currentState; NavigatorState navigator = _navigator.currentState;
assert(navigator != null); assert(navigator != null);
if (!navigator.pop()) navigator.openTransaction((NavigatorTransaction transaction) {
activity.finishCurrentActivity(); if (!transaction.pop())
activity.finishCurrentActivity();
});
return true; return true;
} }
......
...@@ -38,7 +38,7 @@ class _PopupMenu<T> extends StatelessComponent { ...@@ -38,7 +38,7 @@ class _PopupMenu<T> extends StatelessComponent {
performance: route.performance, performance: route.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.of(context).pop(route.items[i].value); }, onTap: () => Navigator.pop(context, route.items[i].value),
child: route.items[i] child: route.items[i]
)) ))
); );
...@@ -114,7 +114,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> { ...@@ -114,7 +114,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
Future showMenu({ BuildContext context, ModalPosition position, List<PopupMenuItem> items, int elevation: 8 }) { Future showMenu({ BuildContext context, ModalPosition position, List<PopupMenuItem> items, int elevation: 8 }) {
Completer completer = new Completer(); Completer completer = new Completer();
Navigator.of(context).push(new _PopupMenuRoute( Navigator.push(context, new _PopupMenuRoute(
completer: completer, completer: completer,
position: position, position: position,
items: items, items: items,
......
...@@ -36,11 +36,11 @@ class _TimePickerDialogState extends State<_TimePickerDialog> { ...@@ -36,11 +36,11 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
} }
void _handleCancel() { void _handleCancel() {
Navigator.of(context).pop(); Navigator.pop(context);
} }
void _handleOk() { void _handleOk() {
Navigator.of(context).pop(_selectedTime); Navigator.pop(context, _selectedTime);
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -11,7 +11,6 @@ import 'package:flutter/services.dart'; ...@@ -11,7 +11,6 @@ import 'package:flutter/services.dart';
import 'basic.dart'; import 'basic.dart';
import 'binding.dart'; import 'binding.dart';
import 'framework.dart'; import 'framework.dart';
import 'navigator.dart';
import 'overlay.dart'; import 'overlay.dart';
typedef bool DragTargetWillAccept<T>(T data); typedef bool DragTargetWillAccept<T>(T data);
...@@ -165,7 +164,7 @@ class _DraggableState<T> extends State<DraggableBase<T>> implements GestureArena ...@@ -165,7 +164,7 @@ class _DraggableState<T> extends State<DraggableBase<T>> implements GestureArena
new _DragAvatar<T>( new _DragAvatar<T>(
pointer: pointer, pointer: pointer,
router: router, router: router,
overlay: Navigator.of(context).overlay, overlay: Overlay.of(context),
data: config.data, data: config.data,
initialPosition: position, initialPosition: position,
dragStartPoint: dragStartPoint, dragStartPoint: dragStartPoint,
......
...@@ -23,7 +23,7 @@ class ModalBarrier extends StatelessComponent { ...@@ -23,7 +23,7 @@ class ModalBarrier extends StatelessComponent {
return new Listener( return new Listener(
onPointerDown: (_) { onPointerDown: (_) {
if (dismissable) if (dismissable)
Navigator.of(context).pop(); Navigator.pop(context);
}, },
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
child: new ConstrainedBox( child: new ConstrainedBox(
......
...@@ -44,6 +44,8 @@ class Overlay extends StatefulComponent { ...@@ -44,6 +44,8 @@ class Overlay extends StatefulComponent {
final List<OverlayEntry> initialEntries; final List<OverlayEntry> initialEntries;
static OverlayState of(BuildContext context) => context.ancestorStateOfType(OverlayState);
OverlayState createState() => new OverlayState(); OverlayState createState() => new OverlayState();
} }
......
...@@ -23,11 +23,11 @@ abstract class OverlayRoute<T> extends Route<T> { ...@@ -23,11 +23,11 @@ abstract class OverlayRoute<T> extends Route<T> {
List<OverlayEntry> get overlayEntries => _overlayEntries; List<OverlayEntry> get overlayEntries => _overlayEntries;
final List<OverlayEntry> _overlayEntries = <OverlayEntry>[]; final List<OverlayEntry> _overlayEntries = <OverlayEntry>[];
void install(OverlayState overlay, OverlayEntry insertionPoint) { void install(OverlayEntry insertionPoint) {
assert(_overlayEntries.isEmpty); assert(_overlayEntries.isEmpty);
for (WidgetBuilder builder in builders) for (WidgetBuilder builder in builders)
_overlayEntries.add(new OverlayEntry(builder: builder)); _overlayEntries.add(new OverlayEntry(builder: builder));
overlay?.insertAll(_overlayEntries, above: insertionPoint); navigator.overlay?.insertAll(_overlayEntries, above: insertionPoint);
} }
// Subclasses shouldn't call this if they want to delay the finished() call. // Subclasses shouldn't call this if they want to delay the finished() call.
...@@ -108,9 +108,9 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -108,9 +108,9 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
} }
} }
void install(OverlayState overlay, OverlayEntry insertionPoint) { void install(OverlayEntry insertionPoint) {
_performance = createPerformance(); _performance = createPerformance();
super.install(overlay, insertionPoint); super.install(insertionPoint);
} }
void didPush() { void didPush() {
......
...@@ -29,7 +29,7 @@ void main() { ...@@ -29,7 +29,7 @@ void main() {
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
expect(tester.findText('drawer'), isNotNull); expect(tester.findText('drawer'), isNotNull);
Navigator.of(context).pop(); Navigator.pop(context);
tester.pump(); // drawer should be starting to animate away tester.pump(); // drawer should be starting to animate away
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
......
...@@ -15,13 +15,13 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{ ...@@ -15,13 +15,13 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
new Container(height: 100.0, width: 100.0), new Container(height: 100.0, width: 100.0),
new Card(child: new Hero(tag: 'a', child: new Container(height: 100.0, width: 100.0, key: firstKey))), new Card(child: new Hero(tag: 'a', child: new Container(height: 100.0, width: 100.0, key: firstKey))),
new Container(height: 100.0, width: 100.0), new Container(height: 100.0, width: 100.0),
new FlatButton(child: new Text('button'), onPressed: () => Navigator.of(args.context).pushNamed('/two')), new FlatButton(child: new Text('button'), onPressed: () => Navigator.pushNamed(args.context, '/two')),
]), ]),
'/two': (RouteArguments args) => new Block([ '/two': (RouteArguments args) => new Block([
new Container(height: 150.0, width: 150.0), new Container(height: 150.0, width: 150.0),
new Card(child: new Hero(tag: 'a', child: new Container(height: 150.0, width: 150.0, key: secondKey))), new Card(child: new Hero(tag: 'a', child: new Container(height: 150.0, width: 150.0, key: secondKey))),
new Container(height: 150.0, width: 150.0), new Container(height: 150.0, width: 150.0),
new FlatButton(child: new Text('button'), onPressed: () => Navigator.of(args.context).pop()), new FlatButton(child: new Text('button'), onPressed: () => Navigator.pop(args.context)),
]), ]),
}; };
......
...@@ -10,7 +10,7 @@ class FirstComponent extends StatelessComponent { ...@@ -10,7 +10,7 @@ class FirstComponent extends StatelessComponent {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new GestureDetector( return new GestureDetector(
onTap: () { onTap: () {
Navigator.of(context).pushNamed('/second'); Navigator.pushNamed(context, '/second');
}, },
child: new Container( child: new Container(
decoration: new BoxDecoration( decoration: new BoxDecoration(
...@@ -29,7 +29,7 @@ class SecondComponent extends StatefulComponent { ...@@ -29,7 +29,7 @@ class SecondComponent extends StatefulComponent {
class SecondComponentState extends State<SecondComponent> { class SecondComponentState extends State<SecondComponent> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new GestureDetector( return new GestureDetector(
onTap: Navigator.of(context).pop, onTap: () => Navigator.pop(context),
child: new Container( child: new Container(
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: new Color(0xFFFF00FF) backgroundColor: new Color(0xFFFF00FF)
......
...@@ -16,10 +16,11 @@ class TestOverlayRoute extends OverlayRoute { ...@@ -16,10 +16,11 @@ class TestOverlayRoute extends OverlayRoute {
void main() { void main() {
test('Check onstage/offstage handling around transitions', () { test('Check onstage/offstage handling around transitions', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
GlobalKey containerKey = new GlobalKey(); GlobalKey containerKey1 = new GlobalKey();
GlobalKey containerKey2 = new GlobalKey();
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/': (_) => new Container(key: containerKey, child: new Text('Home')), '/': (_) => new Container(key: containerKey1, child: new Text('Home')),
'/settings': (_) => new Container(child: new Text('Settings')), '/settings': (_) => new Container(key: containerKey2, child: new Text('Settings')),
}; };
tester.pumpWidget(new MaterialApp(routes: routes)); tester.pumpWidget(new MaterialApp(routes: routes));
...@@ -28,9 +29,7 @@ void main() { ...@@ -28,9 +29,7 @@ void main() {
expect(tester.findText('Settings'), isNull); expect(tester.findText('Settings'), isNull);
expect(tester.findText('Overlay'), isNull); expect(tester.findText('Overlay'), isNull);
NavigatorState navigator = Navigator.of(containerKey.currentContext); Navigator.pushNamed(containerKey1.currentContext, '/settings');
navigator.pushNamed('/settings');
tester.pump(); tester.pump();
...@@ -50,7 +49,7 @@ void main() { ...@@ -50,7 +49,7 @@ void main() {
expect(tester.findText('Settings'), isOnStage); expect(tester.findText('Settings'), isOnStage);
expect(tester.findText('Overlay'), isNull); expect(tester.findText('Overlay'), isNull);
navigator.push(new TestOverlayRoute()); Navigator.push(containerKey2.currentContext, new TestOverlayRoute());
tester.pump(); tester.pump();
...@@ -64,7 +63,7 @@ void main() { ...@@ -64,7 +63,7 @@ void main() {
expect(tester.findText('Settings'), isOnStage); expect(tester.findText('Settings'), isOnStage);
expect(tester.findText('Overlay'), isOnStage); expect(tester.findText('Overlay'), isOnStage);
navigator.pop(); Navigator.pop(containerKey2.currentContext);
tester.pump(); tester.pump();
expect(tester.findText('Home'), isNull); expect(tester.findText('Home'), isNull);
...@@ -77,7 +76,7 @@ void main() { ...@@ -77,7 +76,7 @@ void main() {
expect(tester.findText('Settings'), isOnStage); expect(tester.findText('Settings'), isOnStage);
expect(tester.findText('Overlay'), isNull); expect(tester.findText('Overlay'), isNull);
navigator.pop(); Navigator.pop(containerKey2.currentContext);
tester.pump(); tester.pump();
expect(tester.findText('Home'), isOnStage); expect(tester.findText('Home'), isOnStage);
......
...@@ -74,7 +74,9 @@ void main() { ...@@ -74,7 +74,9 @@ void main() {
expect(tester.findText('16'), isNull); expect(tester.findText('16'), isNull);
expect(tester.findText('100'), isNull); expect(tester.findText('100'), isNull);
navigatorKey.currentState.pushNamed('/second'); navigatorKey.currentState.openTransaction(
(NavigatorTransaction transaction) => transaction.pushNamed('/second')
);
tester.pump(); // navigating always takes two frames tester.pump(); // navigating always takes two frames
tester.pump(new Duration(seconds: 1)); tester.pump(new Duration(seconds: 1));
...@@ -89,7 +91,9 @@ void main() { ...@@ -89,7 +91,9 @@ void main() {
expect(tester.findText('10'), isNull); expect(tester.findText('10'), isNull);
expect(tester.findText('100'), isNull); expect(tester.findText('100'), isNull);
navigatorKey.currentState.pop(); navigatorKey.currentState.openTransaction(
(NavigatorTransaction transaction) => transaction.pop()
);
tester.pump(); // navigating always takes two frames tester.pump(); // navigating always takes two frames
tester.pump(new Duration(seconds: 1)); tester.pump(new Duration(seconds: 1));
......
...@@ -22,14 +22,14 @@ class TestRoute extends Route<String> { ...@@ -22,14 +22,14 @@ class TestRoute extends Route<String> {
results.add('$name: $s'); results.add('$name: $s');
} }
void install(OverlayState overlay, OverlayEntry insertionPoint) { void install(OverlayEntry insertionPoint) {
log('install'); log('install');
OverlayEntry entry = new OverlayEntry( OverlayEntry entry = new OverlayEntry(
builder: (BuildContext context) => new Container(), builder: (BuildContext context) => new Container(),
opaque: true opaque: true
); );
_entries.add(entry); _entries.add(entry);
overlay?.insert(entry, above: insertionPoint); navigator.overlay?.insert(entry, above: insertionPoint);
routes.add(this); routes.add(this);
} }
...@@ -73,11 +73,11 @@ class TestRoute extends Route<String> { ...@@ -73,11 +73,11 @@ class TestRoute extends Route<String> {
void runNavigatorTest( void runNavigatorTest(
WidgetTester tester, WidgetTester tester,
NavigatorState host, NavigatorState host,
void test(NavigatorState transaction), NavigatorTransactionCallback test,
List<String> expectations List<String> expectations
) { ) {
expect(host, isNotNull); expect(host, isNotNull);
test(host); host.openTransaction(test);
expect(results, equals(expectations)); expect(results, equals(expectations));
results.clear(); results.clear();
tester.pump(); tester.pump();
...@@ -95,7 +95,7 @@ void main() { ...@@ -95,7 +95,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
}, },
[ [
'initial: install', 'initial: install',
...@@ -106,7 +106,7 @@ void main() { ...@@ -106,7 +106,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(second = new TestRoute('second')); transaction.push(second = new TestRoute('second'));
}, },
[ [
...@@ -118,7 +118,7 @@ void main() { ...@@ -118,7 +118,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(new TestRoute('third')); transaction.push(new TestRoute('third'));
}, },
[ [
...@@ -130,7 +130,7 @@ void main() { ...@@ -130,7 +130,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.replace(oldRoute: second, newRoute: new TestRoute('two')); transaction.replace(oldRoute: second, newRoute: new TestRoute('two'));
}, },
[ [
...@@ -143,7 +143,7 @@ void main() { ...@@ -143,7 +143,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.pop('hello'); transaction.pop('hello');
}, },
[ [
...@@ -155,7 +155,7 @@ void main() { ...@@ -155,7 +155,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.pop('good bye'); transaction.pop('good bye');
}, },
[ [
...@@ -182,7 +182,7 @@ void main() { ...@@ -182,7 +182,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
}, },
[ [
'first: install', 'first: install',
...@@ -193,7 +193,7 @@ void main() { ...@@ -193,7 +193,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(second = new TestRoute('second')); transaction.push(second = new TestRoute('second'));
}, },
[ [
...@@ -205,7 +205,7 @@ void main() { ...@@ -205,7 +205,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(new TestRoute('third')); transaction.push(new TestRoute('third'));
}, },
[ [
...@@ -217,7 +217,7 @@ void main() { ...@@ -217,7 +217,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.removeRouteBefore(second); transaction.removeRouteBefore(second);
}, },
[ [
...@@ -227,7 +227,7 @@ void main() { ...@@ -227,7 +227,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.pop('good bye'); transaction.pop('good bye');
}, },
[ [
...@@ -239,7 +239,7 @@ void main() { ...@@ -239,7 +239,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(new TestRoute('three')); transaction.push(new TestRoute('three'));
}, },
[ [
...@@ -252,7 +252,7 @@ void main() { ...@@ -252,7 +252,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(four = new TestRoute('four')); transaction.push(four = new TestRoute('four'));
}, },
[ [
...@@ -264,7 +264,7 @@ void main() { ...@@ -264,7 +264,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.removeRouteBefore(four); transaction.removeRouteBefore(four);
}, },
[ [
...@@ -274,7 +274,7 @@ void main() { ...@@ -274,7 +274,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.pop('the end'); transaction.pop('the end');
}, },
[ [
...@@ -301,7 +301,7 @@ void main() { ...@@ -301,7 +301,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
}, },
[ [
'A: install', 'A: install',
...@@ -311,7 +311,7 @@ void main() { ...@@ -311,7 +311,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(new TestRoute('B')); transaction.push(new TestRoute('B'));
}, },
[ [
...@@ -324,7 +324,7 @@ void main() { ...@@ -324,7 +324,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.push(routeC = new TestRoute('C')); transaction.push(routeC = new TestRoute('C'));
}, },
[ [
...@@ -337,7 +337,7 @@ void main() { ...@@ -337,7 +337,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.replaceRouteBefore(anchorRoute: routeC, newRoute: routeB = new TestRoute('b')); transaction.replaceRouteBefore(anchorRoute: routeC, newRoute: routeB = new TestRoute('b'));
}, },
[ [
...@@ -350,7 +350,7 @@ void main() { ...@@ -350,7 +350,7 @@ void main() {
runNavigatorTest( runNavigatorTest(
tester, tester,
host, host,
(NavigatorState transaction) { (NavigatorTransaction transaction) {
transaction.popUntil(routeB); transaction.popUntil(routeB);
}, },
[ [
......
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