Notification texts go here Contact Us Buy Now!

How to Navigate from Splash Screen to a StatefulShellRoute.indexedStack route of go_router Flutter

Navigating from a Splash Screen to a StatefulShellRoute.indexedStack route in go_router Flutter involves defining a shell route (StatefulShellRoute) with a builder function that provides a shell widget (HomeScreen).

In the shell route, the StatefulNavigationShell widget allows navigation to other branches in a stateful manner using goBranch().

To navigate to routes outside the shell route, you can use context.goNamed(nameOfTheRoute) or context.go(pathOfTheRoute).

For example, with three routes "/a", "/b", and "/c" within the shell, you can define them as follows:

StatefulShellRoute.indexedStack(
  builder: (BuildContext context, GoRouterState state,
      StatefulNavigationShell navigationShell) {
    return HomeScreen(navigationShell: navigationShell);
  },
  branches: <StatefulShellBranch>[
    // Route branch for the first tab in the bottom navigation bar
    StatefulShellBranch(
      navigatorKey: _sectionANavigatorKey,
      routes: <RouteBase>[
        GoRoute(
          // Screen in the first tab
          path: '/a',
          builder: (BuildContext context, GoRouterState state) =>
              const ScreenAShellBody(),
        ),
      ],
    ),

    // Route branch for the second tab
    StatefulShellBranch(
      routes: <RouteBase>[
        GoRoute(
          // Screen in the second tab
          path: '/b',
          builder: (BuildContext context, GoRouterState state) =>
              const ScreenBShellBody(),
        ),
      ],
    ),

    // Route branch for the third tab
    StatefulShellBranch(
      routes: <RouteBase>[
        GoRoute(
          // Screen in the third tab
          path: '/c',
          builder: (BuildContext context, GoRouterState state) =>
              const ScreenCShellBody(),
        ),
      ],
    ),
  ],
)

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.