getItems method

  1. @override
Future<Result<int, String, List<T>>> getItems({
  1. bool getCount = false,
  2. Future<Result<int, String, List<T>>> alternativeFunc()?,
  3. List<DataFilter>? subCollectionQuery,
  4. bool? useCursor,
  5. int limit = 1000,
  6. String channel = 'main',
  7. CrudStrategy strategy = const DefaultCrudStrategy(),
})
override

Implementation

@override
Future<Result<int, String, List<T>>> getItems({
  bool getCount = false,
  Future<Result<int, String, List<T>>> Function()? alternativeFunc,
  List<DataFilter>? subCollectionQuery,
  bool? useCursor,
  int limit = 1000,
  String channel = 'main',
  CrudStrategy strategy = const DefaultCrudStrategy(),
}) async {
  final currentItems = _currentList(channel);
  if (strategy.pushNullFirst) {
    _getItemsStream(channel).add([]);
  }
  if (!strategy.forceUpdate &&
      currentItems.isNotEmpty &&
      (currentItems.length != 1 ||
          currentItems[0].id != _getItemStream(channel).valueOrNull?.id)) {
    final items = currentItems;
    if (sortFunc != null) items.sort(sortFunc);
    _getItemsStream(channel).add(items);
    return _listResult(items);
  }
  final res = await (alternativeFunc != null
      ? alternativeFunc()
      : _crud.getItems(
      subCollectionQuery: subCollectionQuery,
      useCursor: useCursor,
      getCount: getCount,
      limit: limit));
  if (res.code == 0) {
    final items = res.data!;
    if (sortFunc != null) items.sort(sortFunc);
    _getItemsStream(channel).add(items);
  }
  return res;
}