firebase 找不到图像?无法显示图像

wqlqzqxt  于 2022-11-17  发布在  其他
关注(0)|答案(2)|浏览(199)

我在两个不同的项目中有这个片段,由于某种原因,它在我当前的项目中不起作用:

Padding(
              padding: const EdgeInsets.only(left: 80, right: 80),
              child: Image.asset('assets/images/logo.png'),
            ),

下面是文件的结构

下面的错误表示未找到资产?
我还试图将图像移动到同一个文件中,但没有工作

════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/logo.png.

When the exception was thrown, this was the stack
#0      PlatformAssetBundle.loadBuffer
#1      AssetBundleImageProvider._loadAsync
#2      AssetBundleImageProvider.loadBuffer
#3      ImageProvider.resolveStreamForKey.<anonymous closure>
#4      ImageCache.putIfAbsent
#5      ImageProvider.resolveStreamForKey
#6      ScrollAwareImageProvider.resolveStreamForKey
#7      ImageProvider.resolve.<anonymous closure>
#8      ImageProvider._createErrorHandlerAndKey.<anonymous closure>
#9      SynchronousFuture.then
#10     ImageProvider._createErrorHandlerAndKey
#11     ImageProvider.resolve
#12     _ImageState._resolveImage
#13     _ImageState.reassemble
#14     StatefulElement.reassemble
#15     Element.reassemble.<anonymous closure>
#16     SingleChildRenderObjectElement.visitChildren
#17     Element.reassemble
#18     Element.reassemble.<anonymous closure>
#19     SingleChildRenderObjectElement.visitChildren
#20     Element.reassemble
#21     Element.reassemble.<anonymous closure>
#22     SingleChildRenderObjectElement.visitChildren
....
....
...
#595    BindingBase.registerSignalServiceExtension.<anonymous closure>
#596    BindingBase.registerServiceExtension.<anonymous closure>
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "assets/images/logo.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#3359f(), name: "assets/images/logo.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
Reloaded 1 of 1363 libraries in 356ms (compile: 20 ms, reload: 128 ms, reassemble: 177 ms).
D/EGL_emulation( 6231): app_time_stats: avg=1439.65ms min=27.34ms max=2851.96ms count=2

════════ Exception caught by image resource service ════════════════════════════
Unable to load asset: assets/images/logo.png.
════════════════════════════════════════════════════════════════════════════════

这是pubspec.yaml文件::资源:- lib/资源/图像/ -lib/资源/图像/徽标. png

rkue9o1l

rkue9o1l1#

在您的pubspec.yaml文件中,您必须将图像添加为资源

assets:
    - assets/images/logo.png

然后你需要重新运行你的flutter应用程序,以加载图像。不要只重新加载,你的资产将不会加载。

gfttwv5a

gfttwv5a2#

视图中的元素应具有以下路径:

Padding(
              padding: const EdgeInsets.only(left: 80, right: 80),
              child: Image.asset('lib/assets/images/logo.png'),
            ),

我错过了“lib/”部分

相关问题