update method
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:
- StateError if no object with the extracted ID exists
- ArgumentError if the extracted/generated ID is invalid
See also:
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.');
}
}