Move default back behavior to FlutterWidgetBinding

Previously MaterialApp was responsible for ending the activity when the
back stack was empty. However, this behavior is more general than
material. This patch moves the behavior to FlutterWidgetBinding, which
has a global view of all the binding observers.

Fixes #1086
This commit is contained in:
Adam Barth 2016-01-07 09:24:14 -08:00
parent 19fb068d83
commit e3d587ea52
2 changed files with 5 additions and 4 deletions

View File

@ -86,11 +86,11 @@ 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);
bool result = false;
navigator.openTransaction((NavigatorTransaction transaction) { navigator.openTransaction((NavigatorTransaction transaction) {
if (!transaction.pop()) result = transaction.pop();
activity.finishCurrentActivity();
}); });
return true; return result;
} }
void didChangeSize(Size size) => setState(() { _size = size; }); void didChangeSize(Size size) => setState(() { _size = size; });

View File

@ -77,8 +77,9 @@ class WidgetFlutterBinding extends BindingBase with Scheduler, Gesturer, Rendere
void handlePopRoute() { void handlePopRoute() {
for (BindingObserver observer in _observers) { for (BindingObserver observer in _observers) {
if (observer.didPopRoute()) if (observer.didPopRoute())
break; return;
} }
activity.finishCurrentActivity();
} }
void handleAppLifecycleStateChanged(ui.AppLifecycleState state) { void handleAppLifecycleStateChanged(ui.AppLifecycleState state) {