Commit 8082f94d authored by chenxiao's avatar chenxiao

增加maybePop,使得willPopScope可用

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