popRoute method
override
Called by the Router when the Router.backButtonDispatcher reports that the operating system is requesting that the current route be popped.
The method should return a boolean Future to indicate whether this delegate handles the request. Returning false will cause the entire app to be popped.
Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.
Implementation
@override
Future<bool> popRoute() async {
final navigator = navigatorKey.currentState;
if (navigator == null) {
return SynchronousFuture<bool>(false);
}
final navigatorDidPop = await navigator.maybePop();
// Navigator will not pop the current page if the page actually exists in
// the nested navigator. We try popping the app route manually in this case.
if (!navigatorDidPop && await _canPop(navigatorDidPop)) {
final appRouteDidPop = popAppRoute();
return appRouteDidPop;
}
return true;
}