popRoute method

  1. @override
Future<bool> popRoute({
  1. Object? result,
  2. PopMode? popMode,
})
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({
  Object? result,
  PopMode? popMode,
}) async {
  //Returning false will cause the entire app to be popped.
  final bool wasPopup = await handlePopupRoutes(result: result);
  if (wasPopup) {
    return true;
  }

  if (_canPop(popMode ?? backButtonPopMode)) {
    await _pop(popMode ?? backButtonPopMode, result as T?);
    notifyListeners();
    return true;
  }

  return super.popRoute();
}