update method

  1. @override
Future<void> update(
  1. E value
)
override

Updates an existing object in the container.

This method determines the object's ID using getId, checks if an object with that ID exists, and updates it if found. If no object with the ID exists, a StateError is thrown to prevent accidental creation of new objects.

Parameters:

  • value - The object to update. Its ID must already exist in the container.

Throws:

See also:

  • updateAll for updating multiple objects
  • add which doesn't require the object to exist
  • set for unconditional storage

Implementation

@override
Future<void> update(E value) async {
  final String id = getId(value);
  if (await containsKey(id)) {
    await set(id, value);
  } else {
    throw StateError('Item with id $id does not exist and cannot be updated.');
  }
}