This article covers the steps you need to follow to load data from Firestore in batches (pagination/endless scrolling) and obtain a list of an object type from it.

Add the rxdart package to your project before we proceed.


We will use a custom class called DataBloc as the input stream of our data. Create a new file called _dataBloc.dart _and a class DataBloc that can support any data type.

class DataBloc<T> {}

Declare the following variables in it that we will use later.

T dataType;
Query query;
int numberToLoadAtATime;
int numberToLoadFromNextTime;
Function documentSnapshotToT;
bool showIndicator = false;
DocumentSnapshot lastFetchedSnapshot;
List<T> objectsList;
BehaviorSubject<List<T>> blocController;
BehaviorSubject<bool> showIndicatorController;

#flutter-widget #flutter #pagination #firestore

Flutter | Pagination/Lazy Loading From Streams With Firestore
28.40 GEEK