Open
Description
I have a typeface with multiple weights I want access to, and font files for each of these weights. I've configured pubspec.yaml
with those weights, but they are not used when the identical FontWeight
is used in a TextStyle
.
pubspec:
fonts:
- family: Chivo
fonts:
- asset: assets/fonts/Chivo-Regular.ttf
- asset: assets/fonts/Chivo-Italic.ttf
style: italic
- asset: assets/fonts/Chivo-Light.ttf
weight: 200
- asset: assets/fonts/Chivo-LightItalic.ttf
weight: 200
style: italic
- asset: assets/fonts/Chivo-Bold.ttf
weight: 700
- asset: assets/fonts/Chivo-BoldItalic.ttf
style: italic
weight: 700
- asset: assets/fonts/Chivo-Black.ttf
weight: 900
- asset: assets/fonts/Chivo-BlackItalic.ttf
weight: 900
style: italic
If I then used FontWeight.bold
in a TextStyle
, the 900 weight is used instead. This does not line up with the documentation on using custom fonts here: https://flutter.dev/docs/cookbook/design/fonts#pubspecyaml-option-definitions
Should the documentation be updated, or is this an issue that should be fixed in the framework?
There is a workaround: two fonts. I configured one font with the "common" weights (400/700), and a second with the "extreme" weights (200/900), treated as 400/700:
fonts:
- family: Chivo
fonts:
- asset: assets/fonts/Chivo-Regular.ttf
- asset: assets/fonts/Chivo-Italic.ttf
style: italic
- asset: assets/fonts/Chivo-Bold.ttf
weight: 700
- asset: assets/fonts/Chivo-BoldItalic.ttf
style: italic
weight: 700
- family: 'Chivo Extreme'
fonts:
- asset: assets/fonts/Chivo-Light.ttf
- asset: assets/fonts/Chivo-LightItalic.ttf
style: italic
- asset: assets/fonts/Chivo-Black.ttf
weight: 700
- asset: assets/fonts/Chivo-BlackItalic.ttf
weight: 700
style: italic