goBranch method

void goBranch(
  1. int index, {
  2. bool initialLocation = false,
})

Navigate to the last location of the StatefulShellBranch at the provided index in the associated StatefulShellBranch.

This method will switch the currently active branch Navigator for the StatefulShellRoute. If the branch has not been visited before, or if initialLocation is true, this method will navigate to initial location of the branch (see StatefulShellBranch.initialLocation).

Implementation

// TODO(chunhtai): figure out a way to avoid putting navigation API in widget
// class.
void goBranch(int index, {bool initialLocation = false}) {
  final StatefulShellRoute route =
      shellRouteContext.route as StatefulShellRoute;
  final StatefulNavigationShellState? shellState =
      route._shellStateKey.currentState;
  if (shellState != null) {
    shellState.goBranch(index, initialLocation: initialLocation);
  } else {
    _router.go(_effectiveInitialBranchLocation(index));
  }
}