Installation
import { Tabs, TabItem } from ‘@astrojs/starlight/components’;
Requirements
Section titled “Requirements”Before installing Go Router Guards, ensure you have:
- Dart SDK:
^3.5.0
- Flutter:
>=3.19.0
- go_router: Latest version
Package Installation
Section titled “Package Installation”Go Router Guards consists of two packages that you can install based on your needs:
flutter pub add go_router_guards route_guards
This gives you both the core guard system and Go Router integration.
flutter pub add go_router_guards
This automatically includes `route_guards` as a dependency.
flutter pub add route_guards
Use this if you're building your own router integration.
Import Statements
Section titled “Import Statements”After installation, add the appropriate imports to your Dart files:
// For Go Router integrationimport 'package:go_router_guards/go_router_guards.dart';
// For core guard functionality (if using separately)import 'package:route_guards/route_guards.dart';
// For Go Router (required)import 'package:go_router/go_router.dart';
Verify Installation
Section titled “Verify Installation”Create a simple test to verify the installation:
import 'package:flutter/material.dart';import 'package:go_router_guards/go_router_guards.dart';
class TestGuard extends GoRouterGuard { @override FutureOr<void> onGoRouterNavigation( NavigationResolver resolver, BuildContext context, GoRouterState state, ) { print('Guard executed successfully!'); resolver.next(); }}
If this compiles without errors, you’re ready to go!
Development Dependencies
Section titled “Development Dependencies”For development and testing, you might want to add:
dev_dependencies: # For type-safe routes (optional) go_router_builder: ^3.0.1
# For testing guards flutter_test: sdk: flutter mocktail: ^1.0.4
# For code quality very_good_analysis: ^10.0.0
IDE Setup
Section titled “IDE Setup”VS Code Extensions
Section titled “VS Code Extensions”For the best development experience, install:
- Dart: Official Dart support
- Flutter: Official Flutter support
- Dart Data Class Generator: For generating boilerplate
Android Studio/IntelliJ
Section titled “Android Studio/IntelliJ”Install the following plugins:
- Dart
- Flutter
Next Steps
Section titled “Next Steps”Now that you have Go Router Guards installed:
- 📚 Check out the Quick Start guide
- 🔍 Explore the route_guards package documentation
- ⚡ Learn about go_router_guards integration
- 🎯 Follow the Creating Guards guide
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Package not found
# Clear pub cache and retryflutter pub cache cleanflutter pub get
Import errors
// Make sure you're importing the correct packageimport 'package:go_router_guards/go_router_guards.dart'; // ✅ Correctimport 'package:go_router_guards/guards.dart'; // ❌ Wrong
Version conflicts
# Use dependency overrides if neededdependency_overrides: meta: ^1.16.0
Build errors with go_router_builder
# Regenerate type-safe routesdart run build_runner build --delete-conflicting-outputs
Getting Help
Section titled “Getting Help”If you encounter issues:
- Check the GitHub Issues
- Review the example app
- Ask in GitHub Discussions
Keeping Updated
Section titled “Keeping Updated”To update to the latest version:
flutter pub upgrade go_router_guards
Or specify a version constraint in your pubspec.yaml
:
dependencies: go_router_guards: ^1.0.0 route_guards: ^1.0.0