diff --git a/lib/src/bluetooth_device.dart b/lib/src/bluetooth_device.dart index 355b2511..dcef6ef4 100644 --- a/lib/src/bluetooth_device.dart +++ b/lib/src/bluetooth_device.dart @@ -21,7 +21,7 @@ class BluetoothDevice { Future connect({ Duration? timeout, bool autoConnect = true, - }) async { + }) { final completer = Completer(); var request = protos.ConnectRequest.create() ..remoteId = id.toString() @@ -36,14 +36,14 @@ class BluetoothDevice { }); } - await FlutterBlue.instance._channel - .invokeMethod('connect', request.writeToBuffer()); - - await state.firstWhere((s) => s == BluetoothDeviceState.connected); - - timer?.cancel(); - - completer.complete(); + FlutterBlue.instance._channel + .invokeMethod('connect', request.writeToBuffer()) + .then((_) { + state.firstWhere((s) => s == BluetoothDeviceState.connected).then((_) { + timer?.cancel(); + completer.complete(); + }); + }); return completer.future; } diff --git a/pubspec.yaml b/pubspec.yaml index 105fbc1f..ac8056c3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_blue description: Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS -version: 0.11.0 +version: 0.12.0 homepage: https://github.com/pauldemarco/flutter_blue environment: