Flutter - Custom Font not displaying

前端 未结 12 2091
感动是毒
感动是毒 2021-01-03 20:11

This is an excerpt of my pubspec.yaml file:

flutter:
  uses-material-design: true
  fonts:
   - family: Coiny
     fonts:
       - asset: fonts/Coiny-Regular         


        
相关标签:
12条回答
  • 2021-01-03 20:36

    Font declaration alignment is not as per flutter pubspec.yaml. It should be like below.

    fonts:
          - family: Coiny
            fonts:
              - asset: fonts/Coiny-Regular.ttf
    

    You can check out it here.

    0 讨论(0)
  • 2021-01-03 20:37

    I had font: not right under flutter:. I moved the font: section right under flutter: , and worked.

    flutter:
    
      fonts:
        - family: Test
          fonts:
          - asset: assets/fonts/Font-Test.ttf
    
    0 讨论(0)
  • 2021-01-03 20:47

    Whenever you make changes to pubspec.yaml file, it is always a good idea to stop the ongoing dart process from your IDE and do a full restart.

    If you do hot reload or hot restart, engine may not be able to fetch the newly added data to your file. If nothing works, you should use @Collin answer, uninstall and reinstall the app.

    0 讨论(0)
  • 2021-01-03 20:48

    I had an issue with the font and was receiving these two warnings:

    Warning: No fonts specified for font [font family name]
    Warning: Missing family name for font.
    

    The issue was that I had the pubspec.yaml fonts section typed incorrectly.

    Make sure your pubspec.yaml looks like this:

    flutter:
    
      fonts:
        - family: FontFamily
          fonts:
          - asset: fonts/Font-Medium.ttf
    
      uses-material-design: true
    

    You will then need to flutter clean and then flutter pub get. If all of this fails, try to uninstall the app and then reinstall it again (as Collin states above) after doing the above.

    I had a "-" next to the nested fonts declaration, which was causing those errors (and the font not to work).

    0 讨论(0)
  • 2021-01-03 20:49

    set in pubspec.yaml

     fonts:
      - family: Montserrat
        fonts:
          - asset: assets/fonts/Montserrat-Regular.ttf
          - asset: assets/fonts/Montserrat-Bold.ttf
    
    
        and then make sure that clean and build
    
    0 讨论(0)
  • 2021-01-03 20:52

    You have add new files in the app therefore you have to close the running device and then restart the emulator.

    -stop a running emulator -run a emulator

    It works in my case.

    0 讨论(0)
提交回复
热议问题