flutter_value_state
library
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. If null
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 parameter currentState
is not null
(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
and mapError
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.
If errorAsState
is true
and action
raise an exception then an
ErrorState is emitted. if false
, 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)
-
-
OnValueStateDefault<T>
= Widget Function(BuildContext context, BaseState<T> state)
-
-
OnValueStateError<T>
= Widget Function(BuildContext context, ErrorState<T> state)
-
-
OnValueStateNoValue<T>
= Widget Function(BuildContext context, NoValueState<T> state)
-
-
OnValueStateWaiting<T>
= Widget Function(BuildContext context, WaitingState<T> state)
-
-
OnValueStateWithValue<T>
= Widget Function(BuildContext context, WithValueState<T> state, Widget? error)
-
-
OnValueStateWrapper<T>
= Widget Function(BuildContext context, BaseState<T> state, Widget child)
-
-
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()
-