requestBluetoothAndLocationPermissions function

Future<bool> requestBluetoothAndLocationPermissions()

Requests Bluetooth and Location permissions required for BLE scanning. Returns true if all permissions are granted, false otherwise.

Implementation

Future<bool> requestBluetoothAndLocationPermissions() async {
  // Request permissions for Bluetooth and Location
  Map<Permission, PermissionStatus> statuses =
      await [
        Permission.location,
        Permission.bluetooth,
        Permission.bluetoothScan,
        Permission.bluetoothConnect,
      ].request();

  // Check if all permissions are granted
  bool allGranted = statuses.values.every((status) => status.isGranted);

  if (!allGranted) {
    // Optionally, show a dialog to the user explaining why permissions are needed
    print('Not all permissions granted: $statuses');
  }

  return allGranted;
}