QueryState<T> class
Represents the current state of a query.
A QueryState contains all information about an async operation: the current data, any error that occurred, and the current status.
Use the computed properties (isLoading, hasData, hasError) to easily check the query state in your UI.
Example:
builder: (context, state) {
if (state.isLoading) return CircularProgressIndicator();
if (state.hasError) return Text('Error: ${state.error}');
if (state.hasData) return Text('Data: ${state.data}');
return SizedBox();
}
- Annotations
Constructors
- QueryState({required QueryStatus status, T? data, bool hasValue = false, Object? error, StackTrace? stackTrace, bool isFetching = false, DateTime? dataUpdatedAt, bool isStale = false})
-
Creates a query state with explicit values.
const
- QueryState.error(Object error, [StackTrace? stackTrace])
-
Creates an error state with
errorand optionalstackTrace.factory - QueryState.idle()
-
Creates an idle state (query not started yet).
factory
- QueryState.loading({T? data, bool isFetching = false, bool isStale = false})
-
Creates a loading state.
factory
- QueryState.success(T data, {DateTime? dataUpdatedAt, bool isFetching = false, bool isStale = false, bool hasValue = true})
-
Creates a success state with
data.factory
Properties
- data → T?
-
The data returned by the async operation, or null if not yet loaded.
final
- dataUpdatedAt → DateTime?
-
When the data was last updated.
final
- error → Object?
-
The error that occurred during the async operation, or null if no error.
final
- hasData → bool
-
Whether data is available.
no setter
- hasError → bool
-
Whether an error has occurred.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasValue → bool
-
Whether the query has produced a value (even if the value is null).
final
- isFetching → bool
-
Whether a background refetch is in progress.
final
- isIdle → bool
-
Whether the query is in idle state (not started).
no setter
- isLoading → bool
-
Whether the query is currently loading.
no setter
- isStale → bool
-
Whether the data is stale (determined by cache).
final
- isSuccess → bool
-
Whether the query completed successfully.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace?
-
The stack trace associated with the error, if any.
final
- status → QueryStatus
-
The current status of the query.
final
Methods
-
copyWith(
{T? data, bool? hasValue, Object? error, StackTrace? stackTrace, QueryStatus? status, bool? isFetching, DateTime? dataUpdatedAt, bool? isStale}) → QueryState< T> - Returns a copy of this state with selected fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override