QoraState<T> class sealed

Represents the state of a query operation.

A query can be in one of four states:

  • Initial: Query hasn't started yet
  • Loading: Actively fetching data (with optional previous data)
  • Success: Data fetched successfully
  • Failure: Fetch failed (with optional previous data for graceful degradation)

Use pattern matching to handle all states exhaustively:

switch (state) {
  case Initial():
    return Text('Ready to load');
  case Loading(:final previousData):
    return previousData != null
      ? Stack(children: [DataView(previousData), Spinner()])
      : Spinner();
  case Success(:final data):
    return DataView(data);
  case Failure(:final error, :final previousData):
    return previousData != null
      ? Stack(children: [DataView(previousData), ErrorBanner()])
      : ErrorScreen(error);
}
Available extensions
Annotations

Properties

dataOrNull → T?
Extracts data from any state that has it, or returns null.
no setter
errorOrNull → Object?
Extracts error from Failure state, or returns null.
no setter
hasData → bool
Returns true if this state contains usable data.
no setter
hasError → bool

Available on QoraState<T>, provided by the QoraStateExtensions extension

Returns true if state has an error.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isError → bool
Returns true if in error state.
no setter
isFirstLoad → bool

Available on QoraState<T>, provided by the QoraStateExtensions extension

Returns true if this is a first-time loading (no previous data).
no setter
isInitial → bool
Returns true if initial (not started).
no setter
isLoading → bool
Returns true if actively loading.
no setter
isRefreshing → bool

Available on QoraState<T>, provided by the QoraStateExtensions extension

Returns true if this is a refresh (loading with previous data).
no setter
isSuccess → bool
Returns true if successful.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
status → QoraStatus

Available on QoraState<T>, provided by the QoraStateExtensions extension

Converts state to a simple status enum.
no setter
successDataOrNull → T?

Available on QoraState<T>, provided by the QoraStateExtensions extension

Returns data if Success, null otherwise (ignores previousData).
no setter
updatedAt → DateTime?

Available on QoraState<T>, provided by the QoraStateExtensions extension

Gets the timestamp when data was last updated.
no setter

Methods

combine<T2, R>(QoraState<T2> other, R combiner(T data1, T2 data2)) → QoraState<R>

Available on QoraState<T>, provided by the QoraStateExtensions extension

Combines this state with another state using a combiner function.
fold<R>({required R onInitial(), required R onLoading(T? previousData), required R onSuccess(T data, DateTime updatedAt), required R onError(Object error, StackTrace? stackTrace, T? previousData)}) → R

Available on QoraState<T>, provided by the QoraStateExtensions extension

Folds the state into a single value of type R.
isStale(Duration threshold) → bool

Available on QoraState<T>, provided by the QoraStateExtensions extension

Checks if data is stale based on a threshold.
map<R>(R transform(T data)) → QoraState<R>
Maps the data type while preserving state structure.
mapData<R>(R transform(T data)) → QoraState<R>

Available on QoraState<T>, provided by the QoraStateExtensions extension

Maps the data type on Success, preserving non-data fields.
maybeWhen<R>({required R orElse(), R onInitial()?, R onLoading(T? previousData)?, R onSuccess(T data, DateTime updatedAt)?, R onError(Object error, StackTrace? stackTrace, T? previousData)?}) → R
Maps the state to a value of type R based on callbacks.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requireData() → T

Available on QoraState<T>, provided by the QoraStateExtensions extension

Returns the data if available, or throws an error.
toJson(Map<String, dynamic> dataToJson(T data)) → Map<String, dynamic>

Available on QoraState<T>, provided by the QoraStateSerializationX extension

Serializes this state to JSON.
toJsonString(Map<String, dynamic> dataToJson(T data)) → String

Available on QoraState<T>, provided by the QoraStateSerializationX extension

Serializes this state to a JSON string.
toString() → String
A string representation of this object.
inherited
when({void onInitial()?, void onLoading(T? previousData)?, void onSuccess(T data, DateTime updatedAt)?, void onError(Object error, StackTrace? stackTrace, T? previousData)?}) → void
Executes a callback based on the current state.

Operators

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