FirestoreListView<Document> class

A ListView.builder that obtains its items from a Firestore query.

As an example, consider the following collection:

class Movie {
  Movie({required this.title, required this.genre});

  Movie.fromJson(Map<String, Object?> json)
    : this(
        title: json['title']! as String,
        genre: json['genre']! as String,
      );

  final String title;
  final String genre;

  Map<String, Object?> toJson() {
    return {
      'title': title,
      'genre': genre,
    };
  }
}

final moviesCollection = FirebaseFirestore.instance.collection('movies').withConverter<Movie>(
     fromFirestore: (snapshot, _) => Movie.fromJson(snapshot.data()!),
     toFirestore: (movie, _) => movie.toJson(),
   );

Using FirestoreListView, we can now show the list of movies by writing:

FirestoreListView<Movie>(
  query: moviesCollection.orderBy('title'),
  itemBuilder: (context, snapshot) {
    Movie movie = snapshot.data();
    return Text(movie.title);
  },
)

For advanced UI use-cases, consider switching to FirestoreQueryBuilder.

Inheritance

Constructors

FirestoreListView({Key? key, required Query<Document> query, required FirestoreItemBuilder<Document> itemBuilder, int pageSize = 10, FirestoreLoadingBuilder? loadingBuilder, FirestoreErrorBuilder? errorBuilder, Axis scrollDirection = Axis.vertical, bool reverse = false, ScrollController? controller, bool? primary, ScrollPhysics? physics, bool shrinkWrap = false, EdgeInsetsGeometry? padding, double? itemExtent, Widget? prototypeItem, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, bool addSemanticIndexes = true, double? cacheExtent, int? semanticChildCount, DragStartBehavior dragStartBehavior = DragStartBehavior.start, ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, String? restorationId, Clip clipBehavior = Clip.hardEdge})
A ListView.builder that obtains its items from a Firestore query.

Properties

builder FirestoreQueryBuilderSnapshotBuilder<Document>
finalinherited
child Widget?
A widget that will be passed to builder for optimizations purpose.
finalinherited
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.
finalinherited
query → Query<Document>
The query that will be paginated.
finalinherited
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.
inherited
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}) 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