FirebaseDatabaseListView constructor
FirebaseDatabaseListView({
- Key? key,
- required Query query,
- required FirebaseItemBuilder itemBuilder,
- int pageSize = 10,
- FirebaseLoadingBuilder? loadingBuilder,
- FirebaseErrorBuilder? 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.
As an example, consider the following collection:
final moviesCollection = FirebaseDatabase.instance.ref('movies');
Using FirebaseDatabaseListView, we can now show the list of movies by writing:
FirebaseDatabaseListView(
query: moviesCollection,
itemBuilder: (context, snapshot) {
var movie = snapshot.value as Map;
return Text(movie['title']);
},
)
For advanced UI use-cases, consider switching to FirebaseDatabaseQueryBuilder.
Implementation
FirebaseDatabaseListView({
Key? key,
required Query query,
required FirebaseItemBuilder itemBuilder,
int pageSize = 10,
FirebaseLoadingBuilder? loadingBuilder,
FirebaseErrorBuilder? 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,
}) : super(
key: key,
query: query,
pageSize: pageSize,
builder: (context, snapshot, _) {
if (snapshot.isFetching) {
return loadingBuilder?.call(context) ??
const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError && errorBuilder != null) {
return errorBuilder(
context,
snapshot.error!,
snapshot.stackTrace!,
);
}
return ListView.builder(
itemCount: snapshot.docs.length,
itemBuilder: (context, index) {
final isLastItem = index + 1 == snapshot.docs.length;
if (isLastItem && snapshot.hasMore) snapshot.fetchMore();
final doc = snapshot.docs[index];
return itemBuilder(context, doc);
},
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
primary: primary,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
itemExtent: itemExtent,
prototypeItem: prototypeItem,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
addSemanticIndexes: addSemanticIndexes,
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
);
},
);