Flutter Go Router Navigation
ASecurityUse a typed `StatefulShellRoute` with one branch per tab. Each branch has its own navigator key, so navigating within Orders does not discard its stack when the user switches to Home or Profile. ```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; part 'app_router.g.dart'; @TypedStatefulShellRoute<AppShellRoute>( branches: [ TypedStatefulShellBranch<HomeBranch>( routes: [TypedGoRoute<HomeRoute>(path: '/home')], ), TypedStatefulShellBranch<OrdersBranch>( r...
- 584 stars
- 0 votes
- 0 copies
- 1 view
- Added September 5, 2026
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-go-router-navigation --agent claude-codeAre you the author of Flutter Go Router Navigation?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-go-router-navigation-abbe76ce)Use a typed `StatefulShellRoute` with one branch per tab. Each branch has its own navigator key, so navigating within Orders does not discard its stack when the user switches to Home or Profile.
```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
part 'app_router.g.dart';
@TypedStatefulShellRoute<AppShellRoute>(
branches: [
TypedStatefulShellBranch<HomeBranch>(
routes: [TypedGoRoute<HomeRoute>(path: '/home')],
),
TypedStatefulShellBranch<OrdersBranch>(
routes: [
TypedGoRoute<OrdersRoute>(
path: '/orders',
routes: [TypedGoRoute<OrderDetailRoute>(path: ':orderId')],
),
],
),
TypedStatefulShellBranch<ProfileBranch>(
routes: [TypedGoRoute<ProfileRoute>(path: '/profile')],
),
],
)
class AppShellRoute extends StatefulShellRouteData {
const AppShellRoute();
@override
Widget builder(
BuildContext context,
GoRouterState state,
StatefulNavigationShell navigationShell,
) => AppScaffold(navigationShell: navigationShell);
}
class HomeBranch extends StatefulShellBranchData {
static final $navigatorKey = GlobalKey<NavigatorState>();
}
class OrdersBranch extends StatefulShellBranchData {
static final $navigatorKey = GlobalKey<NavigatorState>();
}
class ProfileBranch extends StatefulShellBranchData {
static final $navigatorKey = GlobalKey<NavigatorState>();
}
class HomeRoute extends GoRouteData {
const HomeRoute();
@override
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}
class OrdersRoute extends GoRouteData {
const OrdersRoute();
@override
Widget build(BuildContext context, GoRouterState state) => const OrdersScreen();
}
class OrderDetailRoute extends GoRouteData {
const OrderDetailRoute({required this.orderId});
final String orderId;
@override
Widget build(BuildContext context, GoRouterState state) =>
OrderDetailScreen(orderId: orderId);
}
class ProfileRoute extends GoRouteData {
const ProfileRoute();
@override
Widget build(BuildContext context, GoRouterState state) => const ProfileScreen();
}
class AppScaffold extends StatelessWidget {
const AppScaffold({super.key, required this.navigationShell});
final StatefulNavigationShell navigationShell;
@override
Widget build(BuildContext context) => Scaffold(
body: navigationShell,
bottomNavigationBar: NavigationBar(
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: (index) => navigationShell.goBranch(
index,
initialLocation: index == navigationShell.currentIndex,
),
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
NavigationDestination(icon: Icon(Icons.receipt_long), label: 'Orders'),
NavigationDestination(icon: Icon(Icons.person), label: 'Profile'),
],
),
);
}
```
Create and register one global router from the generated routes: `final appRouter = GoRouter(routes: $appRoutes);`. Navigate with route objects, such as `const OrdersRoute().go(context)` and `OrderDetailRoute(orderId: id).push(context)`, rather than raw paths or `context.go` strings.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.