Skip to content
Back to skills

Flutter Auto Route Navigation

ASecurity

Use an `AutoRouteGuard` on the cart route so the routing layer, not the UI, enforces authentication. In `auto_route`, the guard can check auth state and redirect unauthenticated users to `LoginRoute()`. ```dart import 'package:auto_route/auto_route.dart'; class AuthGuard extends AutoRouteGuard { final AuthService authService; AuthGuard(this.authService); @override void onNavigation(NavigationResolver resolver, StackRouter router) { final isLoggedIn = authService.isLoggedIn; if (isLoggedIn) { ...

  • 584 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
development

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-auto-route-navigation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flutter Auto Route Navigation?

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

Security grade badge for Flutter Auto Route Navigation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-flutter-auto-route-navigation-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-auto-route-navigation-agent-skills-standard)

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
Use an `AutoRouteGuard` on the cart route so the routing layer, not the UI, enforces authentication. In `auto_route`, the guard can check auth state and redirect unauthenticated users to `LoginRoute()`.

```dart
import 'package:auto_route/auto_route.dart';

class AuthGuard extends AutoRouteGuard {
  final AuthService authService;

  AuthGuard(this.authService);

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    final isLoggedIn = authService.isLoggedIn;

    if (isLoggedIn) {
      resolver.next(true);
      return;
    }

    router.push(
      LoginRoute(
        onLoginResult: (success) {
          if (success) {
            resolver.next(true);
          } else {
            resolver.next(false);
          }
        },
      ),
    );
  }
}
```

Then attach the guard to the cart route in your router configuration:

```dart
@AutoRouterConfig()
class AppRouter extends _$AppRouter {
  AppRouter(this.authGuard);

  final AuthGuard authGuard;

  @override
  List<AutoRoute> get routes => [
    AutoRoute(page: HomeRoute.page, initial: true),
    AutoRoute(page: LoginRoute.page),
    AutoRoute(
      page: CartRoute.page,
      guards: [authGuard],
    ),
  ];
}
```

Make sure the cart page is annotated so `auto_route` generates the typed route:

```dart
@RoutePage()
class CartPage extends StatelessWidget {
  const CartPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(child: Text('Cart')),
    );
  }
}
```

Why this is the right pattern:

- It keeps navigation type-safe by using `CartRoute()` and `LoginRoute()` instead of route-name strings.
- It protects the route centrally in the router, so every entry path to the cart is covered.
- It avoids putting navigation logic in BLoC or business logic layers.

If you want to return the user to the cart automatically after login, pass the pending intent through the login flow and call `resolver.next(true)` only after successful authentication.

Files in this skill

  • eval-1.baseline.md1.5 KB
  • eval-1.with-skill.md2 KB
  • eval-2.baseline.md1.5 KB
  • eval-2.with-skill.md1.6 KB
  • eval-3.baseline.md2.2 KB
  • eval-3.with-skill.md2.8 KB
  • trigger-1.md144 B
  • trigger-2.md174 B
  • trigger-3.md158 B
  • trigger-4.md163 B
  • trigger-5.md182 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.