checkAndRequestPermissions static method

Future<List<CamerAwesomePermission>?> checkAndRequestPermissions(
  1. bool saveGpsLocation, {
  2. bool checkMicrophonePermissions = true,
  3. bool checkCameraPermissions = true,
})

Implementation

static Future<List<CamerAwesomePermission>?> checkAndRequestPermissions(
  bool saveGpsLocation, {
  bool checkMicrophonePermissions = true,
  bool checkCameraPermissions = true,
}) async {
  try {
    if (Platform.isAndroid) {
      return CameraInterface()
          .requestPermissions(saveGpsLocation)
          .then((givenPermissions) {
        return givenPermissions
            .map((e) => CamerAwesomePermission.values
                .firstWhere((element) => element.name == e))
            .toList();
      });
    } else if (Platform.isIOS) {
      // TODO iOS Return only permissions that were given

      List<String> permissions = [];
      if (checkMicrophonePermissions) {
        permissions.add("microphone");
      }
      if (checkCameraPermissions) {
        permissions.add("camera");
      }

      return CamerawesomePlugin.checkiOSPermissions(permissions)
          .then((givenPermissions) => CamerAwesomePermission.values);
    }
  } catch (e) {
    printLog("failed to check permissions here...");
    // ignore: avoid_print
    print(e);
  }
  return Future.value([]);
}