title: Selecting image from Gallery or Camera in Flutter
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>class _PreferencesState extends State&lt;_Preferences&gt;
      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;
    });
  }
  </code></pre>
  
  <p>Then called here:</p>
  
  <pre><code>  FlatButton(
        textColor: Theme.of(context).primaryColor,
        child: Text('Use Camera'),
        onPressed: () {
            getImage(true);
        },
    ),
    _image == null
        ? Container()
        : Image.file(
            _image,
            height: 300,
            width: 300,
        ),    
  </code></pre>
  
  <p>Every time I call the method I get this error:</p>
  
  <blockquote>
    <p>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))</p>
  </blockquote>
  
  <p>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. </p>