ShellIndexedStackConfig<TRouteData extends Widget> class
abstract
- ShellIndexedStackConfig
Base config for an indexedStack StatefulShellRoute in GoRouter.
Use this for the "main shell" that owns bottom navigation / tabbed layout:
- E.g. Home, Explore, Wallet, Profile tabs.
- Each tab is a
StatefulShellBranch.
Example:
class MainShellRouteData extends StatelessWidget {
final int currentIndex;
const MainShellRouteData({super.key, required this.currentIndex});
@override
Widget build(BuildContext context) {
// Build your Scaffold with BottomNavigationBar using currentIndex
}
}
class MainShellConfig extends ShellIndexedStackConfig<MainShellRouteData> {
const MainShellConfig();
@override
List<StatefulShellBranch> get branches => [
StatefulShellBranch(
routes: [
GoRoute(
path: '/home',
name: 'home',
builder: (context, state) => const HomeScreen(),
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: '/profile',
name: 'profile',
builder: (context, state) => const ProfileScreen(),
),
],
),
];
@override
MainShellRouteData routeConfig(GoRouterState state) {
// Determine the current tab index from the route state.
final index = state.matchedLocation.contains('/profile') ? 1 : 0;
return MainShellRouteData(currentIndex: index);
}
}
// GoRouter registration:
final shellConfig = MainShellConfig();
final router = GoRouter(
routes: [
StatefulShellRoute.indexedStack(
branches: shellConfig.branches,
builder: (context, state, navigationShell) {
final data = shellConfig.routeConfig(state);
return data; // your shell widget
},
),
],
);
Constructors
- ShellIndexedStackConfig()
-
const
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
routeConfig(
GoRouterState state) → TRouteData -
Map the current
GoRouterStateto a typed route data widget. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited