initPermissions method

Future<void> initPermissions(
  1. SensorConfig sensorConfig, {
  2. required bool enableImageStream,
  3. required bool enablePhysicalButton,
})

Implementation

Future<void> initPermissions(
  SensorConfig sensorConfig, {
  required bool enableImageStream,
  required bool enablePhysicalButton,
}) async {
  // wait user accept permissions to init widget completely on android
  if (Platform.isAndroid) {
    _permissionStreamSub =
        CamerawesomePlugin.listenPermissionResult()!.listen(
      (res) {
        if (res && !_isReady) {
          _init(
            enableImageStream: enableImageStream,
            enablePhysicalButton: enablePhysicalButton,
          );
        }
        if (onPermissionsResult != null) {
          onPermissionsResult!(res);
        }
      },
    );
  }
  final grantedPermissions =
      await CamerawesomePlugin.checkAndRequestPermissions(
          cameraContext.exifPreferences.saveGPSLocation);
  if (cameraContext.exifPreferences.saveGPSLocation &&
      !(grantedPermissions?.contains(CamerAwesomePermission.location) ==
          true)) {
    cameraContext.exifPreferences = ExifPreferences(saveGPSLocation: false);
    cameraContext.state
        .when(onPhotoMode: (pm) => pm.shouldSaveGpsLocation(false));
  }
  if (onPermissionsResult != null) {
    onPermissionsResult!(
        grantedPermissions?.hasRequiredPermissions() == true);
  }
}