popUntil method

void popUntil(
  1. RoutePredicate predicate, {
  2. bool scoped = true,
})

Calls maybePop repeatedly on the navigator until the predicate returns true.

see Navigator.popUntil

if scoped is set to true the predicate will visit all StackRouters in hierarchy starting from top until satisfied

Implementation

void popUntil(RoutePredicate predicate, {bool scoped = true}) {
  if (scoped) {
    return _navigatorKey.currentState?.popUntil(predicate);
  }
  final routers = _topMostRouter()._buildRoutersHierarchy();
  bool predicateWasSatisfied = false;
  for (final router in routers.whereType<StackRouter>()) {
    final navState = router._navigatorKey.currentState;
    if (navState == null) break;
    navState.popUntil((route) {
      return predicateWasSatisfied = predicate(route);
    });
    if (predicateWasSatisfied) break;
  }
}