Member-only story
Not In The Flutter Docs, Custom Variable Fonts
Google Fonts package does not yet fully support variable fonts so this is how to do it manually, and I included the font cache code.
Background
The Google Fonts package does not yet support variable fonts, so we have some problems to solve:
1. How to get the flutter engine to recognize the font family associated with the font file.
2. How to cache the fonts during app start up.
3. How to set up the Text Theme to recognize the variable font weight axis in the Text Style definition declaration.
Declaring Variable Fonts In Pubspec
Before the Google Fonts package came along, we used the pubspec to individually set up the font family with the font file. So specifying each variable font in the pubspec looks like this:
That will mean that now we can use those defined font families in the Text Theme.
But first, we should define how to cache the fonts as the Google Fonts package…