loadMore method

Future<bool> loadMore([
  1. ARG? args
])

请求下一页数据

返回是否还有更多数据 true为还有更多数据 false为没有更多数据

Implementation

Future<bool> loadMore([ARG? args]) async {
  try {
    _inLoading = true;

    // 如果已经没有更多数据的话, 就不再请求
    if (!_noMoreData) {
      try {
        final nextPageData = await _pageFetch(++_currentPage, args);
        if (_receiveFullData) {
          // 如果有自定义的合并逻辑, 则调用之, 否则直接合并列表
          if (_onMergeList != null) {
            _dataList = _onMergeList!(_dataList, nextPageData);
          } else {
            _dataList = [..._dataList, ...nextPageData];
          }
        } else {
          _dataList = nextPageData;
        }
        // 如果有提供判断是否列表为空的回调, 则调用之, 否则直接判断是否为空列表
        if (_isNoMoreData != null) {
          _noMoreData = _isNoMoreData!(nextPageData);
        } else {
          _noMoreData = nextPageData.isEmpty;
        }

        if (_subject.isClosed) return false;
        _subject.add(_dataList);
      } catch (e) {
        if (_subject.isClosed) return false;
        _subject.addError(e);
      }
    } else {
      L.d('$_semantics 没有更多数据!');
    }

    return !_noMoreData;
  } finally {
    _inLoading = false;
  }
}