itemWhere method
Future<Result<int, String, T?> >
itemWhere({
- required List<
DataFilter> query, - required T? choiceFunction(
- List<
T>
- List<
- String channel = 'main',
- CrudStrategy strategy = const DefaultCrudStrategy(),
override
Implementation
@override
Future<Result<int, String, T?>> itemWhere({
required List<DataFilter> query,
required T? Function(List<T>) choiceFunction,
String channel = 'main',
CrudStrategy strategy = const DefaultCrudStrategy(),
}) async {
if (strategy.pushNullFirst) {
_getResultStream(channel).add(_nullResult);
_getItemStream(channel).add(null);
}
final res = await _crud.getItems(subCollectionQuery: query);
if (res.code == 0 && res.data != null) {
final items = res.data!;
final T? item = choiceFunction(items);
_getItemStream(channel).add(item);
final list = _updatedList(channel, item);
_getItemsStream(channel).add(list);
final newResult = _dataResult(item);
_getResultStream(channel).add(newResult);
return newResult;
}
_getResultStream(channel).add(_nullResult);
return _nullResult;
}