loadMore method

Future<void> loadMore()

Load more items

Implementation

Future<void> loadMore() async {
  if (_isLoading || _endReached) return;

  _isLoading = true;
  _currentError = null;
  _emitState();

  try {
    final keyToLoad = _nextKey ?? _initialKey;
    final result = await _pagingSource.load(
      LoadParams<Key>(key: keyToLoad, loadSize: _pageSize),
    );

    _items.addAll(result.data);
    _nextKey = result.nextKey;

    if (_nextKey == null || result.data.isEmpty) {
      _endReached = true;
    }

    _emitState();
  } catch (e) {
    _currentError = e.toString();
    _isLoading = false;
    _emitState(error: e.toString());
    rethrow;
  } finally {
    _isLoading = false;
  }
}