Go Router Modular Banner

🧩 GoRouter Modular πŸ’‰

Dependency injection and route management

Perfect for micro-frontends and event-driven communication

Pub Version GitHub Stars License

GoRouter Modular brings modular architecture on top of GoRouter with per-module dependency injection and auto-dispose. Perfect for micro frontends and large-scale apps. πŸš€

πŸ’‘ Inspired by flutter_modular
GoRouter Modular is inspired by the modular architecture approach from flutter_modular by Flutterando. We are grateful for their contribution to the Flutter ecosystem.


Complete Documentation

Open the Docs

Contents

✨ Key Features

  • 🧩 Modular Architecture - Independent, reusable modules
  • πŸ’‰ Dependency Injection - Built-in DI with auto-dispose
  • πŸ›£οΈ GoRouter Integration - Type-safe and declarative navigation
  • 🎭 Event System - Event-driven communication between modules
  • πŸš€ Performance - Lazy loading and efficient memory management
  • πŸ›‘οΈ Type Safety - Fully type-safe with compile-time error detection

πŸ”„ Migration Guide (v4 β†’ v5)

Migrate from the old FutureOr<List<Bind<Object>>> binds() list to the new FutureBinds binds(Injector i) function.

What Changed?

Starting with v5.0, GoRouter Modular features a completely redesigned dependency injection system built from the ground up. The bind registration system changed from returning a list to using a function with an injector for better async support and improved type inference. This new implementation provides 4x faster performance and is significantly more robust.

Why the migration?

  • βœ… Better async support - Native support for asynchronous bind initialization
  • βœ… Improved type inference - Enhanced type safety and better compile-time checks
  • βœ… 4x faster performance - Optimized dependency resolution and injection
  • βœ… More robust - Better error handling and dependency cycle detection

❌ Old Way (v4.x)

class MyModule extends Module {
  @override
  FutureOr<List<Bind<Object>>> binds() => [
    Bind.factory<ApiService>((i) => ApiService()),
    Bind.singleton<DatabaseService>((i) => DatabaseService()),
  ];
}

βœ… New Way (v5.x)

class MyModule extends Module {
  @override
  FutureBinds binds(Injector i) {
    i.add<ApiService>((i) => ApiService());
    i.addSingleton<DatabaseService>((i) => DatabaseService());
  }
}

Migration Steps

1. Change Method Signature

// Old (v4.x)
@override
FutureOr<List<Bind<Object>>> binds() => [
  Bind.singleton<MyService>((i) => MyService()),
];

// New (v5.x) - Using the new injector API
@override
FutureBinds binds(Injector i) {
  i.addSingleton<MyService>((i) => MyService());
}

2. Update Registration Syntax

// Old (v4.x)
Bind.singleton<ApiService>((i) => ApiService())

// New (v5.x) - Using the new injector API
i.addSingleton<ApiService>((i) => ApiService())

3. Use Keys When Needed

@override
FutureBinds binds(Injector i) {
  i.addSingleton<ApiService>((i) => ApiService(), key: 'main');
  i.addSingleton<ApiService>((i) => ApiService(), key: 'backup');
}

Benefits

  • βœ… 4x faster performance - Optimized dependency resolution and injection
  • βœ… Better async support - Native support for asynchronous bind initialization
  • βœ… Improved type inference - Enhanced type safety with better compile-time checks
  • βœ… More robust - Better error handling and dependency cycle detection
  • βœ… Cleaner syntax - More intuitive API without Bind wrapper overhead
  • βœ… Same functionality - All features preserved with better performance

🀝 Contributing

Contributions are very welcome! Open an issue to discuss major changes and submit a PR with clear descriptions of the edits.

  • Follow the project conventions and keep docs updated.
  • Add small usage examples when introducing new features.

πŸ“„ License

This project is distributed under the MIT license. See LICENSE for details.


πŸŽ‰ Happy Coding with GoRouter Modular! πŸŽ‰

Transform your Flutter app into a scalable, modular masterpiece ✨

Contributors

Made with contrib.rocks


Libraries

go_router_modular