popRoute method
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 NavigatorState? state = _findCurrentNavigator();
if (state != null) {
final bool didPop = await state.maybePop(); // Call maybePop() directly
if (didPop) {
return true; // Return true if maybePop handled the pop
}
}
// Fallback to onExit if maybePop did not handle the pop
final GoRoute lastRoute = currentConfiguration.last.route;
if (lastRoute.onExit != null && navigatorKey.currentContext != null) {
return !(await lastRoute.onExit!(
navigatorKey.currentContext!,
currentConfiguration.last
.buildState(_configuration, currentConfiguration),
));
}
return false;
}