I am pulling an image from my gallery using ImagePicker like so:
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);
}
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:
Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
image: DecorationImage(
image: _image == null ? backgroundImage : FileImage(_image),
fit: BoxFit.fill,
),
),
),
The issue is that I cannot seem to get the string value of customImageFile to actually load the image properly.
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:
File: '/storage/emulated/0/Download/images.jpeg'
Instead of just:
'/storage/emulated/0/Download/images.jpeg'
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.
UPDATE: Have managed to reduce the string to:
'/storage/emulated/0/Download/images.jpeg'
By using:
customImageFile = customImageFile.substring(6);
But it now shows me this error:
Cannot open file, path = ''/storage/emulated/0/Download/images.jpeg'' (OS Error: No such file
So I can increase the substring value to 7 to remove the first apostrophe, how do I remove the last character of the String?