Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/firestore_pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FirestorePagination extends StatefulWidget {
this.padding,
this.controller,
this.pageController,
this.onData,
});

/// The query to use to fetch data from Firestore.
Expand Down Expand Up @@ -161,6 +162,11 @@ class FirestorePagination extends StatefulWidget {
/// Defaults to [PageController].
final PageController? pageController;

/// Callback for when data is loaded, allows access to loaded data from the parent widget.
///
/// Defaults to `null`.
final void Function(List<DocumentSnapshot>)? onData;

@override
State<FirestorePagination> createState() => _FirestorePaginationState();
}
Expand Down Expand Up @@ -221,6 +227,8 @@ class _FirestorePaginationState extends State<FirestorePagination> {
..clear()
..addAll(snapshot.docs);

widget.onData?.call(_docs);

// To set new updates listener for the existing data
// or to set new live listener if the first document is removed.
final isDocRemoved = snapshot.docChanges.any(
Expand Down Expand Up @@ -281,6 +289,8 @@ class _FirestorePaginationState extends State<FirestorePagination> {

_docs.insert(0, snapshot.docs.first);

widget.onData?.call(_docs);

// To handle newly added data after this curently loaded data.
await _setLiveListener();

Expand Down