Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Open Type Font (OTF) in Flutter?

Tags:

flutter

I have added the font in pubspec.yaml Any True Type Font works just fine. But, when I add Open Type Font it doesn't work.

Here is my how I added font in pubspec.yaml

  fonts:
    - family: Kufyan
      fonts:
        - asset: assets/fonts/Kufyan.otf

like image 691
Xihuny Avatar asked Jan 23 '20 09:01

Xihuny


2 Answers

The flutter recent version v1.12.13 does not support the open type font(otf) directly. You have to convert the otf to true type font(ttf) somehow. You can use this third-party website to covert the font to ttf before using it in your project. You can refer to the guide on how to use custom fonts in flutter for more information.

Flutter matches the font family based on the metadata in the font itself. So defining family: Kufyan is not required in pubspec.yml


Note: OTF is now officially supported, see supported font types

like image 194
Kiran Maniya Avatar answered Oct 17 '22 03:10

Kiran Maniya


✔️ Officially works since 24 feb of 2021

Proofs

  1. Since this commit (GitHub) enter image description here

  2. Current docs state look here (Flutter docs) enter image description here

like image 38
Kas Elvirov Avatar answered Oct 17 '22 04:10

Kas Elvirov