ZenQuery<T> class

A reactive query that manages async data fetching with caching

Example:

final userQuery = ZenQuery<User>(
  queryKey: 'user:123',
  fetcher: () => api.getUser(123),
  config: ZenQueryConfig(
    staleTime: Duration(minutes: 5),
    retryCount: 3,
  ),
);

// In widget
ZenQueryBuilder<User>(
  query: userQuery,
  builder: (context, data) => Text(data.name),
);
Inheritance
Implementers
Available extensions

Constructors

ZenQuery({required Object queryKey, required Future<T> fetcher(), ZenQueryConfig? config, T? initialData, ZenScope? scope, bool autoDispose = true, bool registerInCache = true})

Properties

activeWatcherCount int
Get count of active watchers (useful for debugging)
no setterinherited
autoDispose bool
Whether to automatically dispose when scope disposes
final
config ZenQueryConfig
Configuration for this query
final
createdAt DateTime
no setterinherited
data Rx<T?>
Current data (null if not loaded yet)
final
error Rx<Object?>
Current error (null if no error)
final
fetcher Future<T> Function()
Function that fetches the data
final
hasData bool
Whether the query has data
no setter
hasError bool
Whether the query has an error
no setter
hashCode int
The hash code for this object.
no setterinherited
initialData → T?
Optional initial data
final
isDisposed bool
Whether this query has been disposed
no setteroverride
isInitialized bool
no setterinherited
isLoading RxBool
Whether the query is currently loading
no setter
isReady bool
no setterinherited
isRefetching bool
Whether the query is currently refetching (loading while having data)
no setter
isStale bool
Whether data is stale and needs refetching
no setter
queryKey String
Unique key for this query (used for caching and deduplication)
final
reactiveObjectCount int
Get count of tracked reactive objects for debugging
no setterinherited
reactiveStats Map<String, int>
Get stats about reactive objects
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scope ZenScope?
Optional scope - if provided, query will be tied to this scope
final
status Rx<ZenQueryStatus>
Current status of the query
final

Methods

addDisposer(void disposer()) → void
Add a disposer function that will be called when the controller is disposed
inherited
addUpdateListener(String updateId, VoidCallback listener) → void
Register a listener for a specific update ID
inherited
autoDispose<T>(ValueNotifier<T> obs, bool disposeCondition(T), void callback(T)) ZenWorkerHandle

Available on ZenController, provided by the ZenControllerAdvancedExtension extension

Worker that auto-disposes when a condition is met
condition<T>(ValueNotifier<T> obs, bool condition(T), void callback(T)) ZenWorkerHandle
inherited
createEffect<T>({required String name}) ZenEffect<T>
Create an effect that will be auto-disposed with this controller
inherited
createWorkerGroup() ZenWorkerGroup
Create a managed worker group
inherited
createWorkers(List<ZenWorkerHandle Function()> creators) List<ZenWorkerHandle>

Available on ZenController, provided by the ZenControllerWorkerExtension extension

Create multiple workers in one call
debounce<T>(ValueNotifier<T> obs, void callback(T), Duration duration) ZenWorkerHandle
inherited
didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
inherited
didChangeAppLifecycleState(AppLifecycleState state) → void
Override from WidgetsBindingObserver to handle app lifecycle
inherited
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
inherited
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
inherited
didChangePlatformBrightness() → void
Called when the platform brightness changes.
inherited
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
inherited
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
inherited
didHaveMemoryPressure() → void
Called when the system is running low on memory.
inherited
didPopRoute() Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
inherited
didPushRoute(String route) Future<bool>
Called when the host tells the application to push a new route onto the navigator.
inherited
didPushRouteInformation(RouteInformation routeInformation) Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
inherited
didRequestAppExit() Future<AppExitResponse>
Called when a request is received from the system to exit the application.
inherited
dispose() → void
Dispose the controller and clean up ALL resources - PREVENTS MEMORY LEAKS
inherited
disposeWorkers(List<ZenWorkerHandle> workers) → void

