loadMoreData method

void loadMoreData()

Implementation

void loadMoreData() {
  if (_hasReachedEnd || _isLoadingMoreData) return;
  _setIsLoading(true);
  final currentIndex = _pages.length;
  final sub = _getQuery().snapshots().listen((snapshot) {
    if (snapshot.docs.isEmpty) {
      _onEndReached();
    } else {
      _hasReachedEnd = false;
    }
    final pageAlreadyExists = currentIndex < _pages.length;
    if (!pageAlreadyExists && _hasReachedEnd) return;
    final loadedPage = Page(snapshot.docs);
    if (pageAlreadyExists) {
      _pages[currentIndex] = loadedPage;
    } else {
      _pages.add(loadedPage);
      _setIsLoading(false);
      _lastDocument = loadedPage.docs.last;
    }
    _atualizeState();
  });
  _streamSubs.add(sub);
}