go_router_modular 5.0.0+2
go_router_modular: ^5.0.0+2 copied to clipboard
Modular Routing and Dependency Injection for Flutter with GoRouter. Features event-driven architecture for seamless module communication and micro-frontend support.
🧩 GoRouter Modular 💉 #
Dependency injection and route management
Perfect for micro-frontends and event-driven communication
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 #
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 binds() list to the new binds(Injector i) function.
What Changed? #
Starting with v5.0, GoRouter Modular now uses auto_injector as the new dependency injection system. The bind registration system changed from returning a list to using a function with an injector. Binds are now injected using .new, and it's important to always type your dependencies for better type safety and inference.
❌ 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) {
// Using .new with auto_injector - remember to type your dependencies!
i.add<ApiService>((i) => ApiService());
i.addSingleton<DatabaseService>((i) => DatabaseService());
//or
i.add<ApiService>(ApiService.new);
i.addSingleton<DatabaseService>(DatabaseService.new);
}
}
Migration Steps #
1. Change Method Signature
// Old (v4.x)
@override
FutureOr<List<Bind<Object>>> binds() => [
Bind.singleton<MyService>((i) => MyService()),
];
// New (v5.x) - Using auto_injector with .new
@override
FutureBinds binds(Injector i) {
// Always type your dependencies!
i.addSingleton<MyService>(MyService.new);
}
⚠️ Important: Always type your dependencies (e.g.,
<MyService>) when using.newto ensure proper type inference and safety.
2. Update Registration Syntax
// Old (v4.x)
Bind.singleton<ApiService>((i) => ApiService())
// New (v5.x) - Using .new with auto_injector
// Remember to type your dependencies!
i.addSingleton<ApiService>(()=> ApiService())
//or
i.addSingleton<ApiService>(ApiService.new)
3. Use Keys When Needed
@override
FutureBinds binds(Injector i) {
// Using .new with auto_injector - always type your dependencies!
i.addSingleton<ApiService>(ApiService.new, key: 'main');
i.addSingleton<ApiService>(ApiService.new, key: 'backup');
}
Benefits #
- ✅ Cleaner syntax - No more Bind wrapper
- ✅ Better performance - Direct registration
- ✅ Easier to read - More intuitive API
- ✅ Same functionality - All features preserved
🤝 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 ✨
Made with contrib.rocks