popUntil method Null safety
- RoutePredicate predicate
Calls pop repeatedly until the predicate returns true.
The predicate may be applied to the same route more than once if Route.willHandlePopInternally is true.
To pop until a route with a certain name, use the RoutePredicate returned from ModalRoute.withName.
The routes are closed with null as their return
value.
See pop for more details of the semantics of popping a route.
Typical usage is as follows:
void _doLogout() {
navigator.popUntil(ModalRoute.withName('/login'));
}
Implementation
void popUntil(RoutePredicate predicate) {
_RouteEntry? candidate = _history.cast<_RouteEntry?>().lastWhere(
(_RouteEntry? e) => e != null && _RouteEntry.isPresentPredicate(e),
orElse: () => null,
);
while(candidate != null) {
if (predicate(candidate.route)) {
return;
}
pop();
candidate = _history.cast<_RouteEntry?>().lastWhere(
(_RouteEntry? e) => e != null && _RouteEntry.isPresentPredicate(e),
orElse: () => null,
);
}
}