Loader<T> class
abstract
Utility base class for a service that pre-loads state to be consumed by another service.
This is useful when a service needs some initial data may be injected from an external source, such as the return value from a create call, into a state management system such as Riverpod.
- Inheritance
-
- Object
- StatefulService<
T?> - Loader
Constructors
-
Loader.new({required FutureOr<
T?> load(), StatefulServiceCache<T?> ? cache, bool verboseLogging = false, bool autoInitialize = false})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
initComplete
↔ Future<
T?> -
A Future that completes when the service has finished initializing. It will contain the state's first emitted
state.
latefinalinherited
- isClosed → bool
-
Returns true if this service has been closed. If this returns true, all calls to update the service's state will
fail.
no setterinherited
- isInitializing → bool
-
no setterinherited
- isUpdating → bool
-
Returns true if this service is currently processing an update call.
no setterinherited
- name → String
-
The provided name of this service, or the runtime type if none was provided.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ ServiceState<
T?> -
The service's current state.
no setterinherited
-
states
→ Stream<
ServiceState< T?> > -
This stream emits the service's state whenever it changes, it will never emit errors.
no setterinherited
-
values
→ Stream<
T?> -
This stream emits the service's state whenever it changes, it will never emit errors.
no setterinherited
- verboseLogging → bool
-
finalinherited
Methods
-
clear(
) → Future< void> -
clearCache(
) → Future< void> -
Clears this service's state cache. Note that this will not affect the current state of the service.
inherited
-
close(
) → Future< void> -
Closes the service. Any in-flight update operations will be discarded and further calls to update the service
state will result in errors.
inherited
-
initialize(
) → Future< void> -
inject(
T state, [bool force = true]) → Future< void> -
listen(
void onData(ServiceState< T?> value)) → StreamSubscription<ServiceState< T?> > -
Listens to the state stream and calls
onData
whenever a new state is emitted.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → Future< void> -
set(
T? value, {bool ignoreConcurrentUpdates = false}) → Future< void> -
Sets the service's state to the provided value directly, without needing changing the service into an intermediate
loading state.
inherited
-
streamUpdates(
Stream< T?> updates(T? state, T? setSavePoint(T?)), {bool ignoreConcurrentUpdates = false}) → Future<void> -
Performs a series of updates of service's state with the values emitted from the stream returned by
updates
. The service state will be locked (no other updates can take place) until the stream completes. update receives two arguments; the service's current state, and a function to call to save the current state as a savepoint.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
update(
FutureOr< T?> update(T? state), {bool ignoreConcurrentUpdates = false}) → Future<void> -
Makes a single update to this service's state with the value returned from
update
.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited