Result<T> class sealed

Result is the base class of an enumerable set of subtypes that represent the different states involved in fetching data for a ResultNotifier.

A result can be in one of the following states:

  • Loading: Represents a loading/reloading state, along with the previous data, if any.
  • Data: The result contains some concrete data.
  • Error: Represents an error, along with the previous data, if any.

There is also a special Initial state, which is used as a default state when no other state has been set. This state inherits from Loading and is handled as such in most cases.

Result provides a number of methods for checking (properties of) the current state as well as converting between the different states. It also provides a number of methods for performing actions based on the current state, for instance when. Example:

result.when(
  loading: (data) => const CircularProgressIndicator(),
  error: (error, stackTrace, data) => Text('Error: $error'),
  data: (data) => Text(data),
),
Implementers
Annotations

Properties

data → T?
The last data, if any.
no setter
error Object?
The last error, if any.
no setter
hasData bool
Checks if the result contains data, regardless of the result type. Note that this is different from isData.
no setter
hashCode int
The hash code for this object.
no setteroverride
isCancelled bool
Checks if the current state is Error and the error is a CancelledException.
no setter
isData bool
Checks if the result is Data. Note that this is different from if this notifier currently contains data (i.e. hasData).
no setter
isError bool
Checks if the current state is Error.
no setter
isInitial bool
Checks if the the result is the Initial loading state.
no setter
isLoading bool
Checks if the the result is Loading. Note that the initial state (Initial) is also interpreted as a loading state.
no setter
isLoadingData bool
Checks if the data is currently being loaded, i.e. the current state is Loading but not Initial.
no setter
isReloading bool
Checks if data is currently being reloaded, i.e. the current state is Loading and hasData.
no setter
lastUpdate DateTime
The last time the result was updated.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

copyWith({T? data, DateTime? lastUpdate}) Result<T>
Creates a copy of this result with the provided values.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toCancelled({T? data, DateTime? lastUpdate}) Result<T>
Attempts to convert the result to cancellation Error.
toData({T? data, T orElse()?, DateTime? lastUpdate}) Result<T>
Attempts to convert the result to Data.
toError({Object? error, StackTrace? stackTrace, T? data, DateTime? lastUpdate}) Result<T>
Attempts to convert the result to Error.
toFresh() Result<T>
Creates a fresh copy of this result, meaning lastUpdate will be set to DateTime.now().
toInitial({T? data, DateTime? lastUpdate}) Result<T>
Attempts to convert the result to the Initial loading state.
toLoading({T? data, DateTime? lastUpdate}) Result<T>
Attempts to convert the result to Loading.
toStale() Result<T>
Creates a stale copy of this result, meaning lastUpdate will be set to zero ms from "epoch".
toString() String
A string representation of this object.
inherited

Operators

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