queryItems<T extends StorableModel> method
Queries and retrieves items that match a specified filter condition.
This method loads all items under the given tag, applies the filter
function to each item, and returns a list of matching items.
Parameters:
tag: A unique identifier for the data collection.fromJson: A function that converts a Map<String, dynamic> into an instance ofT.filter: A predicate function to filter items of typeT.
Returns:
- A Future that resolves to a list of items of type
Tmatching the filter condition.
Usage: Use this method to retrieve items that satisfy a given filter condition.
Implementation
Future<List<T>> queryItems<T extends StorableModel>(
final String tag,
final T Function(Map<String, dynamic>) fromJson,
final bool Function(T item) filter,
) async {
final Map<String, dynamic> data = await _loadData(tag);
final List<T> items =
data.values
.map((final dynamic item) => fromJson(item as Map<String, dynamic>))
.where(filter)
.toList();
return items;
}