replaceAllWith method

void replaceAllWith(
  1. BuildContext context,
  2. List<AppPageNode<T>> pages, {
  3. bool inChildNavigator = false,
})

Implementation

void replaceAllWith(
  BuildContext context,
  List<AppPageNode<T>> pages, {
  bool inChildNavigator = false,
}) {
  if (inChildNavigator) {
    final parentPageNode = _findAncestorPageNode(context);

    if (parentPageNode == null) {
      throw NavigationStackError(
          'Could not find AppPageNode from the current route.\n'
          'Given context Route is not in the pages stack.');
    }

    if (parentPageNode.crossroad == null) {
      throw NavigationStackError(
          'The given context\'s page does not have nested navigation.\n');
    }

    _rootPageNodesSetter = AppPageNodesStackUtil.updateNestedStack(
      parentPageNode.crossroad!.navigatorKey,
      _rootPageStack,
      (previousCrossroad) =>
          previousCrossroad.copyWithActiveBranchStack(NavigationStack(pages)),
    );
  } else {
    final navState = context.findAncestorStateOfType<NavigatorState>();

    final key = navState?.widget.key ?? rootNavKey;

    _rootPageNodesSetter = _handleStackAction(
      (currentStack) => currentStack.replaceAllWith(pages),
      key,
    );
  }

  notifyListeners();
}