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<
Returns true if state has an error.T> , provided by the QoraStateExtensions extensionno 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<
Returns true if this is a first-time loading (no previous data).T> , provided by the QoraStateExtensions extensionno 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<
Returns true if this is a refresh (loading with previous data).T> , provided by the QoraStateExtensions extensionno 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<
Converts state to a simple status enum.T> , provided by the QoraStateExtensions extensionno setter - successDataOrNull → T?
-
Available on QoraState<
Returns data if Success, null otherwise (ignores previousData).T> , provided by the QoraStateExtensions extensionno setter - updatedAt → DateTime?
-
Available on QoraState<
Gets the timestamp when data was last updated.T> , provided by the QoraStateExtensions extensionno setter
Methods
-
combine<
T2, R> (QoraState< T2> other, R combiner(T data1, T2 data2)) → QoraState<R> -
Available on QoraState<
Combines this state with another state using a combiner function.T> , provided by the QoraStateExtensions extension -
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<
Folds the state into a single value of type R.T> , provided by the QoraStateExtensions extension -
isStale(
Duration threshold) → bool -
Available on QoraState<
Checks if data is stale based on a threshold.T> , provided by the QoraStateExtensions extension -
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<
Maps the data type on Success, preserving non-data fields.T> , provided by the QoraStateExtensions extension -
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<
Returns the data if available, or throws an error.T> , provided by the QoraStateExtensions extension -
toJson(
Map< String, dynamic> dataToJson(T data)) → Map<String, dynamic> -
Available on QoraState<
Serializes this state to JSON.T> , provided by the QoraStateSerializationX extension -
toJsonString(
Map< String, dynamic> dataToJson(T data)) → String -
Available on QoraState<
Serializes this state to a JSON string.T> , provided by the QoraStateSerializationX extension -
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