Unable to load image if there is a space in path or name file Flutter

Viewed 3404

I have a problem with a load dynamically an Asset image.

I have an image and I'm trying to load with:

new AssetImage(img_path)

The img_path is:

/storage/emulated/0/WhatsApp/Media/WhatsApp Images/test.jpg

And it return:

(27161): Another exception was thrown: Unable to load asset: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/test.jpg

If i try to move my file for example in

/storage/emulated/0/WhatsApp/Media/test.jpg

It works.

But not if I change name of my file with space for example:

/storage/emulated/0/WhatsApp/Media/test with space.jpg

So I guess that It can be a problem with a space in path.

How can I solve this?

2 Answers

If you want to show the image as a Widget, FileImage() doesn't work so you need to use Image.file() like this:

...

Image.file(File('/storage/emulated/0/lilop_app/native_screenshot-20211107163229.png'), width: 100),

...

Related