ZipRepository<Data> class
Creates a ZipRepository that combines multiple Repositorys into one. It takes a list of Repositorys and a zipper function. The zipper function takes a list of streams and returns a single stream. The zipper function is called every time one of the Repositorys emits a new value.
- Inheritance
-
- Object
- Repository<
Data> - CustomZipRepository<
Data> - ZipRepository
Constructors
-
ZipRepository({required List<
Repository> repositories, required Data zipper(List streams), Duration? autoRefreshInterval, String? name, bool resolveOnCreate = true}) -
Creates a ZipRepository that combines multiple Repositorys into one.
It takes a list of Repositorys and a
zipper
function. Thezipper
function takes a list of streams and returns a single stream. Thezipper
function is called every time one of the Repositorys emits a new value.
Properties
- autoRefreshInterval → Duration?
-
The interval at which the repository will refresh itself.
If null, the repository will not refresh itself.
If not null, the repository will refresh itself
every autoRefreshInterval.
finalinherited
-
currentState
→ RepositoryState<
Data> -
Returns the current state of the repository.
no setterinherited
- currentValue → Data?
-
Getter for the last value of the stream.
Returns null if the stream is empty.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
hydratationFiber
→ RepositoryFiber<
Data?> -
Fiber used to hydrate the repository.
finalinherited
- key → String
-
The key used to save the data in the cache.
This key must be unique.
If you have multiple repositories with the same key, the cache will be
overwritten.
no setterinherited
- name → String
-
Repository name used in logs and debugging.
no setteroverride
-
refreshFiber
→ RepositoryFiber<
Data> -
The
Fiber
is used to avoid multiple refreshes at the same time.finalinherited -
repositories
→ List<
Repository> -
The list of
Repository
s to combine. The zipper function will be called every time one of theRepository
s emits a new value.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
RepositoryState< Data> > -
The stream of the repository.
This stream will emit the data every time it changes.
The data will be cached locally.
The data will be refreshed every autoRefreshInterval.
The data will be refreshed when refresh is called.
latefinalinherited
- tag → String?
-
The tag used to differ cache from same key repositories. It's commonly
used to build the
key
property.no setterinherited - timer ↔ Timer?
-
Internal timer used to refresh the repository.
getter/setter pairinherited
Methods
-
clear(
) → Future< void> -
Clears the cache and emits an empty state to the repository stream.
inherited
-
clearCache(
) → Future< void> -
Clears the cache.
inherited
-
currentValueOrResolve(
) → Future< Data> -
Get the current data of the repository
if it's already resolved, otherwise resolve it.
This method will not refresh the repository if it's already resolved.
inherited
-
dispose(
) → void -
Disposes the repository. You should call this method when you're done
using the repository.
This method will cancel the timer and close the stream.
You should not use the repository after calling this method.
inherited
-
emit(
{required Data data, RepositoryDatasource datasource = RepositoryDatasource.local}) → Future< void> -
Emits a new data to the repository.
inherited
-
fromJson(
String json) → Data -
Transforms the raw data from the remote source to the data that will be
used in the stream.
inherited
-
hydrate(
{bool refreshAfter = true}) → Future< Data?> -
Gets the data from the cache, if it exists, and emits it to the stream.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → Future< Data> -
Refreshes the repository from remote datasource.
inherited
-
resolve(
) → Future< String> -
Gets the data from the remote source and returns the raw data.
The returned string will be saved in the cache and decoded using
fromJson.
inherited
-
shouldRetry(
Exception exception) → FutureOr< bool> -
Used to decide if the repository should retry after an error.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
track(
) → void -
Method used to add this repository to the pool.
It's useful for debugging.
inherited
-
update(
Data resolver(Data? data)) → Future< void> -
Updates the current data and refresh the repository.
The
resolver
function takes the current data and returns the new data. The new data will be added to the stream and the repository will be refreshed. This method is useful if you want to use Optimistic UI. You can update the data to the repository and refresh in a row.inherited -
zipper(
List values) → Data -
This function is called on resolve to get the streams to combine.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited