Skip to content

[Tech Improvement] Migrating to auto_route for routingΒ #452

@fres-sudo

Description

@fres-sudo

πŸ“ 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
  • 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions