🧩 force_inject_provider
A plugin that integrates the ForceInject DI container with the popular Provider package in Flutter.
🛠️ Easily create scoped dependency injection and reactive
ChangeNotifierViewModels.
✨ Features
- ✔️
ProviderScopeto manage lifecycle-aware DI scopes - ✔️
ProviderNotifierBuilder<T>to inject and listen toChangeNotifiers - ✔️ Automatically disposes ViewModels
- ✔️ Clean integration with
force_inject
🚀 Getting Started
1. Define your services:
final services = ServiceCollection();
services.addScoped<CounterViewModel, CounterViewModel>();
ServiceProvider.registerConstructor<CounterViewModel>(
() => CounterViewModel(),
[],
);
final provider = services.buildServiceProvider();
2. Wrap your app or page in a ProviderScope:
return ProviderScope(
create: () => provider.createScope(),
child: MyApp(),
);
3. Use ProviderNotifierBuilder<T> to inject your ViewModel:
ProviderNotifierBuilder<CounterViewModel>(
builder: (context, viewModel, _) => Text('${viewModel.count}'),
)
📦 Example
See example/minimal_provider_di for a full working Flutter app.
📜 License
MIT — Free to use, modify, and distribute.