Flutter custom font not getting applied

给你一囗甜甜゛ 提交于 2020-02-05 04:18:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!