updateByKeySafe method
- @nonVirtual
- E key,
- dynamic value
Calls updateByKey and validates the result in debug mode.
In debug builds, asserts that getValueByKey on the returned instance
equals value. A mismatch means either updateByKey or getValueByKey
is incorrectly implemented.
In release builds the assertion is stripped — no runtime overhead.
Implementation
@nonVirtual
F updateByKeySafe(E key, dynamic value) {
final result = updateByKey(key, value);
assert(() {
final setValue = result.getValueByKey(key);
if (setValue != value) {
throw Exception(
'Failed to update key $key with value $value.\n'
'Either "updateByKey" or "getValueByKey" is incorrectly implemented '
'in the subclass. Expected "$value" but got "$setValue".',
);
}
return true;
}());
return result;
}