How to solve the image picker crash app error?

Issue

I have a app crash when i’m picking a image. i’m using image_picker:0.5.0+7
with any ImageSource it’s crash the app.

File _fileState;

Future getImage(ImageSource imageSource) async{
  // using your method of getting an image
  final File image = await ImagePicker.pickImage(source: imageSource);

  print("path:: ");
  setState(() {
   // print("path:: "+image.path);
    _fileState = image;
  });

}

Shutting down VM
E/AndroidRuntime(16049): FATAL EXCEPTION: main
E/AndroidRuntime(16049): Process: com.grain.test_camera, PID: 16049
E/AndroidRuntime(16049): java.lang.RuntimeException: Unable to resume activity
{com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.RuntimeException: Failure deliver
ing result ResultInfo{who=null, request=2342, result=-1, data=Intent {
dat=content://com.android.providers.media.documents/document/image:25272
flg=0x1 }} to activity {com.grain.test
_camera/com.grain.test_camera.MainActivity}: java.lang.IllegalStateException: Received image from picker that was
not requested
E/AndroidRuntime(16049): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3506)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795)
E/AndroidRuntime(16049): at android.app.ActivityThread.-wrap12(ActivityThread.java)
E/AndroidRuntime(16049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
E/AndroidRuntime(16049): at android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime(16049): at android.os.Looper.loop(Looper.java:203)
E/AndroidRuntime(16049): at android.app.ActivityThread.main(ActivityThread.java:6251)
E/AndroidRuntime(16049): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
E/AndroidRuntime(16049): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342,
result=-1, data=Intent { dat=content://com.android.provid
ers.media.documents/document/image:25272 flg=0x1 }} to activity {com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.IllegalStateException: Received image from picke
r that was not requested

I do not know what I can do please help me

Solution

It seems image_picker documentation has been updated.

You would have to use retrieveLostData when the app restarts (migrate to AndroidX else you may get a force close error)

Future<void> retrieveLostData() async {
    final LostDataResponse response = await ImagePicker.retrieveLostData();
    if (response == null) {
        return;
    }
    if (response.file != null) {
        setState(() {
            if (response.type == RetrieveType.video) {
                _handleVideo(response.file);
            } else {
                _handleImage(response.file);
            }
        });
    } else {
        _handleError(response.exception);
    }
}

Answered By – riftninja

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published