flutter error when importing custom font flutter error when importing custom font dart dart

flutter error when importing custom font


Indentation and formatting is very important when working with YAML (as Gunther already mentioned in his comment). I ran your snippet of code through an online YAML parser and found 2 issues:

  • 1 extra space before fonts: that should not be there
  • -asset: needs an extra space to be - asset:. Otherwise for YAML it is just a string that happens to start with -

The error you received tells you that even though an array was expected for fonts, something else was encountered (the second item on the above list).

Here is the correct form I ended up with:

 fonts:  - family:          icomoon    fonts:     - asset:        fonts/icomoon.ttf


I was having the same behavior when I was trying to add Roboto font like this:

  fonts:    - family: Roboto      fonts:        - asset: fonts/Roboto-Regular.ttf        - asset: fonts/Roboto-Bold.ttf        - weight: 700

I then realized that, I need to press the "Get packages" button (I'm using VSCode). So, once you add, make sure to click "Get packages" button.


after adding your font assets, define it under the assets section of your pubspec.yaml,you should re build your project runflutter packages get ,firstlythis worked for me..