title: Flutter: Display image from URI string or File object
body: <p>I am pulling an image from my gallery using ImagePicker like so:</p>
  
  <pre><code>ImageProvider backgroundImage;
  String customImageFile;
  File _image;
  
  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
  
    setState(() {
      _image = image;
    });
  
    customImageFile = _image.toString();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('customImageFile', customImageFile);
  }
  </code></pre>
  
  <p>As you can see I am trying to store the URI of the image file into SharedPreferences, for persistence, and I am displaying it in my application like this:</p>
  
  <pre><code>Container(
    decoration: BoxDecoration(
      color: Colors.blueAccent,
        image: DecorationImage(
          image: _image == null ? backgroundImage :  FileImage(_image),
          fit: BoxFit.fill,
        ),
      ),
  ),
  </code></pre>
  
  <p>The issue is that I cannot seem to get the string value of customImageFile to actually load the image properly.</p>
  
  <p>EDIT:    Actually, I may have stumbled upon the cause, I hadn't noticed this until I used a print dump of the string.   The actual string comes out to be this:</p>
  
  <pre><code>File: '/storage/emulated/0/Download/images.jpeg'
  </code></pre>
  
  <p>Instead of just:</p>
  
  <pre><code>'/storage/emulated/0/Download/images.jpeg'
  </code></pre>
  
  <p>It may just work if I can play with the String here.   I am having trouble finding anything online about how to ignore the first 6 characters of a String.   Was quite easy to do this in Java and in Visual Basic, but I can't find the method.</p>
  
  <p>UPDATE: Have managed to reduce the string to:</p>
  
  <pre><code>'/storage/emulated/0/Download/images.jpeg'
  </code></pre>
  
  <p>By using: </p>
  
  <pre><code>customImageFile = customImageFile.substring(6);
  </code></pre>
  
  <p>But it now shows me this error:</p>
  
  <pre><code>Cannot open file, path = ''/storage/emulated/0/Download/images.jpeg'' (OS Error: No such file
  </code></pre>
  
  <p>So I can increase the substring value to 7 to remove the first apostrophe, how do I remove the last character of the String?</p>