How to use chinese fonts with chinese characters in Flutter?

994 views Asked by At

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 :)

1

There are 1 answers

2
mohammad esmaili On BEST ANSWER

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