getBondedDevices method

Future<List<BluetoothDevice>> getBondedDevices()

getBondedDevices()

Implementation

Future<List<BluetoothDevice>> getBondedDevices() async {
  bool hasAccess = false;
  if (await Permission.bluetooth.isPermanentlyDenied) openAppSettings();
  hasAccess = await Permission.bluetooth.isGranted;
  if (!hasAccess) hasAccess = await Permission.bluetooth.request().isGranted;

  if (await Permission.bluetoothScan.isPermanentlyDenied) openAppSettings();
  hasAccess = await Permission.bluetoothScan.isGranted;
  if (!hasAccess)
    hasAccess = await Permission.bluetoothScan.request().isGranted;

  if (await Permission.bluetoothConnect.isPermanentlyDenied)
    openAppSettings();
  hasAccess = await Permission.bluetoothConnect.isGranted;
  if (!hasAccess)
    hasAccess = await Permission.bluetoothConnect.request().isGranted;

  if (hasAccess) {
    final List list = await (_channel.invokeMethod('getBondedDevices'));
    return list.map((map) => BluetoothDevice.fromMap(map)).toList();
  } else
    return [];
}