LorenzoBerti
LorenzoBerti

Reputation: 6974

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

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?

Upvotes: 5

Views: 3943

Answers (2)

Mohsen Emami
Mohsen Emami

Reputation: 3172

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),

...

Upvotes: 0

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658155

I assume this is what you actually want

new FileImage(
    new File('/storage/emulated/0/WhatsApp/Media/WhatsApp Images/test.jpg')
)

See also https://docs.flutter.io/flutter/painting/FileImage-class.html

Upvotes: 11

Related Questions