Commit 8082f94d authored by chenxiao's avatar chenxiao

增加maybePop,使得willPopScope可用

parent f6c10426
...@@ -132,6 +132,8 @@ class BoostContainerState extends NavigatorState { ...@@ -132,6 +132,8 @@ class BoostContainerState extends NavigatorState {
@override @override
BoostContainer get widget => super.widget as BoostContainer; BoostContainer get widget => super.widget as BoostContainer;
final List<Route<dynamic>> routerHistory = <Route<dynamic>>[];
ContainerNavigatorObserver findContainerNavigatorObserver( ContainerNavigatorObserver findContainerNavigatorObserver(
Navigator navigator) { Navigator navigator) {
for (NavigatorObserver observer in navigator.observers) { for (NavigatorObserver observer in navigator.observers) {
...@@ -146,7 +148,7 @@ class BoostContainerState extends NavigatorState { ...@@ -146,7 +148,7 @@ class BoostContainerState extends NavigatorState {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
backPressedHandler = ()=>pop(); backPressedHandler = () => maybePop();
} }
@override @override
...@@ -160,6 +162,7 @@ class BoostContainerState extends NavigatorState { ...@@ -160,6 +162,7 @@ class BoostContainerState extends NavigatorState {
void dispose() { void dispose() {
findContainerNavigatorObserver(widget)?.removeBoostNavigatorObserver( findContainerNavigatorObserver(widget)?.removeBoostNavigatorObserver(
FlutterBoost.containerManager.navigatorObserver); FlutterBoost.containerManager.navigatorObserver);
routerHistory.clear();
super.dispose(); super.dispose();
} }
...@@ -169,18 +172,43 @@ class BoostContainerState extends NavigatorState { ...@@ -169,18 +172,43 @@ class BoostContainerState extends NavigatorState {
backPressedHandler?.call(); backPressedHandler?.call();
} }
@override
Future<bool> maybePop<T extends Object>([T result]) async {
final Route<T> route = routerHistory.last;
final RoutePopDisposition disposition = await route.willPop();
if (mounted) {
switch (disposition) {
case RoutePopDisposition.pop:
pop(result);
return true;
break;
case RoutePopDisposition.doNotPop:
return false;
break;
case RoutePopDisposition.bubble:
pop(result);
return true;
break;
}
}
}
@override @override
bool pop<T extends Object>([T result]) { bool pop<T extends Object>([T result]) {
if (routerHistory.length > 1) {
routerHistory.removeLast();
}
if (canPop()) { if (canPop()) {
return super.pop(result); return super.pop(result);
} else { } else {
if (T is Map<String,dynamic>) { if (T is Map<String, dynamic>) {
FlutterBoost.singleton.close(uniqueId, result:result as Map<String,dynamic>); FlutterBoost.singleton
}else{ .close(uniqueId, result: result as Map<String, dynamic>);
} else {
FlutterBoost.singleton.close(uniqueId); FlutterBoost.singleton.close(uniqueId);
} }
} }
return false; return false;
} }
...@@ -194,6 +222,8 @@ class BoostContainerState extends NavigatorState { ...@@ -194,6 +222,8 @@ class BoostContainerState extends NavigatorState {
Future<T> future = super.push<T>(newRoute ?? route); Future<T> future = super.push<T>(newRoute ?? route);
routerHistory.add(route);
if (FlutterBoost.containerManager.postPushRoute != null) { if (FlutterBoost.containerManager.postPushRoute != null) {
FlutterBoost.containerManager FlutterBoost.containerManager
.postPushRoute(name, uniqueId, params, newRoute ?? route, future); .postPushRoute(name, uniqueId, params, newRoute ?? route, future);
......
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