getPermissions static method

Future<bool> getPermissions()

This function gets permissions for the camera,microphone and bluetooth headphones

Implementation

static Future<bool> getPermissions() async {
  ///We request the permissions for the camera,microphone and bluetooth
  await Permission.camera.request();
  await Permission.microphone.request();
  if (Platform.isIOS) {
    await Permission.bluetooth.request();
  }
  await Permission.phone.request();

  ///We check if the permissions are granted
  ///If they are granted we return true
  ///Else we return false
  if (Platform.isIOS) {
    if (await Permission.camera.isGranted &&
        await Permission.microphone.isGranted &&
        await Permission.bluetooth.isGranted) {
      return true;
    }
  } else if (Platform.isAndroid) {
    if (await Permission.camera.isGranted &&
        await Permission.microphone.isGranted &&
        await Permission.phone.isGranted) {
      return true;
    }
  }

  ///We open the app settings if the user has permanently denied the permissions
  ///This is done because the user can't grant the permissions from the app now
  bool isCameraPermissionsDenied = (await Permission.camera.isDenied &&
      !await Permission.camera.shouldShowRequestRationale);
  bool isMicrophonePermissionsDenied =
      (await Permission.microphone.isDenied &&
          !await Permission.microphone.shouldShowRequestRationale);
  bool isBluetoothPermissionsDenied = false;
  bool isPhonePermissionDenied = Platform.isAndroid
      ? (await Permission.phone.isDenied &&
          !await Permission.phone.shouldShowRequestRationale)
      : false;
  if (Platform.isIOS) {
    isBluetoothPermissionsDenied =
        await Permission.bluetooth.isPermanentlyDenied;
  }

  ///We open the app settings if the user has permanently denied the permissions
  ///based on the platform
  if (isCameraPermissionsDenied ||
      isMicrophonePermissionsDenied ||
      isBluetoothPermissionsDenied ||
      isPhonePermissionDenied) {
    await openAppSettings();
    return false;
  }

  return false;
}