Skip to content

Commit dd66653

Browse files
committed
Setup servicesDiscoveredChannel before invoking method. Fixes #107
1 parent 2cf8cec commit dd66653

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/src/bluetooth_device.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ class BluetoothDevice {
1919

2020
/// Discovers services offered by the remote device as well as their characteristics and descriptors
2121
Future<List<BluetoothService>> discoverServices() async {
22-
await FlutterBlue.instance._channel
23-
.invokeMethod('discoverServices', id.toString());
24-
25-
return await FlutterBlue.instance._servicesDiscoveredChannel
22+
var response = FlutterBlue.instance._servicesDiscoveredChannel
2623
.receiveBroadcastStream()
27-
.map((buffer) =>
28-
new protos.DiscoverServicesResult.fromBuffer(buffer))
24+
.map((buffer) => new protos.DiscoverServicesResult.fromBuffer(buffer))
2925
.where((p) => p.remoteId == id.toString())
3026
.map((p) => p.services)
3127
.map((s) => s.map((p) => new BluetoothService.fromProto(p)).toList())
3228
.first;
29+
30+
await FlutterBlue.instance._channel
31+
.invokeMethod('discoverServices', id.toString());
32+
33+
return response;
3334
}
3435

3536
/// Returns a list of Bluetooth GATT services offered by the remote device

0 commit comments

Comments
 (0)