A modern, convenient, simple and safe way to do scoped dependency injection in Flutter.
For learning how to use Disco, see its documentation: >>> https://disco.mariuti.com <<<
- Scoped dependency injection
- Service locator
- Testable
- Independent of state management solutions
- This library focuses on DI, so that state management solutions can focus on the reactivity.
-
Create a provider
final modelProvider = Provider((context) => Model());
-
Scope/provide the provider
ProviderScope( providers: [modelProvider], child: MyWidget(), )
-
Inject the provider (within the above
ProviderScope
's subtree)final model = modelProvider.of(context);
There are multiple examples on the repository:
- basic A basic example showing the basic usage of Disco.
- solidart An example showcasing the power of the
ProviderScope
widgets combined with solidart reactivity. - bloc An example showcasing how to provide a light/dark theme Cubit with Disco.
- auto_route An example showing how to share a provider between multiple pages without scoping the entire app.
- preferences An example showing how to provide async objects with Disco.
This library can be used in combination with many existing packages.
This package is not opinionated about reactivity: feel free to use your state management solution of choice (as long as it is compatible with the concepts of the library).
Compatible state management solutions are those whose signals/observables can be created locally and passed as arguments, such as
solidart
(NB: its providers up to version2.0.0-dev.2
will be replaced with the ones present indisco
),ValueNotifier
/ChangeNotifier
(from Flutter)bloc
(NB: the usage ofBlocProvider
should be replaced with the providers present in this library).
Our repository includes one example with solidart
and one with bloc
.
State management solution entirely leveraging global state, such as riverpod
, are not compatible with this library.
The purpose of this package is to simplify dependency injection for everyone. PRs are welcome, especially for documentation and more examples. Another goal of this library is to be simple. PRs introducing new features or breaking changes will have to be explained in detail.