collection_providers: ^0.0.1+2 copied to clipboard
A group of pre-built providers the wrap the basic dart collections - list, set, map
A wrapper around Provider to add common dart collection providers for quick and easy use.
The package includes wrappers for
set. It allows you to use the providers as if they were native dart collections, with all available interface methods.
Exposing a value #
You can expose a value just like you normally would with
Provider or, if you want type safety, you can use the
CollectionProvider as a drop-in replacement to guarantee that the ChangeNotifier is for one of the Collection types in this library.
Reading a value #
Just like with
Provider, the easiest way to read a value is by using the extension methods on
context.watch<T>(), which makes the widget listen to changes on
context.read<T>(), which returns
Twithout listening to it
context.select<T, R>(R cb(T value)), which allows a widget to listen to only a small part of
Or to use the static method
Provider.of<T>(context), which will behave similarly to
You can also use Provider's
With typed collections,
T must include the type of the collection as well.
For example, if your provider is created using
CollectionProvider(create: (_) => ListChangeNotifier(['default', 'values'])) or
CollectionProvider(create: (_) => ListChangeNotifier<String>()) then you will need to use
context.watch<ListChangeNotifier<String>> as the proper template type to properly look up the provider.
If you do not specify a default collection, or a type, then it defaults to
dynamic and you can leave ignore the type declaration on the ChangeNotifier.
Additional Reading #
To read more about using
Providers, see its documentation here.