getItemWhereSync method

dynamic getItemWhereSync(
  1. bool where(
    1. dynamic
    ), {
  2. String? streamId,
})

Implementation

dynamic getItemWhereSync(bool Function(dynamic) where, {String? streamId}) {
  if (!_cacheLoaded) {
    throw StorageDatabaseException(
      "Cache is not loaded. Call get() method first.",
    );
  }

  dynamic item;

  if (_cache is Map) {
    item = _cache.entries.firstWhere((entry) => where(entry.value));
  } else if (_cache is List) {
    item = _cache.firstWhere(where);
  } else {
    throw StorageDatabaseException(
      "This Collection ($collectionId) does not support collections",
    );
  }

  if (streamId != null && storageListeners.hasStreamId(path, streamId)) {
    storageListeners.getDate(path, streamId);
  }

  return item;
}