我正在尝试向Flutter应用添加自定义字体,但出现此错误Unexpected child "assets.fonts" found under "flutter".
我的字体当前位于lib/assets/fonts
,而我的pubspec.yaml
如下:
name: idk
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets.fonts:
- family: Beautiful People
assets.fonts:
- asset: assets.fonts/BeautifulPeoplePersonalUse-dE0g.ttf
- asset: assets.fonts/BeautifulPeoplePersonalUse-PYP2.ttf
style: italic
该应用程序运行良好,没有assets.fonts
位,有人知道我在做什么错吗?
答案 0 :(得分:1)
问题似乎是 assets.fonts 用作pubspec.yaml中的键,当它应该只是 fonts 时,也应该是< strong>资产/字体/...。
这是启示性的部分:
flutter:
uses-material-design: true
fonts:
- family: Beautiful People
fonts:
- asset: assets/fonts/BeautifulPeoplePersonalUse-dE0g.ttf
- asset: assets/fonts/BeautifulPeoplePersonalUse-PYP2.ttf
style: italic
请参考:Use a custom font,如果您有任何格式问题,请将该示例复制并粘贴到其中,然后替换为您的值。