AsyncValue<T> class sealed Async

The state of an asynchronous operation exposed as a synchronous value.

Pattern-match the four cases with a switch:

switch (results.value) {
  AsyncIdle() => const SearchPrompt(),
  AsyncLoading(:final previous?) => ListView(previous),
  AsyncLoading() => const Spinner(),
  AsyncData(:final value) => ListView(value),
  AsyncError(:final error) => ErrorView(error),
}

AsyncIdle is the state before any operation starts. AsyncLoading and AsyncError carry the previous data through reloads, so UIs can keep showing the old value instead of flashing a spinner.

See also:

  • AsyncSignal, which publishes these states as an operation runs.
Implementers

Properties

hashCode → int
The hash code for this object.
no setterinherited
isLoading → bool
Whether the operation is currently in flight.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
valueOrNull → T?
The most recent usable data: the current value when loaded, or the previous one carried through loading and error states.
no setter

Methods

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

Operators

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