android - 错误 : unable to locate asset entry in pubspec. yaml: "assets/fonts/Lato-Regular.ttf"

标签 android ios flutter dart cross-platform

在我写这篇文章之前,我到处寻找我的错误,但我没有找到任何东西。

尽管我在 pubspec.yaml 文件中正确记录了所有内容,但在调试控制台中出现此错误:

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 文件如下所示:
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

这是字体所在的路径:

path screenshot

你能帮我吗?
我只是找不到解决方案

此致

最佳答案

Assets 文件夹应位于根路径 (/) 中。如果你想把它保存在 lib文件夹,放lib在这样的 Assets 面前:

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

旁注:为避免手动导入字体,我推荐 google_fonts包裹。它有数百种字体,包括 Lato,您可以通过 GoogleFonts.lato() 访问它获取默认值 TextStyle使用 Lato 字体,无需通过 pubspec.yml 导入文件。

关于android - 错误 : unable to locate asset entry in pubspec. yaml: "assets/fonts/Lato-Regular.ttf",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59432187/

相关文章:

android - Firestore 数据的仪表板?

ios - Swift 4 和 Firebase 中的信号量建议

flutter - Flutter 不应该根据设计缩小或放大图像和文本吗?为什么我看到很大的不同?

ios - 如何在越狱的 iOS 5 中启用 ChatKit CKMadridService?

flutter - Flutter将带有数组子对象和对象的json转换为类映射

firebase - Firestore查询不会因Geo flutter 火而返回附近的位置

Android 应用程序崩溃,因为共享库无法适应/系统

java - 检查 Firebase 中是否存在值有一个奇怪的问题

java - BodyEditorLoader - 读取文件时出错

ios - 以编程方式显示导航栏的 UISearchController