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
merlijn mac gillavry
Updated on June 22, 2022Comments
-
merlijn mac gillavry almost 2 years
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
-
zizutg over 4 yearsIn case someone is following tutorials available online, make sure the assets path is correct. My ttf file was in lib/fonts/
-
Oozeerally over 3 yearsConsider adding some information around this answer to make it useful, why or how does this solve the issue?