removeUntil method

bool removeUntil(
  1. RouteDataPredicate predicate, {
  2. bool scoped = true,
})

Calls removeRoute repeatedly until the predicate returns true.

Note: removeRoute does not respect willPopScopes if scoped is set to true the predicate will visit all StackRouters in hierarchy starting from top until satisfied

Implementation

bool removeUntil(RouteDataPredicate predicate, {bool scoped = true}) {
  if (scoped) {
    return _removeUntil(predicate);
  }
  final routers = _topMostRouter()._buildRoutersHierarchy();
  bool predicateWasSatisfied = false;
  for (final router in routers.whereType<StackRouter>()) {
    router._removeUntil((route) {
      return predicateWasSatisfied = predicate(route);
    });
    if (predicateWasSatisfied) break;
  }
  return predicateWasSatisfied;
}