问题
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
Dart File
SizedBox(height: 30.0),
Text(
'Connect with Mentors',
style: TextStyle(
fontFamily: 'Gilroy',
fontSize: 35.0,
),
),
回答1:
As mentioned in the flutter website: https://flutter.dev/docs/cookbook/design/fonts
Folder Structure:
your_app/
fonts/
Raleway-Regular.ttf
Raleway-Italic.ttf
RobotoMono-Regular.ttf
RobotoMono-Bold.ttf
Declare in 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 !
来源:https://stackoverflow.com/questions/59113295/flutter-custom-font-not-getting-applied