merlijn mac gillavry
merlijn mac gillavry

Reputation: 95

flutter error when importing custom font

I try to install an icon as a custom font but whenever I try to run my app the console tells me that I got an error in the pubspec.yaml file. My font location is: myapp/fonts/icomoon.ttf and this is the relevant part of the pubspec.yaml file:

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

and the error message I got is:

#/properties/flutter/properties/fonts/items/properties/fonts: type: wanted [array] got {-asset: fonts/icomoon.ttf} Error building assets for C:\Users\merli\Documents\Projects\WorkoutApp\myapp\build\app\intermediates\flutter\debug/app.flx

FAILURE: Build failed with an exception.

BUILD FAILED in 4s Finished with error: Gradle build failed: 1

Upvotes: 6

Views: 14892

Answers (4)

devnotes sdk
devnotes sdk

Reputation: 11

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

Upvotes: 1

mrconcerned
mrconcerned

Reputation: 1945

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.

Upvotes: 1

K D
K D

Reputation: 215

flutter:

generate: true

uses-material-design: true

assets:

- assets/images/
- assets/go-logo.png
- assets/fb-logo.png

fonts:

- family: icomoon
    -asset icomoon.ttf
- family: Pacifico
    fonts
    -asset Pacifico-Regular.ttf

Upvotes: -1

Andrei Tudor Diaconu
Andrei Tudor Diaconu

Reputation: 2257

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

Upvotes: 10

Related Questions