restoreWithMac static method

Future<BluetoothDevice?> restoreWithMac({
  1. required String deviceName,
  2. required String macAddress,
})

Restore Connection With Mac address on android

Implementation

static Future<BluetoothDevice?> restoreWithMac({
  required String deviceName,
  required String macAddress,
}) async {
  if (!Platform.isAndroid) return null;
  var request = protos.ConnectRequest.create()
    ..remoteId = macAddress
    ..androidAutoConnect = false;
  await FlutterBlue.instance._channel
      .invokeMethod('connect', request.writeToBuffer());
  final device = BluetoothDevice._(
    id: DeviceIdentifier(macAddress),
    name: deviceName,
    type: BluetoothDeviceType.le,
  );
  await device.state.firstWhere((s) => s == BluetoothDeviceState.connected);
  return device;
}