AsyncValue<T> class sealed

The current state of a Future or Stream, accessible from a synchronous context.

One of three variants: AsyncData, AsyncError, or AsyncLoading.

Often, when a Future/Stream emits an error, or is swapped out and is put back into the loading state, you want access to the previous data. (Example: pull-to-refresh in UI and you want to show the current data.) Thus, a previousData is provided in the AsyncError and AsyncLoading states so you can access the previous data (if it exists).

Implementers
Available extensions
Annotations
  • @immutable

Constructors

AsyncValue.data(T data)
Shortcut for AsyncData.new.
const
factory
AsyncValue.error(Object error, StackTrace stackTrace, Option<T> previousData)
Shortcut for AsyncError.new.
const
factory
AsyncValue.loading(Option<T> previousData)
Shortcut for AsyncLoading.new.
const
factory

Properties

data Option<T>

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Returns any data contained within this AsyncValue, including previousData for the AsyncLoading and AsyncError cases.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dataOr(T defaultValue) → T

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Returns any data contained within this AsyncValue, including previousData for the AsyncLoading and AsyncError cases.
dataOrElse(T defaultFn()) → T

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Returns any data contained within this AsyncValue, including previousData for the AsyncLoading and AsyncError cases.
fillInPreviousData(Option<T> newPreviousData) AsyncValue<T>

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Fills in the AsyncLoading.previousData or AsyncError.previousData with newPreviousData if AsyncLoading.previousData or AsyncError.previousData are None. If AsyncLoading.previousData or AsyncError.previousData are Some, then newPreviousData will not be filled in.
map<R>(R mapper(T)) AsyncValue<R>

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Maps an AsyncValue
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
unwrapOr(T defaultValue) → T

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Returns AsyncData.data if this is an AsyncData. Otherwise, returns defaultValue.
unwrapOrElse(T defaultFn()) → T

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Returns AsyncData.data if this is an AsyncData. Otherwise, calls and returns the result of defaultFn.
withoutPreviousData() AsyncValue<T>

Available on AsyncValue<T>, provided by the AsyncValueConvenience extension

Fills in the AsyncLoading.previousData or AsyncError.previousData with None so that there is no previous data whatsoever in the AsyncValue. This also means that data will only be Some when this is AsyncData, which can be useful when you want to erase any non-relevant previous data.

Operators

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

Static Methods

guard<T>(Future<T> fn()) Future<AsyncValue<T>>
Transforms a fallible Future into a safe-to-read AsyncValue. Useful when mutating state.