popUntil<T extends Widget> method

void popUntil<T extends Widget>([
  1. Object? result
])

Pops all routes until the page of type T is visible. The page must have been pushed with push before so the route name matches the widget type.

Implementation

void popUntil<T extends Widget>([Object? result]) {
  assert(T != Widget, 'Provide a page type: popUntil<MyPage>()');
  final state = _key.currentState;
  if (state == null) {
    return;
  }
  var found = false;
  state.popUntilWithResult(
    (route) {
      if (route.settings.name == T.toString()) {
        found = true;
        return true;
      }
      return route.isFirst;
    },
    result,
  );
  assert(found, 'popUntil<$T>: no route named "$T" in the stack');
}