willPop method

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

Returns the value of the first callback added with addScopedWillPopCallback that returns false. If they all return true, returns the inherited method's result (see Route.willPop).

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 (WillPopCallback callback in List<WillPopCallback>.from(_willPopCallbacks)) {
    if (!await callback())
      return RoutePopDisposition.doNotPop;
  }
  return await super.willPop();
}