value_state library
Classes
-
BaseState<
T> - Base class for handling value states.
-
ErrorState<
T> - State for error (may be linked with a ValueState or not)
-
ErrorWithoutPreviousValue<
T> - An error with a ValueState as previous state
-
ErrorWithPreviousValue<
T> - An error with a ValueState as previous state
-
InitState<
T> - Initial state before any processing. If all has been intialized and the action to get the value is started, then emit a WaitingState
-
NoValueState<
T> - State with no value (support null safety).
-
PendingState<
T> - Initial state before any processing. If all has been intialized and the action to get the value is started, then emit a WaitingState
-
ReadyState<
T> - Abstract class for all states that a value, no value or error has been received.
-
StateVisitor<
R, T> - Visitor base class to enhance states capabilities
-
ValueState<
T> - State that provide the value.
-
WaitingState<
T> - State for waiting value and there was no ReadyState before. Useful to handle waiting page before first value is displayed or when a user is disconnected.
-
WithValueState<
T> - Abstraction of a state with a value ValueState or ErrorState
Extensions
-
FutureValueStateExtension
on Future<
T?> -
ObjectWithValueExtensions
on BaseState<
T> - OrExtensions on R?
- ToReadyStateExtensions on T?
-
ValueStatePerformExtensions
on BaseState<
T>
Functions
-
mapState<
T, F> (T? map(F from), BaseState< F> fromState, {BaseState<T> ? currentState, WaitingMapperType<T> ? mapInit, WaitingMapperType<T> ? mapPending, RefreshingyMapperType<T> ? mapNoValue, ErrorMapperType<T, F> ? mapError}) → BaseState<T> -
Helper to map from a state to other state. Useful to map "default" states
from original stream.
The
map
argument contains a function that map the origin event from the stream to the value. Ifnull
is returned, then a NoValueState is emitted. Else a ValueState is emitted with the value returned inside.fromState
is the origin state to map. If the optional parametercurrentState
is notnull
(default value), then the cubit emit the current state refreshing if original stream emit a refreshing state. Else, the refreshing is mapped from original stream.mapInit
,mapPending
,mapNoValue
andmapError
override the default behavior of the mapper. -
performOnState<
T, R> ({required BaseState< T> state(), required PerfomOnStateEmitter<T> emitter, required PerfomOnStateAction<T, R> action, bool errorAsState = true}) → Future<R> -
Handle states (waiting, refreshing, error...) while an
action
is processed.state
must return the state updated. IferrorAsState
istrue
andaction
raise an exception then an ErrorState is emitted. iffalse
, nothing is emitted. The exception is always rethrown by performOnState to be handled by the caller.
Typedefs
-
ErrorMapperType<
T, F> = BaseState< T> ? Function(ErrorState<F> errorState) -
PerfomOnStateAction<
T, R> = FutureOr< R> Function(BaseState<T> state, PerfomOnStateEmitter<T> emitter) -
PerfomOnStateEmitter<
T> = FutureOr< void> Function(BaseState<T> state) -
RefreshingyMapperType<
T> = BaseState< T> ? Function(bool refreshing) -
WaitingMapperType<
T> = BaseState< T> ? Function()