connect method

  1. @override
Future<bool> connect({
  1. required String address,
  2. required ConnectionConfig config,
})
override

Connect to a Bluetooth device via address. Throw BTException if failed.

Implementation

@override
Future<bool> connect({required String address, required ConnectionConfig config}) async {
  try {
    if (Platform.isIOS) {
      // For iOS, force using BLE
      config = const LEBluetoothConnectionConfig();
    }
    _connectionIsLE = config is LEBluetoothConnectionConfig;
    Map<String, dynamic> args = config.toMap();
    args["address"] = address;
    return await methodChannel.invokeMethod("connect", args);
  } on PlatformException catch (e) {
    throw BTException.fromPlatform(e);
  }
}