如果路径或名称文件中有空格,则无法加载图像 [英] Unable to load image if there is a space in path or name file Flutter

查看:230
本文介绍了如果路径或名称文件中有空格,则无法加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在动态加载资源图片时遇到问题.

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)

img_path是:

The img_path is:

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

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

返回:

(27161):引发了另一个异常:无法加载资产: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/test.jpg

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

例如,如果我尝试在

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

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

有效.

但是如果我用空格更改文件名,则不会:

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

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

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

所以我想这可能是路径中有空格的问题.

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

我该如何解决?

推荐答案

我认为这是您真正想要的

I assume this is what you actually want

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

另请参见 https://docs.flutter.io/flutter/painting/FileImage-class.html

这篇关于如果路径或名称文件中有空格,则无法加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