You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 72a0a40
Browse filesBrowse the repository at this point in the historyBrowse files
[google_fonts] Decouple GoogleFontsLite for full tree-shaking and add full feature parity (flutter#12830)
In PR flutter#11433flutter/packages#11433, google_fonts_lite.dart was introduced as an alternative entry point containing only dynamic font resolution methods and the family descriptor map, allowing compilers to tree-shake the static generated font methods.
flutter#11433 was a huge PR, and a breaking one, so we did not publish it yet. Currently this package is set to publish_to: none.
For these reasons I decided to follow up on a few more bits of polish here instead of belaboring the mega PR and the contributor's effort.
_**After this change, I will migrate this package to material_ui and then we will publish one major release with all of these changes to reduce churn on the ecosystem**._
This PR ensures google_fonts_lite.dart is fully decoupled from the main entry point by sharing an internal configuration singleton, ensuring complete compiler tree-shaking of unused generated font code, while adding missing features to google fonts lite for full feature parity with the non-lite version.
## Pre-Review Checklist
**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Copy file name to clipboardExpand all lines: packages/google_fonts/README.md
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,10 +115,32 @@ return MaterialApp(
115
115
```
116
116
117
117
### Lower build size
118
-
The `GoogleFontsLite` class is a replacement for the `GoogleFonts` class containing only a map of all fonts and the `getFont` function. Using *only*`GoogleFontsLite` allows the Dart compiler to tree-shake most of the package's code, yielding a significant reduction in build size.
118
+
The `GoogleFontsLite` class is an alternative entry point containing only a map of all fonts and dynamic font resolution methods. Using *only*`GoogleFontsLite` allows the Dart compiler to tree-shake all unused font methods, yielding a significant reduction in build size.
119
+
120
+
To allow the Dart compiler to tree-shake unused fonts, import `package:google_fonts/google_fonts_lite.dart` instead of `package:google_fonts/google_fonts.dart`.
121
+
122
+
Do not import `package:google_fonts/google_fonts.dart` when optimizing for bundle size, as that imports the generated static font methods.
To avoid visual font swaps that occur when a font is loading, use [FutureBuilder](https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html) and [GoogleFonts.pendingFonts()](https://pub.dev/documentation/google_fonts/latest/google_fonts/GoogleFonts/pendingFonts.html).
143
+
To avoid visual font swaps that occur when a font is loading, use [FutureBuilder](https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html) and [GoogleFonts.pendingFonts()](https://pub.dev/documentation/google_fonts/latest/google_fonts/GoogleFonts/pendingFonts.html) (or `GoogleFontsLite.pendingFonts()`).
122
144
123
145
See the [example app](https://pub.dev/packages/google_fonts/example).
0 commit comments