Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • Where: Script 'C:\Users\merli\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 441

  • What went wrong: Execution failed for task ':app:flutterBuildDebug'.

    Process 'command 'C:\Users\merli\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

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

like image 991
merlijn mac gillavry Avatar asked Jan 28 '23 04:01

merlijn mac gillavry


1 Answers

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
like image 85
Andrei Tudor Diaconu Avatar answered Feb 04 '23 08:02

Andrei Tudor Diaconu