willPop method
- @override
inherited
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:
Form
, which provides anonWillPop
callback that uses this mechanism.- addScopedWillPopCallback, which adds a callback to the list this method checks.
- removeScopedWillPopCallback, which removes a callback from the list this method checks.
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();
}