qora_flutter library
Flutter integration layer for Qora.
Provides widgets, managers, and extensions for using QoraClient in Flutter applications.
Core components
- QoraScope —
InheritedWidgetthat provides a QoraClient to the entire widget tree. - QoraBuilder — subscribes to a query, auto-fetches on mount, and rebuilds on every state change.
- QoraStateBuilder — observe-only variant; rebuilds on state changes without triggering a fetch.
context.qora— shorthand forQoraScope.of(context).
Optional managers
- FlutterLifecycleManager — invalidates queries when the app resumes from background (requires no extra dependency).
- FlutterConnectivityManager — invalidates queries when the device
reconnects to the network (requires
connectivity_plus).
Quick start
void main() {
final client = QoraClient(
config: const QoraClientConfig(
defaultOptions: QoraOptions(
staleTime: Duration(minutes: 5),
gcTime: Duration(minutes: 10),
),
debugMode: kDebugMode,
maxCacheSize: 200,
),
);
runApp(
QoraScope(
client: client,
lifecycleManager: FlutterLifecycleManager(qoraClient: client),
child: MyApp(),
),
);
}
class UserProfile extends StatelessWidget {
final int userId;
const UserProfile({required this.userId, super.key});
@override
Widget build(BuildContext context) {
return QoraBuilder<User>(
queryKey: ['users', userId],
fetcher: () => api.getUser(userId),
builder: (context, state) {
return switch (state) {
Initial() => const SizedBox.shrink(),
Loading(:final previousData) =>
previousData != null
? UserCard(previousData)
: const CircularProgressIndicator(),
Success(:final data) => UserCard(data),
Failure(:final error) => ErrorBanner(error),
};
},
);
}
}
// Invalidate after a mutation
ElevatedButton(
onPressed: () async {
await api.deleteUser(userId);
context.qora.invalidate(['users', userId]);
},
child: const Text('Delete'),
)
Classes
-
CacheEntry<
T> - An entry in the query cache.
- CancelToken
- A cooperative cancellation signal for QoraClient.fetchQuery, QoraClient.watchQuery, and QoraClient.prefetch.
- ConnectivityManager
- Abstract interface for network connectivity observation.
-
Failure<
T> - Failure state - fetch operation failed.
- FlutterConnectivityManager
- Flutter implementation of ConnectivityManager.
- FlutterLifecycleManager
- Flutter implementation of LifecycleManager.
-
InfiniteData<
TData, TPageParam> - Immutable container holding all fetched pages and their corresponding page parameters for an infinite query.
-
InfiniteFailure<
TData, TPageParam> - A fetch failure, with optional previousData for graceful degradation.
-
InfiniteInitial<
TData, TPageParam> - The query has not been executed yet.
-
InfiniteLoading<
TData, TPageParam> - The initial page fetch is in progress (no pages loaded yet).
-
InfiniteQueryBuilder<
TData, TPageParam> - A widget that manages an infinite (paginated) query and rebuilds whenever the state changes.
-
InfiniteQueryController<
TData, TPageParam> - Controls the pagination actions exposed to InfiniteQueryBuilder.builder.
-
InfiniteQueryObserver<
TData, TPageParam> - Manages the pagination lifecycle for a single infinite query.
-
InfiniteQueryOptions<
TData, TPageParam> - Configuration for an infinite (paginated) query.
-
InfiniteQueryState<
TData, TPageParam> - The state machine for an infinite (paginated) query.
-
InfiniteSuccess<
TData, TPageParam> - All currently loaded pages, with pagination status flags.
-
Initial<
T> - Initial state - query hasn't started yet.
-
InMemoryPersistence<
T> - In-memory persistence (for testing).
- InMemoryStorageAdapter
- In-memory StorageAdapter backed by a plain Map.
- LifecycleManager
- Platform-agnostic abstraction over application lifecycle events.
-
Loading<
T> - Loading state - actively fetching data.
- MultiTracker
- A QoraTracker that fans out every hook call to a list of child trackers.
-
MutationController<
TData, TVariables, TContext> - Controls and tracks the lifecycle of a single mutation.
-
MutationFailure<
TData, TVariables> - Failure state — mutation failed.
-
MutationIdle<
TData, TVariables> - Idle state — no mutation has been run yet (or after MutationController.reset).
- MutationMeta
- Identity of one call to a registered mutation, passed to its mutator.
-
MutationOptions<
TData, TVariables, TContext> - Configuration and lifecycle callbacks for a MutationController.
-
MutationPending<
TData, TVariables> - Pending state — mutation is actively running.
- MutationQueue
- The queue of registered mutations.
- MutationQueueBuilder
- A widget that rebuilds whenever the calls in a MutationQueue change: a call queued, sent, retried, failed, discarded or done.
- MutationQueueConfig
- How the mutation queue retries registered mutations.
-
MutationRegistration<
TData, TVariables> - A mutation registered under a key with MutationRegistry.register.
- MutationRegistry
- The mutations a client knows by key.
-
MutationState<
TData, TVariables> - Represents the state of a mutation operation.
-
MutationSuccess<
TData, TVariables> - Success state — mutation completed successfully.
- MutationTracker
- Interface that receives mutation lifecycle notifications from a MutationController.
- MutationUpdate
- An event emitted by QoraClient whenever a tracked MutationController changes state.
- NetworkStatusBuilder
- A widget that rebuilds whenever the NetworkStatus changes.
- NetworkStatusIndicator
- A widget that overlays an offline banner on top of child when the device loses connectivity.
- OfflineMutationQueue
- A FIFO queue of PendingMutations accumulated while the device is offline.
- OfflineReplayResult
- Result of an OfflineMutationQueue.replay call.
- PendingMutation
- A mutation enqueued while the device was offline.
- PersistQoraClient
- A QoraClient that automatically persists query results to a StorageAdapter and restores them on startup (offline-first).
-
QoraBuilder<
T> - A widget that fetches data and rebuilds whenever the query state changes.
- QoraClient
- QoraClientConfig
- Global configuration for QoraClient.
- QoraKey
- Immutable query key with validation and type safety.
-
QoraMutationBuilder<
TData, TVariables, TContext> - A widget that manages a MutationController and rebuilds whenever the mutation state changes.
- QoraOptions
- Per-query configuration that overrides global QoraClientConfig defaults.
-
QoraPrefetch<
T> - A widget that pre-warms the Qora cache for a query as soon as it is mounted, without rendering any loading UI itself.
- QoraScope
- Provides a QoraClient to the widget tree via an InheritedWidget.
-
QoraSerializer<
T> -
A pair of functions that convert a value of type
Tto and from a JSON-compatible representation. -
QoraState<
T> - Represents the state of a query operation.
-
QoraStateBuilder<
T> - A widget that observes query state without triggering a fetch.
-
QoraStateCodec<
T> - Codec for encoding/decoding states with a specific data type.
-
QoraStatePersistence<
T> - Persistence adapter for storing states.
- QoraStateSerialization
- Mixin for serializing and deserializing QoraState.
- QoraStateUtils
- Utility for handling multiple states.
- QoraTracker
- Observability interface injected into QoraClient to report cache and mutation lifecycle events.
- QueryCache
- Internal LRU cache that stores CacheEntry instances keyed by normalised query keys.
- QueryTag
- A tag that associates query cache entries with a logical category.
- QueuedMutation
- One registered call in the mutation queue, as the app sees it.
- ReconnectStrategy
- Controls how QoraClient replays paused queries when the device reconnects.
- SharedPreferences persistence adapter.
- SsrHydrator
- No-op SsrHydrator for non-web platforms.
- StorageAdapter
- Low-level key/value storage contract for Qora persistence.
-
Success<
T> - Success state - data fetched successfully.
Enums
- FetchStatus
- Indicates whether a query is currently executing a network request.
- LifecycleState
- Represents a coarse-grained application lifecycle state.
- MutationStatus
- Coarse-grained status of a MutationState.
- NetworkMode
- Controls how a query or mutation behaves with respect to network status.
- NetworkStatus
- The network reachability status reported by a ConnectivityManager.
- QoraStatus
- Simple status enum for cases where you don't need full state.
- QueuedMutationStatus
- Where a QueuedMutation stands in the mutation queue.
Extensions
-
MutationStateExtensions
on MutationState<
TData, TVariables> - Additional utility extensions on MutationState.
-
MutationStateStreamExtensions
on Stream<
MutationState< TData, TVariables> > - Stream extensions for MutationState.
- QoraBuildContextExtension on BuildContext
- Convenience extension on BuildContext for accessing QoraClient.
-
QoraStateExtensions
on QoraState<
T> - Additional utility extensions for QoraState.
-
QoraStateFutureExtensions
on Future<
QoraState< T> > - Extension for working with Future<QoraState<T>>.
-
QoraStateSerializationX
on QoraState<
T> - Extension for easier serialization access.
-
QoraStateStreamExtensions
on Stream<
QoraState< T> > - Extension for working with Stream<QoraState<T>>.
Functions
-
normalizeKey(
Object key) → List - Normalizes a polymorphic key input to parts.
-
Compares
aandbusing deep equality and returnsawhen they are deeply equal, preserving referential identity for unchanged data.
Typedefs
-
InfiniteQueryFunction<
TData, TPageParam> = Future< TData> Function(TPageParam pageParam) - Function that returns one page of data for an infinite query.
-
MutatorFunction<
TData, TVariables> = Future< TData> Function(TVariables variables) - Mutation function.
- QoraKeyParts = List
- Type alias for raw key parts (backwards compatibility).
- QueryFilter = bool Function(String key, QoraState state, QoraOptions? lastOptions)
- The central engine of Qora: manages queries, cache, deduplication, retries, reactive state, and network-aware pausing / reconnect replay.
-
QueryFunction<
T> = Future< T> Function() - Function that returns query data.
-
RegisteredMutator<
TData, TVariables> = Future< TData> Function(TVariables variables, MutationMeta meta) - The mutator of a registered mutation.
Exceptions / Errors
- MutationDiscardedException
-
Passed to
onErrorwhen the app removes a queued call before it was sent, withMutationQueue.discard,discardScopeorclear. - QoraCancelException
- Thrown by QoraClient.fetchQuery or QoraClient.watchQuery when the associated CancelToken is cancelled before or during the fetch.
- QoraException
- QoraOfflineException
- Thrown by QoraClient.fetchQuery when the device is offline, the query's NetworkMode is NetworkMode.online, and there is no cached data to return.