nextPage method

  1. @nonVirtual
Future<void> nextPage()

Request the next page with current target

Implementation

@nonVirtual
Future<void> nextPage() async {
  if (_state._state is SearchStatusLoading ||
      _state._state is SearchStatusLoadingMore) {
    onReject();
    return;
  } else if (_state._state is SearchStatusDone && _state._isEnd) {
    onNoMoreData();
    return;
  }

  // update state
  _state.load(_state._pageNo);

  Iterable<T>? items = await fetcher(_state._searchTarget, _state._pageNo);
  if (items == null) {
    onFetcherFailed();
  } else {
    final bool isEnd = switch (endStrategy) {
      EndStrategy.empty => items.isEmpty,
      EndStrategy.notEnough => items.length < pageSize,
    };

    if (isEnd) _state._isEnd = true;

    if (items.isEmpty) {
      onNoMoreData();
    } else {
      _state._pageNo += 1;
    }
  }

  // update state
  _state.done(items);
}