setItem<T extends StorableModel> method

Future<void> setItem<T extends StorableModel>(
  1. String tag,
  2. T item
)

Creates or updates an item in a specified collection.

This method retrieves the current data for the given tag, updates the item if it exists, or adds a new one if it doesn't. The updated data is then saved to persistent storage.

Parameters:

  • tag: A unique identifier for the collection where the item is stored.
  • item: An object of type T that extends StorableModel, representing the item to be created or updated.

Returns:

  • A Future that completes when the item is successfully stored.

Implementation

Future<void> setItem<T extends StorableModel>(
  final String tag,
  final T item,
) async {
  final Map<String, dynamic> data = await _loadData(tag);
  data[item.id] = item.toJson();
  await _saveData(tag, data);
}