FirestorePageView<Document> constructor
FirestorePageView<Document> ({
- Key? key,
- required Query<
Document> query, - required Widget itemBuilder(
- BuildContext,
- QueryDocumentSnapshot<
Document> , - int index
- int pageSize = 20,
- FirestoreLoadingBuilder? loadingBuilder,
- FirestoreErrorBuilder? errorBuilder,
- Widget? emptyBuilder,
- Axis scrollDirection = Axis.vertical,
- bool reverse = false,
- PageController? controller,
- ScrollPhysics physics = const BouncingScrollPhysics(),
- int? semanticChildCount,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- String? restorationId,
- Clip clipBehavior = Clip.hardEdge,
Implementation
FirestorePageView({
Key? key,
required Query<Document> query,
required Widget Function(
BuildContext,
QueryDocumentSnapshot<Document>,
int index,
)
itemBuilder,
int pageSize = 20,
FirestoreLoadingBuilder? loadingBuilder,
FirestoreErrorBuilder? errorBuilder,
Widget? emptyBuilder,
Axis scrollDirection = Axis.vertical,
bool reverse = false,
PageController? controller,
ScrollPhysics physics = const BouncingScrollPhysics(),
int? semanticChildCount,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
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.docs.isEmpty) {
return emptyBuilder ??
const Center(
child: Text(
'No Data',
style: TextStyle(fontSize: 20, color: Colors.white),
),
);
}
if (snapshot.hasError && errorBuilder != null) {
return errorBuilder(
context,
snapshot.error!,
snapshot.stackTrace!,
);
}
return PageView.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,
index,
);
},
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
physics: physics,
dragStartBehavior: dragStartBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
);
},
);