扑灭资产

问题描述 投票:1回答:3

我是Flutter的初学者,尝试将图像放置在我的一个小部件中,但出现以下错误:

The following assertion was thrown resolving an image codec:
Unable to load asset: ../w.png

When the exception was thrown, this was the stack
#0      PlatformAssetBundle.load 
package:flutter/…/services/asset_bundle.dart:221
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync 
package:flutter/…/painting/image_provider.dart:484
#2      AssetBundleImageProvider.load 
package:flutter/…/painting/image_provider.dart:469
#3      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> 
package:flutter/…/painting/image_provider.dart:327
...
Image provider: AssetImage(bundle: null, name: "../w.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#767fa(), name: "../w.png", scale: 1.0)

pubspec.yaml:

enter image description here

我的文件夹:

enter image description here

transactionlist.dart

// new Image(image: AssetImage('../../w.png'),width: 300,height: 100,),
Image.asset('../../images/w.png'),

我尝试了StackOverflow的许多解决方案,但没有一个对我有用。使用Flutter Clean,Cold Boot android模拟器,检查一千次YAML文件,重命名文件,但不幸的是,它们都没有帮助我修复它。如果有人有解决此问题的方法,我将非常感谢。

flutter assets
3个回答
3
投票

您知道,标识对于yaml文件夹很重要。我检查了pubspec.yaml文件夹,并且文件夹中assets下方没有空格。在pubspec.yaml中进行更改后,请重新启动它。


1
投票

添加资产后您是否运行flutter软件包获取命令?


0
投票

非常感谢你们俩,我的问题通过小部件内Image的更改路径解决了。

© www.soinside.com 2019 - 2024. All rights reserved.