queryItems<T extends StorableModel> method

Future<List<T>> queryItems<T extends StorableModel>(
  1. String tag,
  2. T fromJson(
    1. Map<String, dynamic>
    ),
  3. bool filter(
    1. T item
    )
)

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 of T.
  • filter: A predicate function to filter items of type T.

Returns:

  • A Future that resolves to a list of items of type T matching 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;
}