在pubspec.yaml的flutter中未找到图像文件

llycmphe  于 2023-06-07  发布在  Flutter
关注(0)|答案(5)|浏览(465)

当我尝试从assets/images文件夹中加载image时,它显示
对不起,您访问的页面不存在。尝试创建文件或修复文件的路径。
但文件在那里。我已经检查了目录手动通过文件资源管理器了。

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
gorkyyrv

gorkyyrv1#

问题是由于缩进。尝试使用pubspec文件的重新格式化,它将完美地工作。

eulz3vhy

eulz3vhy2#

我通过在单词“asserts”前加两个空格,在横线前加三个空格,在横线后加一个空格来解决这个问题。以这种方式:

ogq8wdun

ogq8wdun3#

如果您使用Windows而不是macOS,请尝试使用带反斜杠的文件路径。例如"assets\fonts\Quicksand-Regular.ttf"而不是"assets/fonts/Quicksand-Regular.ttf"

yjghlzjz

yjghlzjz4#

试试这个:

flutter:
  assets:
    -android/assests/directory/
i2byvkas

i2byvkas5#

检查pubspec. yaml中资源的缩进。它通常应该从资产前的新行开始2个空格,从新行开始3个空格,加上一个-和1个空格,然后是资产的路径。如果它仍然不起作用,只需关闭代码编辑器并重新打开它。

相关问题