简体   繁体   中英

Custom 'fontFamily' is not working in Flutter

I am a fresher for 'Flutter' and I tried to add a new font family from google fonts to my app. I followed these steps.

  1. Download google font (IndieFlower-Regular.ttf)

  2. Created a folder 'fonts' in the root directory and copied the.tff file.

  3. Added it to pubspec.yaml file and get dependencies.

  4. Added into.dart file as follows

    style: TextStyle( color: Colors.black87, fontSize: 25.0, fontFamily: 'IndieFlower'), ), https://github.com/ChkBuk/FlutterPlayground/tree/master

But when run the application, its font family does not apply. Can anybody help with this issue?

as per your yaml file, you are adding font in the root, but it should be coming inside assets section

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

in actual, it should be used like below

assets
  - fonts:
    - family: IndieFlower
      fonts:
        - asset: fonts/IndieFlower-Regular.ttf

If you get an error after doing all the necessary things, its the font family, flutter allows only some fonts in app, I don't the main reason, for my app, I needed Bench nine font family but after doing all the necessary things, it did not work, I search too, but then I found the same reason above I written, Change font family

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM