flutter

iOS app crashes when opening image gallery using image_picker


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.


Solution

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