【问题标题】:image file not found in flutter in pubspec.yaml在 pubspec.yaml 的颤振中找不到图像文件
【发布时间】:2020-04-04 09:28:03
【问题描述】:

当我尝试从 assets/images 文件夹加载图像时,它会显示

资产 assets/images/waiting.png 不存在。尝试创建文件或修复文件的路径。

但是文件在那里。我也通过文件资源管理器手动检查了目录。

flutter:
  uses-material-design: true
  assets:
    - assets/images/waiting.png

我尝试了很多,但它不起作用。这是一个错误还是什么?还是我的代码问题?

name: flutter_expense_app
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  intl: ^0.16.1

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  uses-material-design: true
  assets:
    - assets/images/waiting.png
  # - assets/images/waiting.png
  #- images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: OpenSans
      fonts:
        - asset: assets/fonts/OpenSans-Regular.ttf
        - asset: assets/fonts/OpenSans-Bold.ttf
          weight: 700
    - family: Quicksand
      fonts:
        - asset: assets/fonts/Quicksand-Regular.ttf
        - asset: assets/fonts/Quicksand-Bold.ttf
          weight: 700      
  #  - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

【问题讨论】:

  • 你能分享你的完整 Pubspec 吗?
  • 一分钟.....
  • Pubspec 看起来不错,你能分享一下你是如何尝试使用这张图片的吗?
  • 检查 pubspec.yaml 中资产的标识。它通常应该在换行符的 3 个空格后开始。
  • 您的资产文件夹是否位于项目的根目录?

标签: flutter flutter-dependencies


【解决方案1】:

问题是因为缩进。尝试使用重新格式化的 pubspec 文件,它将完美运行。

【讨论】:

    【解决方案2】:

    我通过在“断言”一词之前放置两个空格、在水平线之前放置三个空格、在它之后放置一个空格来解决这个问题。以这种方式:

    【讨论】:

      猜你喜欢
      • 2021-01-06
      • 1970-01-01
      • 2018-09-22
      • 2019-06-02
      • 2021-07-04
      • 2021-07-19
      • 1970-01-01
      • 2021-03-18
      • 2021-06-10
      相关资源
      最近更新 更多