willPop method

  1. @override
Future<RoutePopDisposition> willPop()
override

Returns RoutePopDisposition.doNotPop if any of callbacks added with addScopedWillPopCallback returns either false or null. If they all return true, the base Route.willPop's result will be returned. The callbacks will be called in the order they were added, and will only be called if all previous callbacks returned true.

Typically this method is not overridden because applications usually don't create modal routes directly, they use higher level primitives like showDialog. The scoped WillPopCallback list makes it possible for ModalRoute descendants to collectively define the value of willPop.

See also:

Implementation

@override
Future<RoutePopDisposition> willPop() async {
  final _ModalScopeState<T>? scope = _scopeKey.currentState;
  assert(scope != null);
  for (final WillPopCallback callback
      in List<WillPopCallback>.of(_willPopCallbacks)) {
    if (await callback() != true) {
      return RoutePopDisposition.doNotPop;
    }
  }
  return super.willPop();
}