Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app crashes when opening image gallery using image_picker

Tags:

flutter

I'm trying to write a feature that allows a user to select an image from their gallery on iOS. I'm able to capture the image from the camera, but when I try to do the same from the image gallery, my app crashes.

I made sure that I'm using the latest version of the plugin (0.6.0), and have tried running the app both in the simulator and on my iOS device. I'm currently using an iPhone 8 simulator running iOS 12.4, and my device is an iPhone 7+, also on iOS 12.4

// opens the camera for use, works as expected
// does not currently store the image anywhere, but I know why

  void _showCamera() async {
    var picture = await ImagePicker.pickImage(
      source: ImageSource.camera
    );
  }
// this code crashes
  void _showImageGallery() async {
    var picture = await ImagePicker.pickImage(
      source: ImageSource.gallery
    );
  }

If I call _showCamera() from my onTap: callback, the camera opens without issue. When I call _showImageGallery() from the exact same onTap: callback, the app crashes. I'd expect it to work the same since they're otherwise identical functions.

like image 604
Luke Avatar asked Jun 14 '19 14:06

Luke


2 Answers

I think you missed adding the NSPhotoLibraryUsageDescription to the info.plist file

like image 162
Sergio Bernal Avatar answered Oct 25 '22 16:10

Sergio Bernal


This issue exists on flutter stable channel. Switch to flutter beta channel to resolve this issue. Use this command to switch the flutter channel:

flutter channel beta
like image 32
Rachit Rawat Avatar answered Oct 25 '22 16:10

Rachit Rawat