【问题标题】:flutter unable to load svg resource颤振无法加载svg资源
【发布时间】:2019-02-15 21:23:48
【问题描述】:

我正在使用 flutter_svg(版本 0.10.3)包在我的应用程序中加载 svg。但它向我显示一个错误,说它无法加载资源。 这是我的代码

static final Map<Gender, String> _genderImage = {
Gender.female: 'assets/images/gender_female.svg',
Gender.other: 'assets/images/gender_other.svg',
Gender.male: 'assets/images/gender_male.svg'
};
Widget icon = Padding(
    padding: EdgeInsets.only(left: _leftPadding(context)),
    child: SvgPicture.asset(
      _assetName,
      height: _iconSize(context),
      width: _iconSize(context),
    ));

这是错误: 抛出了另一个异常:无法加载资产:assets/images/gender_male.svg

【问题讨论】:

  • 您是否已将它们添加到pubspec.yaml
  • 否,但我认为我正在使用的软件包没有必要
  • 很确定是:-)
  • 是的,你是对的。谢谢

标签: dart flutter


【解决方案1】:

将资产添加到 pubspec.yaml 是必要的,因为 Flutter 使用位于项目根目录的 pubspec.yaml 文件来识别应用所需的资产。 p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 2021-12-22
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    相关资源
    最近更新 更多