turnOn static method

Future<void> turnOn({
  1. int timeout = 60,
})

Turn on Bluetooth (Android only),

Implementation

static Future<void> turnOn({int timeout = 60}) async {
  var responseStream = FlutterBluePlus._methodStream.stream
      .where((m) => m.method == "OnTurnOnResponse")
      .map((m) => m.arguments)
      .map((args) => BmTurnOnResponse.fromMap(args));

  // Start listening now, before invokeMethod, to ensure we don't miss the response
  Future<BmTurnOnResponse> futureResponse = responseStream.first;

  // invoke
  bool changed = await _invokeMethod('turnOn');

  // only wait if bluetooth was off
  if (changed) {
    // wait for response
    BmTurnOnResponse response = await futureResponse.fbpTimeout(timeout, "turnOn");

    // check response
    if (response.userAccepted == false) {
      throw FlutterBluePlusException(ErrorPlatform.fbp, "turnOn", FbpErrorCode.userRejected.index, "user rejected");
    }

    // wait for adapter to turn on
    await adapterState.where((s) => s == BluetoothAdapterState.on).first.fbpTimeout(timeout, "turnOn");
  }
}