RemoteState<T> class

A sealed class representing fetched data and the states it can be in.

If you find yourself continually using enums and classes to represent loaded data, or you have a habit of shuffling errors away to where they can be quietly ignored, consider using RemoteState. It makes it easier to represent the real state of a remote data fetch and handle it properly.

See also:

How to fix a bad user interface

Annotations
  • @freezed

Constructors

RemoteState.error([Object? error, StackTrace? stackTrace])
We asked, but something went wrong. Here's the error.
factory
RemoteState.initial()
We haven't asked for the data yet.
factory
RemoteState.loading()
We've asked, but haven't got an answer yet.
factory
RemoteState.success(T value)
Everything worked, and here's the data.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isError bool
State-checking predicate. Returns true if we've failed to load some data. Returns true only if RemoteState is RemoteState.error
getter/setter pair
isInitial bool
State-checking predicate. Returns true if we haven't asked for data yet. Returns true only if RemoteState is RemoteState.initial
getter/setter pair
isLoading bool
State-checking predicate. Returns true if we're loading. Returns true only if RemoteState is RemoteState.loading
getter/setter pair
isSuccess bool
State-checking predicate. Returns true if we've successfully loaded some data. Returns true only if RemoteState is RemoteState.success
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

map<TResult extends Object?>({required TResult initial(_Initial<T> value), required TResult loading(_Loading<T> value), required TResult success(_Success<T> value), required TResult error(_Error<T> value)}) → TResult
Achieves the same result as when without destructuring.
override
maybeMap<TResult extends Object?>({TResult initial(_Initial<T> value)?, TResult loading(_Loading<T> value)?, TResult success(_Success<T> value)?, TResult error(_Error<T> value)?, required TResult orElse()}) → TResult
Achieves the same result as maybeWhen without destructuring.
override
maybeWhen<TResult extends Object?>({TResult initial()?, TResult loading()?, TResult success(T value)?, TResult error(Object? error, StackTrace? stackTrace)?, required TResult orElse()}) → TResult
Defines logic based on the current state with a fallback for unhandled states.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<TResult extends Object?>({required TResult initial(), required TResult loading(), required TResult success(T value), required TResult error(Object? error, StackTrace? stackTrace)}) → TResult
Defines logic based on the current state.
override

Operators

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

Static Methods

guard<T>(Future<T> future()) Future<RemoteState<T>>
Convert a Future to RemoteState. Emits RemoteState.success if the future completes Emits RemoteState.error if future fails.