-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Custom fonts CookBook example not working as expected #3591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The Flutter engine matches fonts within a family based on the metadata in the font itself, not the style descriptors declared in the The Edmondsans regular, medium, and bold fonts contain metadata declaring their weights as 400, 410, and 420 respectively. However, the Flutter text subsystem only supports font weight buckets representing even multiples of 100 (https://api.flutter.dev/flutter/dart-ui/FontWeight-class.html). So all three of these fonts are mapped to Declaring these fonts as different families in |
Thanks a lot for the explanation @jason-simmons! It didn't occur me that my font could have been the one causing this. I think it would still be good to update the cookbook documentation so it won't confuse other developers. |
Moving to the website for the cookbook. |
Should we update the docs here to explain that these descriptors are actually ignored? |
This looks like a bug in the flutter engine to me. The value specified in the Working with multiple font families as a workaround would work but is far from elegant in my eyes. |
Based on what @jason-simmons mentioned, I created the following python script to "fix" your custom font files to use the correct weights that flutter respects. Create a
This is probably the best workaround out there at the moment. No multiple font families, and no needing to modify each font individually. |
@jason-simmons : Is this font issue still occurring? If so, I can document this workaround. If not, I'll close this issue. |
@miquelbeltran, ah the ultimate irony! You filed it, you fix it! :D |
Without additional information we're not able to resolve this issue, so it will be closed at this time. You're still free to add more info and respond to any questions above, though. We'll reopen the case if you do. Thanks for your contribution! |
I'll work on this now |
For what I can see, Flutter still only supports multiples of 100 when it comes to the font weight. Reviewing the cookbook recipe, I see that now it says:
I am thinking, I could add an explanation and workaround in the recipe, e.g.
Any thoughts on this? My only concern is that it could be promoting the wrong code practices, so we need to be clear that it is just a workaround for font files that aren't compliant with what Flutter expects. |
@miquelbeltran : That works. These docs are fluid, so we can always change again later if this appears to be in error. |
I added custom fonts to my project following the explanation in https://flutter.dev/docs/cookbook/design/fonts
In the example you can find:
So I followed it and in my
pubspec.yaml
I have:Then in my code:
However I noticed that:
To actually use my Medium and Bold custom font files, I had to use them in a different way:
Then in my code, this will work as expected:
My configuration info:
This issue here seem to be related: flutter/flutter#29806
I'd suggest to change the cookbook examples until custom fonts work as expected.
The text was updated successfully, but these errors were encountered: