无法加载资源:图像

发布于 2025-01-19 09:20:08 字数 804 浏览 0 评论 0原文

我有这个资产图像代码,

 Image.asset(
              '${listPic[1]}',
           
            ),

图像位于列表中
最终列表<图像> listPic= [ Image.asset('assets/images/pic1.jpg'), Image.asset('assets/images/pic2.jpg'), ];

我知道 pubsec 有效,因为当我像这样直接输入图像位置时,

Image.asset(
              'assets/images/pic1.jpg',
            ),

图像就会显示, 列表或 Image.asset() 是否有问题 我尝试在 ${listPic[0]} 之后使用 .toString 它没有做任何事情而是说不必要的字符串插值。

给出这个错误

The following assertion was thrown resolving an image codec: Unable to load asset: Image(image: AssetImage(bundle: null, name: "assets/images/pic1.jpg"), frameBuilder: null, loadingBuilder: null, alignment: Alignment.center, this.excludeFromSemantics: false, filterQuality: low)

I have this code for asset image

 Image.asset(
              '${listPic[1]}',
           
            ),

the images are located in a List
final List<Image> listPic= <Image>[ Image.asset('assets/images/pic1.jpg'), Image.asset('assets/images/pic2.jpg'), ];

I know the pubsec works, because when I directly type the image location like this

Image.asset(
              'assets/images/pic1.jpg',
            ),

the image is displayed,
Is there something wrong with the list or Image.asset()
I have tried using .toString after the ${listPic[0]} it didn't do anything instead said unnecessary string interpolation.

gives this error

The following assertion was thrown resolving an image codec: Unable to load asset: Image(image: AssetImage(bundle: null, name: "assets/images/pic1.jpg"), frameBuilder: null, loadingBuilder: null, alignment: Alignment.center, this.excludeFromSemantics: false, filterQuality: low)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野の 2025-01-26 09:20:08

您声明的列表是list&lt; image&gt;类型,但您正在使用它,就好像是list&lt; string&gt;

而是尝试一下:

final List<String> imagePaths = [ 
    'your/path/pic1.jpg', 
    'your/path/pic2.jpg',
];

Image.asset(
    toolImage[1],
)

The list you declared is a List<Image> type, but you are using it as if it's a List<String>.

Try this instead:

final List<String> imagePaths = [ 
    'your/path/pic1.jpg', 
    'your/path/pic2.jpg',
];

Image.asset(
    toolImage[1],
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文