QoraBuilder<T> class
A widget that fetches data and rebuilds whenever the query state changes.
QoraBuilder handles the full query lifecycle:
- Fetches on mount (unless enabled is
false) - Subscribes to all state transitions — loading, success, failure
- Re-fetches automatically when the query is externally invalidated (e.g. after a lifecycle event or an explicit QoraClient.invalidate call)
- Cancels the subscription cleanly on dispose
The builder receives both the QoraState and a FetchStatus so the UI
can distinguish between actively fetching and waiting for network
(FetchStatus.paused).
Basic usage
QoraBuilder<User>(
queryKey: ['users', userId],
fetcher: () => api.getUser(userId),
builder: (context, state, fetchStatus) {
if (fetchStatus == FetchStatus.paused) {
return OfflinePlaceholder(staleData: state.dataOrNull);
}
return switch (state) {
Initial() => const SizedBox.shrink(),
Loading(:final previousData) =>
previousData != null
? Stack(children: [UserCard(previousData), const Spinner()])
: const CircularProgressIndicator(),
Success(:final data) => UserCard(data),
Failure(:final error, :final previousData) =>
previousData != null
? Column(children: [UserCard(previousData), ErrorBanner(error)])
: ErrorScreen(error),
};
},
)
Conditional (dependent) query
QoraBuilder<Profile>(
queryKey: ['profiles', userId],
fetcher: () => api.getProfile(userId!),
enabled: userId != null,
builder: (context, state, fetchStatus) { ... },
)
Preserving previous data across key changes
QoraBuilder<List<Post>>(
queryKey: ['posts', page],
fetcher: () => api.getPosts(page),
keepPreviousData: true,
builder: (context, state, fetchStatus) {
// Loading state always carries the last page's data
final posts = state.dataOrNull ?? [];
return PostList(posts: posts, isRefreshing: state.isLoading);
},
)
Derived subscriptions with select
QoraBuilder<List<User>>(
queryKey: ['users'],
fetcher: () => api.getUsers(),
select: (users) => users.length, // rebuild only when the count changes
builder: (context, state, fetchStatus) =>
Text('${state.dataOrNull?.length ?? 0} users'),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- QoraBuilder
Constructors
-
QoraBuilder({Key? key, required Object queryKey, required Future<
T> fetcher(), required Widget builder(BuildContext context, QoraState<T> state, FetchStatus fetchStatus), Object? select(T data)?, QoraOptions? options, QoraClient? client, bool enabled = true, bool keepPreviousData = false}) -
const
Properties
-
builder
→ Widget Function(BuildContext context, QoraState<
T> state, FetchStatus fetchStatus) -
Builds the widget tree from the current QoraState and FetchStatus.
final
- client → QoraClient?
-
Override the client provided by the nearest QoraScope.
final
- enabled → bool
-
When
false, no fetch is triggered and the widget passively observes the current cached state.final -
fetcher
→ Future<
T> Function() -
The async function that performs the network/IO request.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- keepPreviousData → bool
-
When
true, Loading and Failure states are augmented with the last successfully fetched data if the client did not already supply it.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- options → QoraOptions?
-
Per-query configuration (stale time, retry count, polling interval, …).
final
- queryKey → Object
-
The query key — either a QoraKey or a plain List.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- select → Object? Function(T data)?
-
Rebuild filter for derived data.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< QoraBuilder< T> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited