image_picker closes the app or returns nothing after choosing a photo
The picked data never returns to the original call after Android kills MainActivityShort answer
On Android the system can kill MainActivity while the picker is open, so the app restarts and the result never arrives. Call retrieveLostData at startup. A singleInstance launchMode makes the picker always report a cancel. On iOS, add the usage description keys to Info.plist.
Fix it fast
1Find out which cause you have
Check the activity declaration in the Android manifest and the usage keys in the iOS plist. Both are quick to read and rule out two of the causes.
grep -n "launchMode" android/app/src/main/AndroidManifest.xml grep -n "UsageDescription" ios/Runner/Info.plist2Match what you see, then jump to its fix
- 1
The app is restarted while the picker is open and the picked file never reaches your codeAndroid killed MainActivity while the picker was openFix - 2
The picker opens and closes as if you cancelled, every timeMainActivity uses launchMode singleInstanceFix - 3
iOS only, and the keys from the plugin README are absent from Info.plistThe iOS usage description keys are not in Info.plistFix
- 1
What does the error look like?
The picked data never returns to the original call after Android kills MainActivityWith launchMode singleInstance the picker always returns RESULT_CANCELED
Cause 1 of 3
Android killed MainActivity while the picker was open
1Check
Android may destroy a background activity to recover memory, and its state is lost. image_picker then cannot return the result to the original call.
grep -rn "retrieveLostData" lib/2Fix
Ask the plugin for lost data once at startup. The call is one-time, so store the result right away.
Future<void> recoverPickedFiles() async {
final response = await ImagePicker().retrieveLostData();
if (response.isEmpty) return;
final files = response.files;
if (files != null) {
// use files
} else {
// response.exception has the reason
}
}3Verify
After a restart caused by the picker, the picked file is recovered at startup.
flutter runConfirmed by pub.dev
Cause 2 of 3
MainActivity uses launchMode singleInstance
1Check
singleInstance runs the activity alone in its task, and the plugin docs say the picker then always returns RESULT_CANCELED.
grep -n "launchMode" android/app/src/main/AndroidManifest.xml2Fix
Use singleTask instead, which the plugin recommends.
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
... >3Verify
Rebuild and pick a photo. The result now comes back.
flutter runConfirmed by pub.dev
Cause 3 of 3
The iOS usage description keys are not in Info.plist
1Check
The plugin's README requires purpose strings in ios/Runner/Info.plist for the camera, the photo library, and the microphone for video.
plutil -p ios/Runner/Info.plist | grep UsageDescription2Fix
Add the keys with a short, honest reason for each one that your app uses.
<key>NSPhotoLibraryUsageDescription</key>
<string>Choose a photo for your profile.</string>
<key>NSCameraUsageDescription</key>
<string>Take a photo for your profile.</string>3Verify
Rebuild the iOS app and pick from the gallery and the camera.
flutter run -d <ios-device-id>Confirmed by pub.dev
How do I stop it coming back?
- Call retrieveLostData in your first screen's initState on Android.
- Move camera captures out of the app cache if you need to keep them, since the plugin stores them there.
- Test the picker on a real Android phone as well as an emulator.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter Image.network shows nothing or throws when the image fails
EXCEPTION: resolving an image codec
Image.network throws an exception that goes to FlutterError.onError when a download or decode fails, so a 404 leaves a red screen or an empty box.
3 causes, each with a fixMobile apps
CLIENT_ID and REVERSED_CLIENT_ID are not in GoogleService-Info.plist
ANDROID_CLIENT_ID is missing from GoogleService-Info.plist
Firebase's Google sign-in steps enable the Google provider first and only then have you download a new GoogleService-Info.plist.
2 causes, each with a fixMobile apps
Scheduled flutter_local_notifications never appear when the app is closed
zonedSchedule does nothing, with no error shown
Local notifications are scheduled with the system, so they should fire while the app is closed.
5 causes, each with a fixMobile apps
flutter_local_notifications throws ArgumentError: iOS settings must be set
Android settings must be set when targeting Android platform.
The plugin's initialize call checks that InitializationSettings holds settings for the platform the app is running on.
3 causes, each with a fixMobile apps
Flutter cannot open a file: OS Error No such file or directory
FileSystemException: Cannot open file, path = '...' (OS Error: No such file or directory, errno = 2)
Errno 2 means the exact path you gave does not exist on the device.
3 causes, each with a fixMobile apps
flutter_tts does not speak, or stops early, on Android or iOS
Text to speech works on one phone but not on another
Check platform setup first.
5 causes, each with a fix