pickImageFromCamera static method

Future<File?> pickImageFromCamera()

Implementation

static Future<File?> pickImageFromCamera() async {
  try {
    // For iOS, don't check permissions beforehand
    // Let the system handle it
    if (!Platform.isIOS) {
      if (!await _requestPermissions()) {
        throw Exception('Permission denied for camera access');
      }
    }

    final XFile? image = await _picker.pickImage(
      source: ImageSource.camera,
      imageQuality: 80,
    );

    if (image == null) {
      return null;
    }

    return File(image.path);
  } catch (e) {
    // Provide a more helpful error message
    if (e.toString().contains('Permission denied') ||
        e.toString().contains('access denied')) {
      throw Exception(
        'Camera access denied. Please grant camera permission in your device settings.',
      );
    }
    throw Exception('Error picking image from camera: $e');
  }
}