updateStoredValue<T> method
Replaces a field's stored value. Set notify to also notify subscribers.
Defaults to storing only. Clients can read storage when read access is
enabled and no dynamic read hook overrides it. Applies the field's codec
and validation; requires start.
Notifications require notification access and send one GATT value without fragmentation or application-level acknowledgement. If transmission fails, the stored value remains updated.
Implementation
Future<void> updateStoredValue<T>(
BleField<T> field,
T value, {
bool notify = false,
}) {
final bytes = field.encode(value);
return _enqueue(() async {
if (!identical(_field(field.uuid), field)) {
throw ArgumentError('Field does not belong to the active profile');
}
if (notify && !field.access.contains(BleProperty.notify)) {
throw StateError('Field does not support notifications');
}
await _platform.setValue(field.uuid, bytes);
_values[field.uuid] = List.of(bytes);
if (notify) await _platform.notify(field.uuid, bytes);
});
}