QueriesBuilder<TQueryData, TData> class Collections

Builds from a list of queries that may change length or order, handing the builder their results in the same order as queries.

QueriesBuilder<Task, String>(
  queries: <QuerySelectOptions<Task, String>>[
    for (final id in visibleIds)
      QuerySelectOptions<Task, String>(
        queryKey: taskKey(id),
        queryFn: (context) => api.getTask(id, signal: context.signal),
        select: (task) => task.name,
      ),
  ],
  builder: (context, results) => Column(
    children: [
      for (final result in results) Text(result.dataOrNull ?? '…'),
    ],
  ),
)
  • Observers are reused by key and occurrence, so reordering the list starts no requests. Duplicate keys share one cache entry while keeping their own options.
  • Each query fails and settles on its own; one error does not disturb its neighbours. To fold the list into one value, see combine on a List<QueryResult>.
  • Homogeneous: one data type per collection, because a Dart List has one element type. A list of two types still compiles: Dart infers their common supertype, Object for a String and an int, and the cache entries are created as that, so a read of one of those keys as its own type, String or int, then throws QueryDataTypeError. For queries of different types, read each one and combine their results.
  • The list is re-applied whenever the parent rebuilds this widget, as the single-query builders re-apply their options; an unchanged list moves nothing.

No buildWhen. There is no single result to filter on: a predicate over the whole list would fire for any query in it and say nothing about which. Read each query with its own QueryBuilder (or any other call style) to filter per query. What this widget does guarantee is that it never rebuilds for a notification carrying what it is already showing, compared element by element.

The widget owns its QueriesController; use that directly for the same collection outside a widget.

Inheritance

Constructors

QueriesBuilder({Key? key, required List<QueryObserverOptionsBase<TQueryData, TData>> queries, required Widget builder(BuildContext context, List<QueryResult<TData>> results), QueryClient? client})
Observes queries on client, or else on the nearest QueryClientProvider's client, and builds with builder.
const

Properties

builder → Widget Function(BuildContext context, List<QueryResult<TData>> results)
Builds from the results, one per entry of queries in the same order — first, and again whenever a result or the list changes.
final
client → QueryClient?
The client to observe on. null — the usual case — uses the nearest QueryClientProvider's.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
queries → List<QueryObserverOptionsBase<TQueryData, TData>>
The queries to observe, in the order their results are handed to builder. Re-applied whenever the parent rebuilds this widget; duplicate keys keep independent observer options.
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<QueriesBuilder<TQueryData, TData>>
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