AsyncState
is class commonly used with Future/Stream signals to represent the states the signal can be in.
AsyncSignal
AsyncState
is the default state if you want to create a AsyncSignal
directly:
AsyncState
AsyncState
is a sealed union made up of AsyncLoading
, AsyncData
and AsyncError
.
.future
Sometimes you need to await a signal value in a async function until a value is completed and in this case use the .future getter.
.isCompleted
Returns true if the future has completed with an error or value:
.hasValue
Returns true if a value has been set regardless of the state.
.hasError
Returns true if a error has been set regardless of the state.
.isRefreshing
Returns true if the state is refreshing with a loading flag, has a value or error and is not the loading state.
.isReloading
Returns true if the state is reloading with having a value or error, and is the loading state.
.requireValue
Force unwrap the value of the state and throw an error if it has an error or is null.
.value
Return the current value if exists.
.error
Return the current error if exists.
.stackTrace
Return the current stack trace if exists.
.map
If you want to handle the states of the signal map
will enforce all branching.
.maybeMap
If you want to handle some of the states of the signal maybeMap
will provide a default and optional overrides.
Pattern Matching
Instead of map
and maybeMap
it is also possible to use dart switch expressions to handle the branching.