Query<T> class

Query is will fetch and cache the response of the queryFn.

The queryFn must be asynchronous and the result is cached.

Query takes a key to identify and store it in the global cache. The key can be any serializable data. The key is converted to a String using jsonEncode.

Each Query can override the global defaults for refetchDuration, cacheDuration, see CachedQuery.config for more info.

Use forceRefetch to force the query to be run again regardless of whether the query is stale or not.

To run side effects if the query function is successful or not use onSuccess and onError.

Inheritance

Constructors

Query({required Object key, required Future<T> queryFn(), OnQueryErrorCallback<T>? onError, OnQuerySuccessCallback<T>? onSuccess, T? initialData, QueryConfig? config})
Query is will fetch and cache the response of the queryFn.
factory

Properties

config QueryConfig
The config for this specific query.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
hasListener bool
Weather the query stream has any listeners.
no setterinherited
key String
The key used to store and access the query. Encoded using jsonEncode.
finalinherited
result Future<QueryState<T>>
Get the result of calling the queryFn.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stale bool
Whether the current query is marked as stale and therefore requires a refetch.
no setterinherited
state QueryState<T>
The current state of the query.
no setterinherited
stream Stream<QueryState<T>>
Stream the state of the query.
no setterinherited
unencodedKey Object
The original key.
finalinherited

Methods

close() Future<void>
Closes the stream and therefore starts the delete timer.
inherited
deleteQuery({bool deleteStorage = false}) → void
Delete the query and query key from cache
inherited
invalidateQuery() → void
Mark query as stale.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refetch() Future<QueryState<T>>
Refetch the query immediately.
override
toString() String
A string representation of this object.
inherited
update(UpdateFunc<T> updateFn) → void
Update the current Query data.
override

Operators

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