replaceAll method

void replaceAll(
  1. List<PageRouteInfo<Object?>>? routes,
  2. int previousIndex
)

Resets _pages stack with given routes and sets previousActiveRoute as active index if provided

Implementation

void replaceAll(List<PageRouteInfo>? routes, int previousIndex) {
  final routesToPush = _resolveRoutes(routes);
  final previousActiveRoute = stackData[previousIndex];

  _pages.clear();
  _childControllers.clear();
  _pushAll(routesToPush, fromDefault: routes == null);
  var targetIndex = routesToPush.indexWhere((r) => r.name == previousActiveRoute.name);
  if (targetIndex == -1) {
    targetIndex = homeIndex == -1 ? 0 : homeIndex;
  }
  setActiveIndex(targetIndex, notify: false);
}