load method

Future<void> load({
  1. bool reload = false,
  2. bool ignoreIfLoading = false,
})

Implementation

Future<void> load({
  bool reload = false,
  bool ignoreIfLoading: false,
}) async {
  var _loading = loadingStream.value;

  if (_loading) {
    if (!ignoreIfLoading) {
      queue.add(() => load(reload: reload));
    }
    return;
  } else {
    _addToLoadingStream(true);
  }

  if (reload) {
    _pageIndex = 0;
  }
  try {
    _addToEndOfResultStream(false);
    List<T>? response = await getLoader().call(_pageIndex);
    bool _endOfResult = response?.isEmpty ?? true;

    _addToEndOfResultStream(_endOfResult);
    if (!_endOfResult) {
      _pageIndex++;
    }
    await _addItems(response ?? [], reload);
  } catch (error) {
    /**
     * Clear first
     */
    // await _clear(forceSkipDelay: true);
    /**
     * Prevent the list from loading more pages!
     */
    _addToEndOfResultStream(true);
    dataSubject.add(DataWrapper(dataList, error));
    return Future.error(error);
  } finally {
    _addToLoadingStream(false);
  }
}