popUntil<T extends Object> method

void popUntil<T extends Object>(
  1. String target, [
  2. T? result
])

pop until a page, find the first match target, if not find in this navigator, find in native, this way will remove all un match VC and route

eg: N1(/main) F1(/home) F1(/first) popUntil(/main) will remove /home /first and VC(F1)

Implementation

void popUntil<T extends Object>(String target, [T? result]) async {
  ///find in current routes, remove top
  if (foundInCurrentRoutes(target)) {
    bool findTarget = false;
    while (!findTarget) {
      if (_history.isNotEmpty) {
        RouteConfig temp = _history.last;
        if (temp.currentPage!.path.regex.hasMatch(target)) {
          findTarget = true;
          _callbacks[temp]?.complete(result);
        } else {
          _history.removeLast();
        }
      } else {
        findTarget = true;
      }
    }
    notifyListeners();
  } else {
    print('not find ${target} in Uris');
  }

  /// multiply flutters should chat with native
  if (multiple) {
    await NavigatorChannel.popUntil(target, result);
  }
}