writeValueWithoutResponse method
Write a new value to the characteristic without waiting for a response from the Bluetooth device.
This means that the data that is written may not reach the device and you won't know about it. It's a bit like UDP.
-
May throw NotSupportedError if the operation is not allowed. Check properties to see if it is supported.
-
May throw NetworkError if the device is not connected or if there is an error with the communication.
-
May throw StateError if the characteristic is null.
ignore: deprecated_member_use_from_same_package
- Will call WebBluetoothRemoteGATTCharacteristic.writeValue if WebBluetoothRemoteGATTCharacteristic.writeValueWithoutResponse is not supported on the browser.
See: writeValueWithResponse.
Implementation
Future<void> writeValueWithoutResponse(final Uint8List data) async {
try {
if (_characteristic.hasWriteValueWithoutResponse()) {
return _characteristic.writeValueWithoutResponse(data);
}
webBluetoothLogger.info(
"WriteValueWithoutResponse not supported in this browser. "
"Using writeValue instead",
null,
StackTrace.current);
// ignore: deprecated_member_use_from_same_package
return _characteristic.writeValue(data);
} catch (e) {
final error = e.toString().trim();
if (error.startsWith("NotSupportedError")) {
throw NotSupportedError(uuid);
} else if (error.startsWith("NetworkError")) {
throw NetworkError.withUUid(uuid);
} else if (error.startsWith("InvalidStateError")) {
throw StateError("Characteristic is null");
}
rethrow;
}
}