popUntilWithResult<T extends Object?> method
- RoutePredicate predicate,
- T? result
Calls pop repeatedly until the predicate returns true, returning the
result to the last popped route.
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.
Implementation
@optionalTypeArgs
void popUntilWithResult<T extends Object?>(RoutePredicate predicate, T? result) {
_RouteEntry? candidate = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate);
while (candidate != null) {
if (predicate(candidate.route)) {
return;
}
// Check what would be next if we pop this route.
final _RouteEntry? next = _lastRouteEntryWhereOrNull(
(_RouteEntry e) => _RouteEntry.isPresentPredicate(e) && e != candidate,
);
if (next != null && !next.route.willHandlePopInternally && predicate(next.route)) {
pop<T>(result);
} else {
pop();
}
candidate = _lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate);
}
}