Provided
A Provided
references an independent state which can be manually updated over time.
A Provided
can be easily declared:
// Here we declare a Provided with an initial state of 0.final refCounter = Provided((_) => 0);
Sometimes a Provided
can have some dependencies which are only read when the state is created. For example a repository can have a dependency on an api client:
/// Use read to inject dependencies when creating your instances.final refRepository = Provided((read) { return Repository(apiClient: read(refApiClient));});
When you have a Provided
that has a meaning only when it is overriden, it can be useful to create it without an initial value:
final refCurrentItem = Provided<Item>.undefined();
There are two methods on the store object to modify the state of a Provided
:
// To write a new value independent of the previous one:store.write(refProvided, 10);
// To write a new value which depends of the previous one:store.update(refProvided, (x) => x + 1);