DataDelegate<V> class

Delegates fetching and caching behavior of specified Data object.

If you provide toStorage or toMemory then you must also provide onClearCache.

If toStorage or toMemory throws then onClearCache is called.

Inheritance

Constructors

DataDelegate({required _FromNetwork<V> fromNetwork, _FromMemory<V>? fromMemory, _ToMemory<V>? toMemory, _FromStorage<V>? fromStorage, _ToStorage<V>? toStorage, _ClearCache? onClearCache})

Properties

fromMemory → _FromMemory<V>?
Load cached data from memory. This cannot be async.
final
fromNetwork → _FromNetwork<V>
HTTP request to obtain data from your API
final
fromStorage → _FromStorage<V>?
Load data from storage. This could be SQLite, shared_preferences etc.
final
hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Whether the bloc is closed.
no setterinherited
isLocked bool
Whether there already is ongoing network request. Only one request is allowed at the time.
getter/setter pair
lastUpdated DateTime?
DateTime of last fromNetwork call. This will be updated when fromNetwork call either succeeds or fails. You can use this value to decide if you need to refresh your data.
no setter
onClearCache → _ClearCache?
Define how to clear memory & storage cache.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state Data<V>
The current state.
no setterinherited
stream Stream<Data<V>>
The current stream of states.
no setterinherited
toMemory → _ToMemory<V>?
Save data into memory cache.
final
toStorage → _ToStorage<V>?
Persist data into storage.
final

Methods

addError(Object error, [StackTrace? stackTrace]) → void
Reports an error which triggers onError with an optional StackTrace.
inherited
clearCache() Future<void>
Clear cache using onClearCache.
close() Future<void>
Closes the instance. This method should be called when the instance is no longer needed. Once close is called, the instance can no longer be used.
inherited
emit(Data<V> state) → void
Updates the state to the provided state. emit does nothing if the state being emitted is equal to the current state.
inherited
fetch() Future<void>
Fetch data fromNetwork.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onChange(Change<Data<V>> change) → void
Called whenever a change occurs with the given change. A change occurs when a new state is emitted. onChange is called before the state of the cubit is updated. onChange is a great spot to add logging/analytics for a specific cubit.
inherited
onError(Object error, StackTrace stackTrace) → void
Called whenever an error occurs and notifies BlocObserver.onError.
override
reload({bool force = false}) Future<void>
Fetch data using fromNetwork again. Immediately returns is isLocked is true.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited