Flutter Go Router Navigation
ASecurityPut authentication policy on the single root `GoRouter` through its `redirect` callback. Pages should render their UI only; they must not redirect from `build`. ```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; part 'app_router.g.dart'; abstract interface class AuthSession { bool get isLoggedIn; } @TypedGoRoute<LoginRoute>(path: '/login') class LoginRoute extends GoRouteData { const LoginRoute({this.from}); final String? from; @override Widget build(Bu...
- 584 stars
- 0 votes
- 1 copy
- 6 views
- 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-66f9c2c2)Put authentication policy on the single root `GoRouter` through its `redirect` callback. Pages should render their UI only; they must not redirect from `build`.
```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
part 'app_router.g.dart';
abstract interface class AuthSession {
bool get isLoggedIn;
}
@TypedGoRoute<LoginRoute>(path: '/login')
class LoginRoute extends GoRouteData {
const LoginRoute({this.from});
final String? from;
@override
Widget build(BuildContext context, GoRouterState state) => const LoginScreen();
}
@TypedGoRoute<CartRoute>(path: '/cart')
class CartRoute extends GoRouteData {
const CartRoute();
@override
Widget build(BuildContext context, GoRouterState state) => const CartScreen();
}
@TypedGoRoute<CheckoutRoute>(path: '/checkout')
class CheckoutRoute extends GoRouteData {
const CheckoutRoute();
@override
Widget build(BuildContext context, GoRouterState state) => const CheckoutScreen();
}
GoRouter createAppRouter(AuthSession auth) => GoRouter(
routes: $appRoutes,
redirect: (context, state) {
final protectedLocations = {'/cart', '/checkout'};
final needsAuth = protectedLocations.contains(state.uri.path);
final onLogin = state.uri.path == '/login';
if (!auth.isLoggedIn && needsAuth) {
return LoginRoute(from: state.uri.toString()).location;
}
if (auth.isLoggedIn && onLogin) {
return state.uri.queryParameters['from'] ?? const CartRoute().location;
}
return null;
},
);
```
After the login state changes, notify the router so it re-evaluates redirection (for example, supply an auth `ChangeNotifier` as `refreshListenable`, or a stream with `GoRouterRefreshStream`). Navigation remains typed: `const CartRoute().go(context)` and `const CheckoutRoute().push(context)`. If `from` can point outside the app, validate or constrain it before using it to avoid open redirects.
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.