我尝试安装自定义字体,但是控制台告诉我pubspec.yaml文件中出现错误。 我收到的错误消息是:
flutter pub get 在pubspec.yaml中检测到错误: 字体下的意外关键资产((String))。 请在C:\ Users \ Divyansh \ Desktop \ Development \ flutter \ Expense_Planner \ pubspec.yaml中更正pubspec.yaml文件 退出代码1
这是我添加到pubspec.yaml文件中的部分:
fonts:
- family: OpenSans
fonts:
- asset: fonts/OpenSans-Regular.ttf
- asset: fonts/OpenSans-Bold.ttf
weight: 700
- family: Quicksand
fonts:
- asset: fonts/Quicksand-Regular.ttf
- asset: fonts/Quicksand-Bold.ttf
weight: 700
答案 0 :(得分:1)
您有一个错字“资产”,这是您更正的pubspec:
fonts:
- family: OpenSans
fonts:
- asset: fonts/OpenSans-Regular.ttf
- asset: fonts/OpenSans-Bold.ttf
weight: 700
- family: Quicksand
fonts:
- asset: fonts/Quicksand-Regular.ttf
- asset: fonts/Quicksand-Bold.ttf # You had a typo in this line
weight: 700
答案 1 :(得分:0)
除了@Guilherme提到的错字外,别忘了在 pubspec.yaml 文件中导入包含字体的文件夹:
# To add assets to your application, add an assets section, like this:
assets:
- folderThatContainsYourFonts/
答案 2 :(得分:-1)
我建议您通过抖动使用google_fonts pkg,而不要下载每种字体并将其放在pubsec.yaml文件中。