Available on ZenController, provided by the ZenControllerWorkerExtension extension

Dispose specific workers
ever<T>(ValueNotifier<T> obs, void callback(T)) ZenWorkerHandle
Type-safe convenience worker methods
inherited
fetch({bool force = false}) Future<T>
Fetch or refetch data
getResourceStats() Map<String, dynamic>
Get comprehensive resource usage statistics
inherited
getWorkerStats() Map<String, dynamic>
Get worker statistics for debugging/monitoring
inherited
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
inherited
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
inherited
handleStartBackGesture(PredictiveBackEvent backEvent) bool
Called at the start of a predictive back gesture.
inherited
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
inherited
interval<T>(ValueNotifier<T> obs, void callback(T), Duration duration) ZenWorkerHandle
inherited
invalidate() → void
Invalidate query (mark as stale)
limited<T>(ValueNotifier<T> obs, void callback(T), int maxExecutions) ZenWorkerHandle

Available on ZenController, provided by the ZenControllerAdvancedExtension extension

Worker that executes a limited number of times
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
obs<T>(T initialValue) Rx<T>
Create and auto-track a reactive variable - PREVENTS MEMORY LEAKS
inherited
obsList<T>([List<T>? initialValue]) RxList<T>
Create and auto-track a reactive list - PREVENTS MEMORY LEAKS
inherited
obsMap<K, V>([Map<K, V>? initialValue]) RxMap<K, V>
Create and auto-track a reactive map - PREVENTS MEMORY LEAKS
inherited
obsSet<T>([Set<T>? initialValue]) RxSet<T>
Create and auto-track a reactive set - PREVENTS MEMORY LEAKS
inherited
once<T>(ValueNotifier<T> obs, void callback(T)) ZenWorkerHandle
inherited
onClose() → void
User-defined cleanup hook - called before internal disposal
override
onDetached() → void
Called when the app is detached
inherited
onHidden() → void
Called when the app is hidden
inherited
onInactive() → void
Called when the app is inactive
inherited
onInit() → void
inherited
onPause() → void
Called when the app is paused (goes to background)
inherited
onReady() → void
inherited
onResume() → void
Called when the app is resumed (comes back to foreground)
inherited
pauseAllWorkers() → void
Pause all workers managed by this controller
inherited
pauseSpecificWorkers(List<ZenWorkerHandle> workers) → void

Available on ZenController, provided by the ZenControllerWorkerExtension extension

Pause specific workers
pauseWorkers() → void
Pause workers - convenience method for UI callbacks (no parameters)
inherited
refetch() Future<T>
Refetch data (force refresh)
removeUpdateListener(String updateId, VoidCallback listener) → void
Remove a listener for a specific update ID
inherited
reset() → void
Reset query to idle state
resumeAllWorkers() → void
Resume all workers managed by this controller
inherited
resumeSpecificWorkers(List<ZenWorkerHandle> workers) → void

Available on ZenController, provided by the ZenControllerWorkerExtension extension

Resume specific workers
resumeWorkers() → void
Resume workers - convenience method for UI callbacks (no parameters)
inherited
select<R>(R selector(T data)) ZenQuery<R>
Creates a derived query that selects a subset of data.
setData(T newData) → void
Manually set data (for optimistic updates)
startObservingAppLifecycle() → void
Start observing app lifecycle events
inherited
stopObservingAppLifecycle() → void
Stop observing app lifecycle events
inherited
throttle<T>(ValueNotifier<T> obs, void callback(T), Duration duration) ZenWorkerHandle
inherited
toString() String
A string representation of this object.
override
trackReactive(Rx reactive) → void
Manually track a reactive object (for external reactive objects)
inherited
update([List<String>? updateIds]) → void
Optimized update method that can notify specific listeners or all listeners
inherited
watch<T>(ValueNotifier<T> observable, void callback(T), {WorkerType type = WorkerType.ever, Duration? duration, bool condition(T)?}) ZenWorkerHandle
Create workers that auto-dispose with controller
inherited

Operators

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