willPop method

  1. @Deprecated('Use popDisposition instead. ' 'This feature was deprecated after v3.12.0-1.0.pre.')
  2. @override
Future<RoutePopDisposition> willPop()

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:


  'Use popDisposition instead. '
  'This feature was deprecated after v3.12.0-1.0.pre.',
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()) {
      return RoutePopDisposition.doNotPop;
  return super.willPop();