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 using a shell route as a wrapper around other routes to share a common internal navigator and UI elements.

The StatefulShellRoute widget is not a route itself, but a container for other routes, allowing you to share a common internal navigator and UI elements.

To achieve this navigation, follow these steps:

  1. Define Your Shell Route:
  2. StatefulShellRoute.indexedStack(
      builder: (BuildContext context, GoRouterState state,
          StatefulNavigationShell navigationShell) {
        return HomeScreen(navigationShell: navigationShell);
      },
      branches: <StatefulShellBranch>[
        // ... Define your shell branches here.
      ],
    );
    
  3. Create Routes for Each Branch:
  4. StatefulShellBranch(
      navigatorKey: _sectionANavigatorKey,
      routes: <RouteBase>[
        GoRoute(
          path: '/a',
          builder: (BuildContext context, GoRouterState state) =>
              const ScreenAShellBody(),
        ),
      ],
    ),
    
    // ... Define other shell branches and routes here.
    
  5. Navigate to the Shell Route:
  6. context.goNamed('shell');
    
  7. Navigate Within the Shell Branches:
  8. context.go('/a'); // Navigates to the first branch's route
    context.go('/b'); // Navigates to the second branch's route
    

By following these steps, you can navigate from a splash screen to a StatefulShellRoute.indexedStack route, allowing you to share common UI elements and a common internal navigator across multiple routes.

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.