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.