disco 1.0.0+1 copy "disco: ^1.0.0+1" to clipboard
disco: ^1.0.0+1 copied to clipboard

A Flutter library bringing a new concept of scoped providers for dependency injection, which are independent of any specific state management solution.

License: MIT Coverage GitHub issues GitHub pull-requests pub.dev Version (including pre-releases) GitHub stars

Disco #

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 <<<

Features #

  • 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.

Usage #

  1. Create a provider

    final modelProvider = Provider((context) => Model());
    
    copied to clipboard
  2. Scope/provide the provider

    ProviderScope(
      providers: [modelProvider],
      child: MyWidget(),
    )
    
    copied to clipboard
  3. Inject the provider (within the above ProviderScope's subtree)

    final model = modelProvider.of(context);
    
    copied to clipboard

Examples #

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.

Additional information #

This library can be used in combination with many existing packages.

State management #

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 solutions

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 version 2.0.0-dev.2 will be replaced with the ones present in disco),
  • ValueNotifier/ChangeNotifier (from Flutter)
  • bloc (NB: the usage of BlocProvider should be replaced with the providers present in this library).

Our repository includes one example with solidart and one with bloc.

Incompatible solutions

State management solution entirely leveraging global state, such as riverpod, are not compatible with this library.

Contributions #

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.

12
likes
160
points
143
downloads

Publisher

verified publishermariuti.com

Weekly Downloads

2024.08.05 - 2025.02.17

A Flutter library bringing a new concept of scoped providers for dependency injection, which are independent of any specific state management solution.

Homepage
Repository (GitHub)

Topics

#dependency-injection #scope #provider

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on disco