Imesh Jeewantha
Imesh Jeewantha

Reputation: 21

The flutter image_picker plugin restarts the app every time when an image is picked on Redmi Note 9

This happens only in Redmi Note 9. I've read the image_picker documentation and it says this occurs when there is not enough memory in the device and it causes to restart of the MainActivity in the Flutter app. But the device has enough memory.

Is there any fix or any alternatives for this package?

Upvotes: 1

Views: 405

Answers (2)

smita
smita

Reputation: 161

I have used image_pickers package.

Future<File> getImage() async {
 List<Media> _listImagePaths = [];
 _listImagePaths = await ImagePickers.pickerPaths(
              galleryMode: GalleryMode.image,
              showGif: true,
              selectCount: 1,
              showCamera: true,
              cropConfig:
                  CropConfig(enableCrop: false),
              compressSize: 500,
              uiConfig: UIConfig(
                uiThemeColor: Colors.orange,
              ),
            );
  File pickedFiles=File(_listImagePaths[0].path!);
  return pickedFiles;
}

Upvotes: 0

Sumit Banwakade
Sumit Banwakade

Reputation: 179

Try This sample of Code, this worked for me:

Code :

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

Upvotes: 0

Related Questions