disconnect method

Future<BluetoothDeviceState> disconnect(
  1. Duration? timeout
)

Cancels connection to the Bluetooth Device

Implementation

Future<BluetoothDeviceState> disconnect(Duration? timeout) async {
  final stateCompleter =
      state.firstWhere((state) => state is BluetoothDeviceDisconnected);

  await FlutterBlue.instance._channel
      .invokeMethod('disconnect', id.toString());

  if (timeout != null) {
    return await stateCompleter.timeout(timeout);
  } else {
    return await stateCompleter;
  }
}