QueryBuilder<T> class

A widget that executes an async operation and builds UI based on its state.

QueryBuilder automatically manages the query lifecycle, subscribing when mounted and unsubscribing when disposed. It handles loading, error, and success states, making async operations simple to use in Flutter widgets.

The query is shared across all widgets with the same queryKey, so multiple QueryBuilder widgets with identical keys will share state and only execute the async operation once.

Example:

QueryBuilder<List<User>>(
  queryKey: 'users',
  queryFn: () => api.fetchUsers(),
  builder: (context, state) {
    if (state.isLoading) return CircularProgressIndicator();
    if (state.hasError) return Text('Error: ${state.error}');
    if (state.hasData) return UserList(users: state.data!);
    return SizedBox();
  },
)
Inheritance

Constructors

QueryBuilder({required QueryKey queryKey, required Widget builder(BuildContext context, QueryState<T> state), Future<T> queryFn()?, Future<T> queryFnWithToken(CancellationToken token)?, QueryOptions? options, QueryKey? dependsOn, Key? key})
Creates a QueryBuilder for the given queryKey.
const

Properties

builder Widget Function(BuildContext context, QueryState<T> state)
Builds the widget tree based on the current query state.
final
dependsOn QueryKey?
The parent query key that this query depends on.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
options QueryOptions?
Optional configuration for the query.
final
queryFn Future<T> Function()?
The async function to execute.
final
queryFnWithToken Future<T> Function(CancellationToken token)?
The async function to execute with cancellation support.
final
queryKey QueryKey
Unique identifier for this query.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<QueryBuilder<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