fluquery library

FluQuery - Powerful asynchronous state management for Flutter

Inspired by TanStack Query (React Query), FluQuery provides:

  • Automatic caching and cache invalidation
  • Background refetching
  • Window focus refetching
  • Polling/realtime queries
  • Parallel and dependent queries
  • Mutations with optimistic updates
  • Infinite/paginated queries
  • Offline support
  • Persistence to disk
  • And much more!

Classes

CacheTime
Configuration for how long unused query data stays in cache
CancellationToken
Token for cancelling in-flight requests
ConnectivityManager
Manages network connectivity state for automatic refetching
DefaultQueryOptions
Default query options factory
DevtoolsController
Controller that aggregates query/mutation/service data for devtools display.
DevtoolsStats
Aggregate statistics for devtools header
FluQueryDevtools
FluQuery Devtools - Visual debugging tool for inspecting queries and cache.
FluQueryLogger
Logger for FluQuery
HiveCePersister
Hive CE-based persister for production use.
InfiniteQuery<TData, TError, TPageParam>
Infinite query for paginated data
InfiniteQueryOptions<TData, TError, TPageParam>
Options for infinite queries
InfiniteQueryState<TData, TError, TPageParam>
State for infinite query pages
InMemoryPersister
In-memory persister for testing
JsonSerializer<TData>
Simple JSON serializer for data that's already JSON-compatible
ListMapSerializer
Serializer for List
Mutation<TData, TError, TVariables, TContext>
A Mutation manages the state and lifecycle of a mutation operation
MutationBuilder<TData, TError, TVariables>
Builder widget for mutations (alternative to hooks)
MutationBuilderState<TData, TError, TVariables>
State for MutationBuilder
MutationCache
Cache for storing and managing mutations
MutationCacheEvent
Event emitted by the mutation cache
MutationOptions<TData, TError, TVariables, TContext>
Options for configuring a mutation
MutationState<TData, TError, TVariables, TContext>
Immutable state of a mutation Uses Object? internally to avoid web runtime generic cast issues
PersistedQuery
A persisted query entry that can be serialized/deserialized
Persister
Abstract persister interface for storage backends
PersistOptions<TData>
Options for query persistence
PlaceholderData<T>
Placeholder data configuration
PlaceholderFromCache<T>
Placeholder from cache
PlaceholderValue<T>
Placeholder with a static value
Query<TData, TError>
A Query manages the state and lifecycle of a single piece of server data
QueryBuilder<TData, TError>
Builder widget for queries (alternative to hooks)
QueryCache
Cache for storing and managing queries
QueryCacheEvent
Event emitted by the query cache
QueryClient
The main client for managing queries and mutations.
QueryClientConfig
Configuration for QueryClient
QueryClientProvider
Provides a QueryClient to the widget tree
QueryConfig<TData, TError>
Configuration for a single query in useQueries
QueryDataSerializer<TData>
Serializer interface for converting data to/from persistable format
QueryFnContext
Context passed to query functions
QueryFocusManager
Manages app lifecycle and focus state for automatic refetching
QueryKeyUtils
Utilities for working with query keys
QueryObserver<TData, TError>
Observer for a query that manages subscriptions and state updates
QueryOptions<TData, TError>
Options for configuring a query
QueryResult<TData, TError>
Result returned by a query observer Uses Object? internally to avoid web runtime generic cast issues
QuerySnapshot
Snapshot of a query's state for devtools display
QueryState<TData, TError>
Immutable state of a query Uses Object? internally to avoid web runtime generic cast issues
ReactiveList<T>
A reactive list state with convenient mutation methods.
ReactiveMap<K, V>
A reactive map state with convenient mutation methods.
ReactiveState<T>
A reactive state container for services.
Retryer
Retryer for handling query retries - uses Object? to avoid web type issues
Service
Base class for all services in the application.
ServiceContainer
Container for managing service registration, resolution, and lifecycle.
ServiceKey
A strongly-typed key for identifying services in the container.
ServiceRef
Reference passed to services for accessing dependencies.
ServiceRegistration<T extends Service>
Registration info for a service.
SharedPrefsAdapter
Adapter interface for SharedPreferences
SharedPrefsPersister
SharedPreferences-based persister
StaleTime
Configuration for when data is considered stale
StatefulService<TState>
A service that maintains a single immutable state object.
UseInfiniteQueryResult<TData, TError, TPageParam>
Result type for useInfiniteQuery hook
UseMutationResult<TData, TError, TVariables, TContext>
Result type for useMutation hook
ViewModelProvider<T extends Service>
Provider for screen-scoped ViewModels (factory services).

Enums

DevtoolsPosition
Position for the devtools toggle button
FetchStatus
Fetch status enum
LogLevel
Log level for FluQuery
MutationCacheEventType
Event types for mutation cache
MutationStatus
Mutation status enum
NetworkMode
Network mode for queries
QueryCacheEventType
Event types for query cache
QueryStatus
Query status enum
QueryStatusFilter
Filter options for query list
RefetchType
Refetch behavior when invalidating queries

Extensions

StatefulServiceHooks on StatefulService<TState>
Extension for using selectors with hooks.

Functions

