flutter_injections 1.1.1 flutter_injections: ^1.1.1 copied to clipboard
Elevate your project's dependency management with this versatile Flutter package. Say goodbye to the limitations of context and unlock the ability to seamlessly create dependencies for modules. Simpli [...]
Flutter Injections #
This package helps you to manage any dependencies in your project without need to use context and makes possible to create dependencies for modules. The objective is help any developer to manage dependencies with a easy to use API.
Learn more #
More details on the documentation.
Why Flutter Injections? #
- Fast and Efficient
Flutter Injections use search-tree to get the dependencies, this improve the speed to get them, and use less CPU to search for specific objects.
- Module Injections
Create module injections that have all dependencies needed on your widgets. I.E
HomeInjections
have all dependencies needed onHomePage
. - Easy to use
The focus is to keep it simple to handle dependencies on large scale applications.
- Auto dispose
Objects are auto disposed when FlutterInjection is removed from the Widget Tree.
- Simple dispose
With Flutter Injections you can dispose a specific object using
__dispose<T>
method.
How to use #
It`s simple, just three steps:
-
Add the FlutterInjections to pubspec.yaml file
flutter_injections: ^any # or current version
-
Create your FlutterInjections anywhere you to need.
class YourPageInjections extends StatelessWidget { const YourPageInjections({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return FlutterInjectionsWidget(injections: [ Inject<YourRepository>((i) => YourRepository(client: i.find<Dio>())), Inject<YourController>( (i) => YourController(repository: i.find<YourRepository>())), ], builder:(_) => const YourPage()); } }
Or you can use extends the new widget FlutterModule to add your dependencies
class YourModule extends FlutterModule { const YourModule({Key? key}) : super(key: key); @override Widget get child => const YourPage(); @override List<Inject<Object>> get injections => [ Inject<YourRepository>((i) => YourRepository(client: i.find<Dio>())), Inject<YourController>( (i) => YourController(repository: i.find<YourRepository>())), ]; }
-
And finally, use it to get the dependencies:
final controller = FlutterInjections.get<YourController>();
- Direct and simple! Good job and have fun!
Contribuitors #
Be a contribuitor too!
Made with contrib.rocks.