title: Flutter load image asset with image file
body: <p>I have a page to allow a user to post something, which includes an image. When the page loads, it loads a <code>default.png</code> image and when the user clicks on it, the user is redirected to another page where they can take a picture or choose from a gallery.</p>
  <p>The main issue here is that when <code>my post an item page</code> loads it looks at the <code>Image.asset</code> and see's null. Therefore, <code>Image.asset</code> is able to load the <code>defaultImage</code>, BUT when the user chooses an image or takes a picture the value that is returned is a <code>File</code> and with the <code>path</code> attached to it makes it into a <code>String</code> (as seen below)</p>
  <pre><code>child: Image.asset(
                      imageName1?.path ?? defaultImage,
                      fit: BoxFit.cover,
                    ),
  </code></pre>
  <p>So, <code>Image.asset</code> is not able to load this <code>File.path</code></p>
  <p>This is the error that I get:</p>
  <pre><code>Exception has occurred.
  FlutterError (Unable to load asset: /data/user/0/com.flutter_project/cache/image_picker4920072427102948834.jpg)
  </code></pre>
  <p>I know that <code>Image.file</code> works with <code>file.path</code>... but do I really need to make an if statement somewhere to ensure proper image display?</p>
  <p>Is there some simpler way?</p>
  <p>Extra note: when I do a refresh in my visual studio (while my app is running) the image actually loads (as it should)... very weird...
  my page is <code>stateful</code> and when I pass the <code>result</code> (the file from the popped page) I do a <code>setstate</code> to <code>imageName1</code></p>
  <pre><code>final result = await Navigator.push(
  context,
  MaterialPageRoute(builder: (context) =&gt; PhotoPreviewPage()),
  );
  
  setState(() {
  imageName1 = result;
  });
  </code></pre>