From 25af9a88ca84af9b4570cd2e7dab53a84ba27ea6 Mon Sep 17 00:00:00 2001 From: sante Date: Thu, 3 Apr 2025 00:05:19 -0300 Subject: [PATCH] Added support for onData callback --- lib/src/firestore_pagination.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/src/firestore_pagination.dart b/lib/src/firestore_pagination.dart index 2cdc67d..8247f3e 100644 --- a/lib/src/firestore_pagination.dart +++ b/lib/src/firestore_pagination.dart @@ -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. @@ -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)? onData; + @override State createState() => _FirestorePaginationState(); } @@ -221,6 +227,8 @@ class _FirestorePaginationState extends State { ..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( @@ -281,6 +289,8 @@ class _FirestorePaginationState extends State { _docs.insert(0, snapshot.docs.first); + widget.onData?.call(_docs); + // To handle newly added data after this curently loaded data. await _setLiveListener();