FirestoreQueryBuilder<Document> class
Listens to a query and paginates the result in a way that is compatible with infinite scroll views, such as ListView or GridView.
FirestoreQueryBuilder will subscribe to the query and obtain the first pageSize items (10 by default). Then as the UI needs to render more items, it is possible to call FirestoreQueryBuilderSnapshot.fetchMore to obtain more items.
FirestoreQueryBuilder is independent from how the query will be rendered and as such can be used with any existing widget for rendering list of items.
An example of how to combine FirestoreQueryBuilder with ListView would be:
FirestoreQueryBuilder<Movie>(
query: moviesCollection.orderBy('title'),
builder: (context, snapshot, _) {
if (snapshot.isFetching) {
return const CircularProgressIndicator();
}
if (snapshot.hasError) {
return Text('error ${snapshot.error}');
}
return ListView.builder(
itemCount: snapshot.docs.length,
itemBuilder: (context, index) {
// if we reached the end of the currently obtained items, we try to
// obtain more items
if (snapshot.hasMore && index + 1 == snapshot.docs.length) {
// Tell FirestoreQueryBuilder to try to obtain more items.
// It is safe to call this function from within the build method.
snapshot.fetchMore();
}
final movie = snapshot.docs[index];
return Text(movie.title);
},
);
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- FirestoreQueryBuilder
- Implementers
Constructors
-
FirestoreQueryBuilder({Key? key, required Query<
Document> query, required FirestoreQueryBuilderSnapshotBuilder<Document> builder, int pageSize = 10, Widget? child}) -
Listens to a query and paginates the result in a way that is compatible with
infinite scroll views, such as ListView or GridView.
const
Properties
-
builder
→ FirestoreQueryBuilderSnapshotBuilder<
Document> -
final
- child → Widget?
-
A widget that will be passed to builder for optimizations purpose.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- pageSize → int
-
The number of items that will be fetched at a time.
final
-
query
→ Query<
Document> -
The query that will be paginated.
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(
) → _FirestoreQueryBuilderState< Document> -
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