我正在尝试在flutter中使用自定义字体。我已将字体放置在根目录下的“ fonts”文件夹中,该文件夹与pubspec.yaml文件位于同一级别
我还使用文档中的格式将字体添加到了pubspec.yaml中。完整档案:
name: app_name
description: app_description
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
rxdart: ^0.22.1+1
intl: ^0.15.7
dev_dependencies:
flutter_launcher_icons: "^0.7.2"
flutter_test:
sdk: flutter
flutter:
fonts:
- family: Lato
fonts:
- asset: /fonts/Lato-Regular.ttf
flutter_icons:
ios: true
android: true
image_path_ios: "lib/res/launcher/ic_launcher_iphone.png"
image_path_android: "lib/res/launcher/ic_launcher.png"
我仍然遇到上述错误
Error: unable to locate asset entry in pubspec.yaml: "/fonts/Lato-Regular.ttf".
答案 0 :(得分:2)
删除前导/
。 asset: /fonts/Lato-Regular.ttf
-> asset: fonts/Lato-Regular.ttf
确保字体文件夹位于项目的顶部文件夹中。