Skip to content

Commit

Permalink
Add state check before discoverServices is called. (pauldemarco#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldemarco authored Apr 8, 2020
1 parent df44e5c commit b5d4289
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class BluetoothDevice {

/// Discovers services offered by the remote device as well as their characteristics and descriptors
Future<List<BluetoothService>> discoverServices() async {
final s = await state.first;
if (s != BluetoothDeviceState.connected) {
return Future.error(new Exception(
'Cannot discoverServices while device is not connected. State == $s'));
}
var response = FlutterBlue.instance._methodStream
.where((m) => m.method == "DiscoverServicesResult")
.map((m) => m.arguments)
Expand Down

0 comments on commit b5d4289

Please sign in to comment.