Flutter自定义字体未应用 [英] Flutter custom font not getting applied
本文介绍了Flutter自定义字体未应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Flutter
中为我的 Text
设置自定义字体.我已经尝试了所有我知道的东西,但是没有用.这是bug还是什么?
Am trying to set a custom font to my Text
in Flutter
. I have tried everything I know but it didn't work. Is this a bug or something?
flutter:
uses-material-design: true
assets:
- assets/images/onboarding1.png
- assets/images/onboarding2.png
- assets/images/onboarding3.png
fonts:
- family: Gilroy
fonts:
- asset: assets/fonts/gilroy_extrabold.otf
飞镖文件
SizedBox(height: 30.0),
Text(
'Connect with Mentors',
style: TextStyle(
fontFamily: 'Gilroy',
fontSize: 35.0,
),
),
推荐答案
As mentioned in the flutter website: https://flutter.dev/docs/cookbook/design/fonts
文件夹结构:
your_app/
fonts/
Raleway-Regular.ttf
Raleway-Italic.ttf
RobotoMono-Regular.ttf
RobotoMono-Bold.ttf
在pubspec.yaml中声明:
flutter:
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
- asset: fonts/Raleway-Italic.ttf
style: italic
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Regular.ttf
- asset: fonts/RobotoMono-Bold.ttf
weight: 700
您在声明时使用资产前缀,我认为这是问题所在!
You are using asset prefix while declaring, I think it's the problem !
这篇关于Flutter自定义字体未应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文