错误:无法在pubspec.yaml中找到资产条目:“ assets / fonts / Lato-Regular.ttf”; [英] Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf"

查看:721
本文介绍了错误:无法在pubspec.yaml中找到资产条目:“ assets / fonts / Lato-Regular.ttf”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我写这篇文章之前,我到处搜索了我的错误,但是却什么也没找到。

Before I wrote this, I searched everywhere for my mistake, but I didn't find anything.

尽管我正确无误,并在pubspec中写下了这些内容。 yaml文件,我在调试控制台中收到此错误:

although I have everything correctly and written down in the pubspec.yaml file, I get this error in the debug console:

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf".
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf".
Exited (sigterm)

我的pubspec.yaml文件如下所示:

my pubspec.yaml file looks like this:

name: shopping_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

  # 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:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - 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: Lato
      fonts:
        - asset: assets/fonts/Lato-Regular.ttf
        - asset: assets/fonts/Lato-Bold.ttf
          weight: 700
    - family: Anton
      fonts:
        - asset: assets/fonts/Anton-Regular.ttf
  #   - 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

这是字体在其中的路径:

here is the path where the fonts are inside:

路径屏幕截图

您能帮我吗?
我只是找不到解决方法

Can you help me maybe? I just can't find a solution

最诚挚的问候

推荐答案

资产文件夹应位于根路径(/)中。如果要将其保留在 lib 文件夹中,请将 lib 放在这样的资产前面:

The assets folder should be in the root path (/). If you want to keep it in the lib folder, put lib in front of assets like this:

//new path
lib/assets/fonts/Lato-Regular.ttf

旁注:为避免必须手动导入字体,建议使用 google_fonts 软件包。它具有包括Lato在内的数百种字体,您可以使用 GoogleFonts.lato()访问它,以获取默认的 TextStyle 与Lato字体,而不必通过 pubspec.yml 文件导入。

Sidenote: To avoid having to import fonts manually, I recommend the google_fonts package. It has hundreds of fonts including Lato and you can access it with GoogleFonts.lato() to get a default TextStyle with the Lato font without having to import it via the pubspec.yml file.

这篇关于错误:无法在pubspec.yaml中找到资产条目:“ assets / fonts / Lato-Regular.ttf”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