flutter / flutter/flutter

ImagePicker throws PlatformException on permission denial (camera_access_denied)

Open
#177,977 13 comments 0 reactions 0 assignees View on GitHub
c: crash e: device-specific engine p: camera P3 package platform-android team-android triaged-android
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

1. Install and run the above sample on a real device
2. Tap the camera FAB to trigger ImagePicker.pickImage(source: ImageSource.camera
3. When the OS prompts for camera permission, choose “Deny”
4. Observe that the method throws PlatformException(camera_access_denied, ...)

### Expected results

If camera permission is denied, pickImage should:
Either return null or
Complete with a well-documented, consistent error that can be handled without crashing the flow
Ideally, the picker should not attempt to open the camera when permission is denied.

### Actual results

The call throws PlatformException(camera_access_denied, The user did not allow camera access., null, null)
In some cases, the UI appears to proceed into the camera flow before erroring.

### Code sample

Code sample

```dart
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(const App());

class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: const Demo());
}
}

class Demo extends StatefulWidget {
const Demo({super.key});
@override
State createState() => _DemoState();
}

class _DemoState extends State {
final ImagePicker picker = ImagePicker();
String result = 'Tap the button to pick from camera';

Future pickFromCamera() async {
try {
final XFile? image = await picker.pickImage(
source: ImageSource.camera,
imageQuality: 20,
);
setState(() => result = 'Result: ${image?.path ?? "null"}');
} catch (e) {
setState(() => result = 'Error: $e');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('ImagePicker Permission Test')),
body: Center(child: Text(result)),
floatingActionButton: FloatingActionButton(
onPressed: pickFromCamera,
child: const Icon(Icons.camera_alt),
),
);
}
}
```

### Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

### Logs

Logs

```console
Full exception: PlatformException(camera_access_denied, The user did not allow camera access., null, null)
```

### Flutter Doctor output

Doctor output

```console
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.35.4, on Microsoft Windows [Version 10.0.26100.6584], locale en-US)
[√] Windows Version (Windows 11 or higher, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2024.3.2)
[√] VS Code, 64-bit edition (version 1.105.1)
[√] Connected device (4 available)
[√] Network resources
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.