Wait for writeWithoutResponse completion (#166)
* Wait for writeWithoutResponse request completion on Android * Wait for writeWithoutResponse request completion on Darwin * Add WriteWithoutResponse button in example app * Update changelog and bump version * Apply suggestions from code review Co-authored-by: Foti Dim <foti@navideck.com> --------- Co-authored-by: Foti Dim <foti@navideck.com>
This commit is contained in:
@@ -129,7 +129,7 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _writeValue() async {
|
||||
Future<void> _writeValue({required bool withResponse}) async {
|
||||
BleCharacteristic? selectedCharacteristic = this.selectedCharacteristic;
|
||||
if (selectedCharacteristic == null ||
|
||||
!valueFormKey.currentState!.validate() ||
|
||||
@@ -146,13 +146,8 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
}
|
||||
|
||||
try {
|
||||
await selectedCharacteristic.write(
|
||||
value,
|
||||
withResponse: _hasSelectedCharacteristicProperty(
|
||||
[CharacteristicProperty.writeWithoutResponse],
|
||||
),
|
||||
);
|
||||
_addLog('Write', value);
|
||||
await selectedCharacteristic.write(value, withResponse: withResponse);
|
||||
_addLog('Write${withResponse ? "" : "WithoutResponse"}', value);
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
_addLog('WriteError', e);
|
||||
@@ -377,11 +372,19 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
discoveredServices.isNotEmpty &&
|
||||
_hasSelectedCharacteristicProperty([
|
||||
CharacteristicProperty.write,
|
||||
CharacteristicProperty.writeWithoutResponse
|
||||
]),
|
||||
onPressed: _writeValue,
|
||||
onPressed: () => _writeValue(withResponse: true),
|
||||
text: 'Write',
|
||||
),
|
||||
PlatformButton(
|
||||
enabled: isConnected &&
|
||||
discoveredServices.isNotEmpty &&
|
||||
_hasSelectedCharacteristicProperty([
|
||||
CharacteristicProperty.writeWithoutResponse,
|
||||
]),
|
||||
onPressed: () => _writeValue(withResponse: false),
|
||||
text: 'WriteWithoutResponse',
|
||||
),
|
||||
PlatformButton(
|
||||
enabled: isConnected &&
|
||||
discoveredServices.isNotEmpty &&
|
||||
|
||||
@@ -20,9 +20,9 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/universal_ble/darwin
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
device_info_plus: b0fafc687fb901e2af612763340f1b0d4352f8e5
|
||||
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
universal_ble: ff19787898040d721109c6324472e5dd4bc86adc
|
||||
universal_ble: cf52a7b3fd2e7c14d6d7262e9fdadb72ab6b88a6
|
||||
|
||||
PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
|
||||
|
||||
|
||||
Reference in New Issue
Block a user