0

I'm trying to show Chinese characters in my Flutter web app with Chinese font. Something like this.

enter image description here

After downloading the font ttf file, I applied it to my Chinese characters, but it doesn't seem to work.

Here is how I apply my styling.

Text(
    "你好",
    style: TextStyle(
        fontFamily: "Chinese",
        fontSize: 70,
        color: Color.fromARGB(255, 234, 222, 218)
    ),
)

This is my pubspec.yaml file.

fonts:
    - family: Chinese
      fonts:
      - asset: assets\fonts\MaShanZheng-Regular.ttf

The result. enter image description here

How do I solve this? Much appreciated :)

InvalidHop
  • 104
  • 1
  • 10
  • Does this answer your question? [How to change the default font family in Flutter](https://stackoverflow.com/questions/64237031/how-to-change-the-default-font-family-in-flutter) – OMi Shah Oct 06 '22 at 09:16
  • I would probably have missed out on the indentation in the pubspec file if it weren't for @mohammad esmaili answer. – InvalidHop Oct 08 '22 at 02:27

1 Answers1

3

Pubspec is very sensitive about indentation:

  fonts:
    - family: Chinese
      fonts:
        - asset: assets\fonts\MaShanZheng-Regular.ttf
        

Make sure you have the right path too and got the font

mohammad esmaili
  • 1,614
  • 2
  • 4
  • 17
  • This worked! However, I noticed I also did the same thing for other fonts for English characters. But those fonts were able to be applied, why is that? – InvalidHop Oct 07 '22 at 06:53
  • well i think the fonts are supporting english language by default, due to the english is an international language, there are tons of fonts which will support it. – mohammad esmaili Oct 07 '22 at 07:10