getItems method
Future<Result<int, String, List<T> > >
getItems({
- bool getCount = false,
- Future<
Result< alternativeFunc()?,int, String, List< >T> > - List<
DataFilter> ? subCollectionQuery, - bool? useCursor,
- int limit = 1000,
- String channel = 'main',
- 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;
}