go_router_modular 5.0.1 copy "go_router_modular: ^5.0.1" to clipboard
go_router_modular: ^5.0.1 copied to clipboard

Modular Routing and Dependency Injection for Flutter with GoRouter. Features event-driven architecture for seamless module communication and micro-frontend support.

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


31
likes
150
points
767
downloads

Publisher

unverified uploader

Weekly Downloads

Modular Routing and Dependency Injection for Flutter with GoRouter. Features event-driven architecture for seamless module communication and micro-frontend support.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

event_bus, flutter, go_router, go_transitions

More

Packages that depend on go_router_modular