-
Notifications
You must be signed in to change notification settings - Fork 188
Description
📝 Improvement Description
Migrate from the default Flutter routing system to auto_route
package for better type-safe navigation, code generation, and improved developer experience.
🛑 Problem Statement
The current default routing system lacks type safety, requires manual route configuration, and makes navigation code verbose and error-prone. String-based route names are difficult to maintain and refactor, leading to runtime errors and poor developer experience.
💡 Proposed Solution
- Add
auto_route
dependency topubspec.yaml
- Create
AppRouter
class with@AutoRouterConfig
annotation - Define routes using
@RoutePage
annotations on page widgets - Generate routing code using
build_runner
- Replace
MaterialApp
withMaterialApp.router
- Update all
Navigator.pushNamed
calls to usecontext.router.push()
- Implement nested routing where applicable
- Add route guards for authentication if needed
🌿 Benefits
- Type-safe routing with compile-time error checking
- Code generation reduces boilerplate and human errors
- Better IDE support with auto-completion for routes
- Easier refactoring and maintenance
- Support for nested routing and complex navigation patterns
- Built-in route guards and middleware support
- Improved developer experience and productivity
- Better testability of navigation logic
🧱 Impact Area
- Backend
- Frontend
- Infrastructure
- DevOps
- Other
✍️ Additional Context
Related packages to consider:
- auto_route
- auto_route_generator
- build_runner
Build Runner Introduction Consequences:
🔄 Development workflow: Requires running dart run build_runner build
after route changes
🏗️ CI/CD impact: Build pipelines must include code generation step before compilation
📁 Git considerations: Generated files (*.gr.dart) shouldn't be committed to version control
👥 Team coordination: All developers must run build_runner after pulling route changes
⏱️ Build time: Initial setup and route changes will slightly increase build duration
🐛 Debugging: Generated code may complicate stack traces and debugging
📦 Dependency management: Additional dev dependencies increase project complexity
💻 IDE integration: Some IDEs may require restart after code generation
Migration checklist:
- Update pubspec.yaml dependencies
- Create router configuration
- Annotate existing pages
- Generate routing code
- Update main.dart
- Replace all navigation calls
- Test all navigation flows
- Update CI/CD pipeline for
build_runner
- Update development documentation
- Configure IDE/editor for generated files
📜 Code of Conduct
- ✅ I agree to the Code of Conduct