英文:
Flutter error on custom font : 'Error on line 78, column 4: Expected a key while parsing a block mapping.' in pubspec.yaml
问题
抱歉,我无法识别HTML实体并将其转换为文本。以下是您提供的文本的中文翻译:
"我是Flutter的新手,在尝试使用自定义字体时遇到了一个新错误。我查看了官方文档,甚至尝试复制那里的代码结构,但仍然不起作用。
这是错误消息:“在第78行,第4列上发生错误:在解析块映射时需要一个键。”
这是错误的截图:[自定义字体错误]
[![1]][1]
我尝试在pubspec.yaml中对行进行了缩进,但仍然不起作用。
这是我的pubspec.yaml文件:
# “family”键与字体系列名称以及包含字体资源和其他描述的“fonts”键。例如:
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
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
这是我的pubspec.yaml文件的截图,包含更多细节:
pubspec.yaml截图
[![2]][2]
任何帮助都将不胜感激。
<details>
<summary>英文:</summary>
i'm new to flutter and I face a new error when i was trying use a custome font. I see the official docs and even try to copy the codes structure from there, but it doesn't work either.
here is the error : "Error on line 78, column 4: Expected a key while parsing a block mapping."
and here is screenshot of error:[custom font error]
[![][1]][1]
[1]:https://i.stack.imgur.com/12fCR.png
I try to indent thr lines in pubspec.yaml but still dont work.
and here is my pubspec.yaml file :
"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: 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
- family: Trajan Pro
fonts:
- asset: fonts/TrajanPro.ttf
- asset: fonts/TrajanPro_Bold.ttf
weight: 700
and here is screenshot of my pubspec.yaml file with more details:
pubspec.yaml screenshot
[![][2]][2]
[2]:https://i.stack.imgur.com/G0xzn.png
any help will be appriaciated.
</details>
# 答案1
**得分**: 0
我找到了问题。问题出在我的字体文件夹地址上。
我在pubspec.yaml文件中写错了字体的地址。
<details>
<summary>英文:</summary>
I found the Problem. the problem was with the folder address of my fonts.
i wrote the the wrong address for fonts in pubspec.yaml file.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论