简体   繁体   English

自定义“fontFamily”在 Flutter 中不起作用

[英]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.我是 'Flutter' 的新手,我尝试将来自 google fonts 的新字体系列添加到我的应用程序中。 I followed these steps.我遵循了这些步骤。

  1. Download google font (IndieFlower-Regular.ttf)下载谷歌字体(IndieFlower-Regular.ttf)

  2. Created a folder 'fonts' in the root directory and copied the.tff file.在根目录中创建了一个文件夹“字体”并复制了 .tff 文件。

  3. Added it to pubspec.yaml file and get dependencies.将其添加到 pubspec.yaml 文件并获取依赖项。

  4. Added into.dart file as follows添加到.dart文件中如下

    style: TextStyle( color: Colors.black87, fontSize: 25.0, fontFamily: 'IndieFlower'), ), https://github.com/ChkBuk/FlutterPlayground/tree/master样式:TextStyle(颜色: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根据您的 yaml 文件,您在根目录中添加字体,但它应该进入资产部分

......
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如果在完成所有必要的事情后出现错误,它的字体系列,flutter 只允许应用程序中的一些 fonts,我不是主要原因,对于我的应用程序,我需要 Bench 9 字体系列,但在做了所有必要的事情之后,没用,我也搜了,后来发现和上面写的一样的原因,换字体系列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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