Skip to content
Back to skills

Flutter Go Router Navigation

ASecurity

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(Bu...

  • 584 stars
  • 0 votes
  • 1 copy
  • 6 views
  • Added September 5, 2026
developmentgo

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-go-router-navigation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flutter Go Router Navigation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Flutter Go Router Navigation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-flutter-go-router-navigation-66f9c2c2/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-go-router-navigation-66f9c2c2)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
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.md1.7 KB
  • eval-1.with-skill.md1.4 KB
  • eval-2.baseline.md2.1 KB
  • eval-2.with-skill.md1.9 KB
  • eval-3.baseline.md2.8 KB
  • eval-3.with-skill.md3.2 KB
  • trigger-1.md134 B
  • trigger-2.md118 B
  • trigger-3.md100 B
  • trigger-4.md131 B
  • trigger-5.md116 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.