getAllItems<T extends StorableModel> method

Future<List<T>> getAllItems<T extends StorableModel>(
  1. String tag,
  2. T fromJson(
    1. Map<String, dynamic>
    )
)

Retrieves all stored items from a specific tag.

This method loads all the data associated with the given tag and deserializes each item using the fromJson function.

Parameters:

  • tag: A unique identifier for the data collection.
  • fromJson: A function that converts a Map<String, dynamic> into an instance of T.

Returns:

  • A Future that resolves to a list of items of type T.

Usage: Use this method to retrieve all stored items for a particular collection.

Implementation

Future<List<T>> getAllItems<T extends StorableModel>(
  final String tag,
  final T Function(Map<String, dynamic>) fromJson,
) async {
  final Map<String, dynamic> data = await _loadData(tag);
  return data.values
      .map((final dynamic item) => fromJson(item as Map<String, dynamic>))
      .toList();
}