【问题标题】:Flutter : image not being found [duplicate]颤振:找不到图像[重复]
【发布时间】:2021-07-19 01:10:03
【问题描述】:

这是我的小部件,用于在应用中显示我自己的小照片。

Widget image() {
    return CircleAvatar(
      radius: 50.0,
      backgroundImage: AssetImage('images/me.jpeg'),
    );
  }

然而,出于某种原因,我不断收到这个

The following assertion was thrown resolving an image codec:
Unable to load asset: images/me.jpeg

When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:225:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:668:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:651:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:504:13)
...
Image provider: AssetImage(bundle: null, name: "images/me.jpeg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#14309(), name: "images/me.jpeg", scale: 1.0)

虽然图片在文件夹中。请帮忙

【问题讨论】:

  • 您是否将图像路径添加到 pubspec.ymal 文件中?

标签: flutter assets


【解决方案1】:

确保将图像添加到 pubspec.yaml 文件中,然后运行 ​​pub get

  assets:
    - images/me.jpeg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-18
    • 2021-01-06
    • 1970-01-01
    • 2021-05-24
    • 2020-02-09
    • 2022-01-08
    • 2021-07-04
    • 2020-10-21
    相关资源
    最近更新 更多