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 = FlutterBluePlusPlatform.instance.onTurnOnResponse;

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

  // invoke
  bool changed = await _invokePlatform(() => FlutterBluePlusPlatform.instance.turnOn(BmTurnOnRequest()));

  // 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");
  }
}