sossoldi icon indicating copy to clipboard operation
sossoldi copied to clipboard

[Tech Improvement] Migrating to `auto_route` for routing

Open fres-sudo opened this issue 4 months ago • 0 comments

📝 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

  1. Add auto_route dependency to pubspec.yaml
  2. Create AppRouter class with @AutoRouterConfig annotation
  3. Define routes using @RoutePage annotations on page widgets
  4. Generate routing code using build_runner
  5. Replace MaterialApp with MaterialApp.router
  6. Update all Navigator.pushNamed calls to use context.router.push()
  7. Implement nested routing where applicable
  8. 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
  • [x] 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

  • [x] ✅ I agree to the Code of Conduct

fres-sudo avatar Aug 02 '25 10:08 fres-sudo