defaultRetryDelay(int attemptIndex, Object error) Duration
Default retry delay with exponential backoff
useInfiniteQuery<TData, TError, TPageParam>({required QueryKey queryKey, required Future<TData> queryFn(QueryFnContext context), required TPageParam? initialPageParam, required GetNextPageParamFn<TData, TPageParam>? getNextPageParam, GetPreviousPageParamFn<TData, TPageParam>? getPreviousPageParam, StaleTime staleTime = StaleTime.zero, CacheTime cacheTime = CacheTime.defaultTime, bool enabled = true, bool refetchOnWindowFocus = true, bool refetchOnReconnect = true, int retry = 3, RetryDelayFn retryDelay = defaultRetryDelay, int? maxPages}) UseInfiniteQueryResult<TData, TError, TPageParam>
Hook for infinite/paginated queries
useIsFetching({QueryKey? queryKey}) int
Hook to get the number of queries currently fetching
useIsMutating() int
Hook to get the number of mutations currently pending
useMutation<TData, TError, TVariables, TContext>({required MutationFn<TData, TVariables> mutationFn, List? mutationKey, TContext onMutate(TVariables)?, void onSuccess(TData data, TVariables variables, TContext? context)?, void onError(TError error, TVariables variables, TContext? context)?, void onSettled(TData? data, TError? error, TVariables variables, TContext? context)?, int retry = 0, RetryDelayFn retryDelay = defaultRetryDelay, NetworkMode networkMode = NetworkMode.online}) UseMutationResult<TData, TError, TVariables, TContext>
Hook for performing mutations
useQueries({required List<QueryConfig> queries}) List<QueryResult>
Hook for running multiple queries in parallel
useQuery<TData, TError>({required QueryKey queryKey, required QueryFn<TData> queryFn, StaleTime staleTime = StaleTime.zero, CacheTime cacheTime = CacheTime.defaultTime, bool enabled = true, Duration? refetchInterval, bool refetchOnWindowFocus = true, bool refetchOnReconnect = true, bool refetchOnMount = true, int retry = 3, RetryDelayFn retryDelay = defaultRetryDelay, TData? placeholderData, TData? initialData, DateTime? initialDataUpdatedAt, bool keepPreviousData = false, PersistOptions<TData>? persist}) QueryResult<TData, TError>
Hook for fetching and caching data
useQueryClient() QueryClient
Hook to get the QueryClient from context
useQuerySelect<TData, TError, TSelect>({required QueryKey queryKey, required QueryFn<TData> queryFn, required TSelect select(TData data), StaleTime staleTime = StaleTime.zero, CacheTime cacheTime = CacheTime.defaultTime, bool enabled = true, Duration? refetchInterval, bool refetchOnWindowFocus = true, bool refetchOnReconnect = true, bool refetchOnMount = true, int retry = 3, RetryDelayFn retryDelay = defaultRetryDelay, TData? placeholderData, TData? initialData, DateTime? initialDataUpdatedAt, bool keepPreviousData = false}) QueryResult<TSelect, TError>
Hook for fetching data with a select function to transform the result
useSelect<TService extends StatefulService<TState>, TState, R>(R selector(TState state)) → R
Hook to select state from a singleton StatefulService.
useService<T extends Service>() → T
Hook to access a singleton service from the ServiceContainer.
useSimpleMutation<TData, TVariables>({required Future<TData> mutationFn(TVariables), void onSuccess(TData data, TVariables variables)?, void onError(Object error, TVariables variables)?}) UseMutationResult<TData, Object, TVariables, void>
Simplified mutation hook
useSimpleQuery<TData>({required QueryKey queryKey, required Future<TData> queryFn(), StaleTime staleTime = StaleTime.zero, bool enabled = true, bool keepPreviousData = false}) QueryResult<TData, Object>
Simplified useQuery hook for basic use cases
useViewModel<T extends Service>(BuildContext context) → T
Hook to get a ViewModel from ViewModelProvider.
useViewModelSelect<TService extends StatefulService<TState>, TState, R>(BuildContext context, R selector(TState state)) → R
Hook to select state from a ViewModel StatefulService.

Typedefs

GcTime = CacheTime
@deprecated Use CacheTime instead. Will be removed in v2.0.0.
GetNextPageParamFn<TData, TPageParam> = TPageParam? Function(TData lastPage, List<TData> allPages, TPageParam? lastPageParam, List<TPageParam?> allPageParams)
Infinite query get next page param function
GetPreviousPageParamFn<TData, TPageParam> = TPageParam? Function(TData firstPage, List<TData> allPages, TPageParam? firstPageParam, List<TPageParam?> allPageParams)
Infinite query get previous page param function
HivePersister = HiveCePersister
MutationFn<TData, TVariables> = FutureOr<TData> Function(TVariables variables)
Function type for mutations
QueryFn<T> = FutureOr<T> Function(QueryFnContext context)
Function type for fetching query data
QueryKey = List
Query key type - can be a list of dynamic values
RetryDelayFn = Duration Function(int attemptIndex, Object error)
Retry delay function type
SelectFn<TData, TResult> = TResult Function(TData data)
Select function for transforming query data
ServiceFactory<T extends Service> = T Function(ServiceRef ref)
Factory function type for creating services.
UseQueryResult<TData, TError> = QueryResult<TData, TError>
Result type for useQuery hook
VoidCallback = void Function()
Void callback type

Exceptions / Errors

CircularDependencyException
Exception thrown when a circular dependency is detected.
QueryCancelledException
Exception thrown when a query is cancelled
ServiceDisposedException
Exception thrown when trying to use a disposed service.
ServiceNotFoundException
Exception thrown when a requested service is not registered.