Selecting image from Gallery or Camera in Flutter
The crash could be due to camera permission. Image picker
plugin has removed the camera permission condition. When we access camera, app asks us for permission, but this condition in not supported anymore. We need to ask the permission manually using permission_handler
plugin. Read more details about this change here and see this link on how to add runtime permission using permission_handler
. Hope this resolves your issue.

Doing Things Occasionally
Doing Things Occasionally. Like coding shit.
Updated on December 10, 2022Comments
-
Doing Things Occasionally 6 minutes
I am trying to give users a method to add a photo from their gallery or their camera but, flutter keeps crashing after the button is pressed.
I've implemented the image picker dependency as well as Dart:io, migrated to Android X but, still no luck. Here is some of my code:
class _PreferencesState extends State<_Preferences> with TickerProviderStateMixin { File _image; getImage(bool isCamera) async { File image; if (isCamera) { image = await ImagePicker.pickImage(source: ImageSource.camera); } else { image = await ImagePicker.pickImage(source: ImageSource.gallery); } setState(() { _image = image; }); }
Then called here:
FlatButton( textColor: Theme.of(context).primaryColor, child: Text('Use Camera'), onPressed: () { getImage(true); }, ), _image == null ? Container() : Image.file( _image, height: 300, width: 300, ),
Every time I call the method I get this error:
Exception has occurred. PlatformException (PlatformException(error, Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference, null))
I thought I changed the image type from null so it wouldn't be called but, I'm not sure what else to do here.