How to solve the image picker crash app error?

前端 未结 4 1720
走了就别回头了
走了就别回头了 2021-01-14 12:41

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 getIm         


        
相关标签:
4条回答
  • 2021-01-14 13:10

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-14 13:14

    It may be related to AndroidX compability. You have to avoid AndroidX or migrate your project to AndroidX.

    There were a breaking change after version 0.5.0

    0 讨论(0)
  • 2021-01-14 13:14

    I found out that in developer mode, phone close main activity of flutter because of an option in developer options this comment from author of package is

    On Android, the MainActivity can be killed and restarted after launching the image picker for various of reasons. this can be tested by selecting `don't keep activities alive' option in the developer options in phone's setting app.

    then when I disable this option I get result in every device that I checked. link of this description is here. I hope it works for you.

    0 讨论(0)
  • 2021-01-14 13:20

    image_picker plugin does not support camera permission condition anymore. For instance, when we try to access camera from an app, the app asks us for permission. Now, since image_picker plugin has removed that condition, we need to ask the permission manually using permission_handler plugin. Read more details about this change here

    Use this plugin to add the request manually ie runtime and you should be able to get rid of this crash.

    0 讨论(0)
提交回复
热议问题