Skip to content

Commit 03ef35b

Browse files
Sander Kerstenajkahl
authored andcommitted
Dematerialize exceptions inside readCharacteristic instead of in some stream transformation
so the stack trace is the one for the call to readCharacteristic (ending in the user's code that initiated the read that failed) instead of some generic list of stream handling methods.
1 parent 231031b commit 03ef35b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/flutter_reactive_ble/lib/src/connected_device_operation.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ class ConnectedDeviceOperationImpl implements ConnectedDeviceOperation {
4343
_blePlatform.charValueUpdateStream;
4444

4545
@override
46-
Future<List<int>> readCharacteristic(CharacteristicInstance characteristic) {
46+
Future<List<int>> readCharacteristic(
47+
CharacteristicInstance characteristic,
48+
) async {
4749
final specificCharacteristicValueStream = characteristicValueStream
4850
.where((update) => update.characteristic == characteristic)
49-
.map((update) => update.result.dematerialize());
51+
.map((update) => update.result);
5052

51-
return _blePlatform
53+
final result = await _blePlatform
5254
.readCharacteristic(characteristic)
5355
.asyncExpand((_) => specificCharacteristicValueStream)
5456
.firstWhere((_) => true,
5557
orElse: () => throw NoBleCharacteristicDataReceived());
58+
return result.dematerialize();
5659
}
5760

5861
@override

0 commit comments

Comments
 (0)