QueryScope<Q extends Accessor> class

A scope in which selections are recorded, one per widget build.

The scope owns the selection tree recorded during its last run, so it can be re-fetched wholesale (refetch) and so the client knows which scopes to notify when data lands.

Implemented types

Constructors

QueryScope(SlingClient<Q> client, {required void onChanged(), FlushScheduler scheduler = microtaskScheduler, String? debugLabel, FetchPolicy? fetchPolicy, Duration? maxAge})

Properties

cache → Cache
no setteroverride
client → SlingClient<Q>
final
debugLabel → String
Names this scope in WaterfallWarnings.
final
deps → Set<String>
Dependency keys read during the last run (and by accessors created in it afterwards). A scope rebuilds when a write touches any of them.
no setteroverride
error → Object?
The last error from a fetch this scope took part in.
no setter
fetchPolicy → FetchPolicy
How this scope combines cache and network (see FetchPolicy). Defaults to SlingClient.fetchPolicy.
final
hashCode → int
The hash code for this object.
no setterinherited
hasMissingData → bool
True if the last run touched data that is not in the cache.
no setter
isLoading → bool
True while a fetch containing selections from this scope is pending.
no setter
isStale → bool
True when the last run rendered cached data older than maxAge (or never fetched from the server); a background refetch is in flight or blocked by a sticky error. Always false without a maxAge.
no setter
maxAge → Duration?
Stale-while-revalidate window. When set, a run whose data was last fetched from the server longer ago than this (or never: hydrated snapshots, optimistic writes) keeps rendering the cached values and refetches the whole selection in the background; isStale is true meanwhile. null (the default, from SlingClient.maxAge) means cached data never expires: only refetch gets fresh data.
final
onChanged → void Function()
Invoked when data relevant to this scope changed and it should re-run.
final
operation → String
query, mutation or subscription.
no setteroverride
root → Selection
Root of the selection tree recorded in the current scope.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scheduler → FlushScheduler
How this scope asks the client to flush (see FlushScheduler).
final
whenSettled → Future<void>
Completes when the fetch this scope is waiting on has landed (or failed).
no setter

Methods

dispose() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onMiss(Selection leaf) → void
Called when a field was read but is not in the cache. For object and list fields the node itself is reported (its children come as the skeleton accessors are read).
override
onWrite(CacheWrite write) → void
Called on manual writes (generated setters) so dependants can be re-rendered and, during a mutation's optimistic phase, so the write can be undone if the mutation fails.
override
refetch() → Future<void>
Re-fetches everything this scope selected during its last run.
revalidate() → Future<void>
Re-fetches like refetch, unless every field read in the last run is within maxAge, in which case nothing is sent and the future completes at once. Without a maxAge it is exactly refetch. The soft option for "refresh when this screen comes back into view".
row({required void onChanged()}) → RowScope
Creates a RowScope under this scope: accessors bound to it record their dependencies there, so a write only re-runs that row (onChanged) rather than this scope. Dispose it with the row.
run<T>(T body(Q root)) → T
Runs body with a fresh selection tree, returning its result.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

ownerOf(Recorder recorder) → QueryScope<Accessor>?
The query scope owning recorder (an accessor's recorder): itself, or the parent of a RowScope. null for other recorders (cache, mutation and subscription scopes).