Sitelet https://github.com/flutter/packages/pull/11433
Skip to content

[google_fonts] Add google_fonts_lite file to allow tree-shaking of the other huge files - #11433

Merged
auto-submit[bot] merged 1 commit into
flutter:mainfrom
TheCarpetMerchant:main
Sep 4, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:mainfrom
TheCarpetMerchant:main

Conversation

@TheCarpetMerchant

Copy link
Copy Markdown
Contributor

Adds a google_fonts_lite.dart generated file, which contains a map of fontFamily to fonts variants and a getFont function that simply forwards the call to the internal googleFontsTextStyle function which does the downloading and loading of the font.

List which issues are fixed by this PR. You must list at least one issue.
flutter/flutter#184337

I have not done documentation, testing etc because this PR is for discussion purposes. I'd like approval of the concept before doing the paperwork.

The idea is to provide a lite version of the GoogleFonts class. This lite version does not depend on any of the other generated code, which is absolutely huge and takes up a massive amount of space (8MB on android for v8.0.0). By using this lite version only, the compiler is able to tree-shake all that additionnal code while you retain the ability to invoke any font from the package via getFont.

For me this brings the package's footprint from 8MB/target platform to less than a 1MB/target when building a release apk.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added p: google_fonts triage-framework Should be looked at in framework triage labels Apr 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a 'lite' version of the Google Fonts generator to support tree-shaking by creating a GoogleFontsLite class. Key changes include updating the generator to process a new template, making the GoogleFontsFile constructor const, and adding the google_fonts_lite.tmpl file. Review feedback recommends fixing a typo in the template comments, declaring the GoogleFontsLite class as abstract with a static const map, using display names for font keys, and implementing safer error handling in the getFont method to replace the current null-assertion operator.

// That is used to allow tree-shaking to remove all of the _parts files.
// If you only call GoogleFontsLite.fontsMap or GoogleFontsLite.loadFont(),
// the code in the GoogleFonts class and its parts classes is never called.
// WHat is called is googleFontsTextStyle, which attempts to load a font if not already loaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo: "WHat" should be "What".

// What is called is googleFontsTextStyle, which attempts to load a font if not already loaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Comment thread packages/google_fonts/generator/google_fonts_lite.tmpl Outdated
Comment on lines +23 to +25
static TextStyle getFont(String fontFamily) {
return googleFontsTextStyle(fontFamily: fontFamily, fonts: fontsMap[fontFamily]!);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getFont method uses the null-assertion operator !, which will cause a runtime crash if an unknown font family is requested. It is safer to check for the existence of the font and throw a more descriptive error.

  static TextStyle getFont(String fontFamily) {
    final fonts = fontsMap[fontFamily];
    if (fonts == null) {
      throw ArgumentError('No font family with name $fontFamily was found.');
    }
    return googleFontsTextStyle(fontFamily: fontFamily, fonts: fonts);
  }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a good suggestion.

Separate from that GoogleFontsLite.getFont currently only accepts String fontFamily, omitting textStyle, fontSize, color, fontWeight, fontStyle, etc. We should accept and forward all optional parameters to googleFontsTextStyle so GoogleFontsLite.getFont shares the same signature as GoogleFonts.getFont.

@stuartmorgan-g
stuartmorgan-g requested a review from Piinks April 7, 2026 18:16

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guidezpl, correct me if I am wrong, the generator script here would need to integrate with the internal dashboard where we pull these fonts from? Thanks in advance. :)

I appreciate the contribution @TheCarpetMerchant! We need to confirm if this will work with the existing workflows we have for this package.

@guidezpl

guidezpl commented Apr 8, 2026

Copy link
Copy Markdown
Member

@guidezpl, correct me if I am wrong, the generator script here would need to integrate with the internal dashboard where we pull these fonts from? Thanks in advance. :)

I appreciate the contribution @TheCarpetMerchant! We need to confirm if this will work with the existing workflows we have for this package.

Before this PR, the generator finds the font directory to generate the Dart code, and this PR seems to do nothing different in that regard, so from that point of view, this PR is okay

@justinmc
justinmc requested a review from Piinks April 21, 2026 22:09

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience while I reviewed this very carefully. This is an excellent addition. Bringing the package footprint down from 8MB to <1MB is a massive win for the ecosystem, especially for web and size-constrained mobile applications. 🎊

While the current results are impressive, I noticed an architectural 'leak' in the dependency graph that we should address to prevent future regressions.

Currently, google_fonts_lite.dart imports google_fonts_base.dart, which in turn imports ../google_fonts.dart. The main google_fonts.dart file exports google_fonts_all_parts.dart, where the 'heavy' GoogleFonts class and its asMap() method live.

The likely reason you are seeing size savings now is that the compiler is smart enough to see that GoogleFonts.asMap() is never called when using the Lite path. However, this is a fragile dependency. Because google_fonts_base.dart still has a direct import path to the heavy library (just to access the Config instance), any future change to the GoogleFonts class, such as a static initializer, a new field, or a change in how Config is accessed, could accidentally 'trap' the compiler into pulling all 8MB of font parts back into the binary without warning.

To make this optimization robust and permanent, we should decouple the configuration from the font metadata:

  1. Move the Config class and the GoogleFonts.config static instance into a new, standalone internal file (e.g., lib/src/google_fonts_config.dart).
  2. Update google_fonts_base.dart to import this new config file instead of the heavy google_fonts.dart entry point.
  3. Ensure the generator is updated to reflect this new structure.

Given that the Config refactor is a foundational change, it might be cleanest to handle the extraction of Config in a separate, small PR first. Once the configuration is decoupled, this PR can be rebased to provide a truly 'Lite' path that is cryptographically sealed off from the heavy parts files.

WDYT @TheCarpetMerchant? :)

@TheCarpetMerchant

TheCarpetMerchant commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor Author

The likely reason you are seeing size savings now is that the compiler is smart enough to see that GoogleFonts.asMap() is never called when using the Lite path. However, this is a fragile dependency. Because google_fonts_base.dart still has a direct import path to the heavy library (just to access the Config instance), any future change to the GoogleFonts class, such as a static initializer, a new field, or a change in how Config is accessed, could accidentally 'trap' the compiler into pulling all 8MB of font parts back into the binary without warning.

To make this optimization robust and permanent, we should decouple the configuration from the font metadata:

1. Move the `Config` class and the `GoogleFonts.config` static instance into a new, standalone internal file (e.g., `lib/src/google_fonts_config.dart`).

2. Update `google_fonts_base.dart` to import this new config file instead of the heavy `google_fonts.dart` entry point.

3. Ensure the generator is updated to reflect this new structure.

Sure, makes sense to make it more robust. Here's a PR where each part of the library (the full part and the lite part) has its own instance of the config stored as a static variable within their own file (although the lite version doesn't exist yet lol) : #11602

Edit : I didn't keep a single static instance because that would have meant breaking existing user code by moving the instance outside of the GoogleFonts class and into the GoogleFontsConfig class. This would be a huge annoyance for users for no real benefit as users of the lite version will only use that one, and users of the main one won't see the difference.

@Piinks

Piinks commented May 15, 2026

Copy link
Copy Markdown
Contributor

Following up in #11602 👍

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

From triage: This is blocked on the PR referenced above, right?

@Piinks

Piinks commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

From triage: This is blocked on the PR referenced above, right?

Yup! After that lands we can move this forward.

auto-submit Bot pushed a commit that referenced this pull request Jul 15, 2026
Extract Config from google_fonts_all_parts.dart to google_fonts_config.dart. Rename Config to GoogleFontsConfig to avoid namespace clutter. Add a deprecated Config typedef for backward compatibility. Export GoogleFontsConfig and the deprecated Config in lib/google_fonts.dart. Bump package version to 8.2.0.

Unblocks #11433

## 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.
@Piinks

Piinks commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

The change to extract the config class has landed, if you would rebase here, we can finally move this forward! Thanks!

@TheCarpetMerchant
TheCarpetMerchant force-pushed the main branch 4 times, most recently from e6dae09 to a605afc Compare August 4, 2026 06:34
@TheCarpetMerchant

Copy link
Copy Markdown
Contributor Author

The change to extract the config class has landed, if you would rebase here, we can finally move this forward! Thanks!

Alright, I've rebased and updated the changelog, readme + bump to 8.3.0. Squashed it to one commit.
The last thing to do would be to add a test for this, but since it requires running a full build I'm unsure of how that could be put in place with regards to CI.

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @TheCarpetMerchant, thanks for rebasing this after #11602 landed!

To answer your question regarding testing:

You do not need to set up a full flutter build apk release build in CI. Package unit tests in this repository run under flutter test.

To satisfy the testing requirement, please add a unit test file test/google_fonts_lite_test.dart that tests GoogleFontsLite in scenarios like:

  • GoogleFontsLite.getFont('Lato') returns a TextStyle with the expected font family.
  • Styling options (fontSize, color, fontWeight, etc.) are forwarded correctly to the returned TextStyle.
  • Requesting an unknown font family throws a descriptive error.
  • GoogleFontsLite.fontsMap is populated.

Thanks!

// That is used to allow tree-shaking to remove all of the _parts files.
// If you only call GoogleFontsLite.fontsMap or GoogleFontsLite.loadFont(),
// the code in the GoogleFonts class and its parts classes is never called.
// WHat is called is googleFontsTextStyle, which attempts to load a font if not already loaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Comment thread packages/google_fonts/generator/google_fonts_lite.tmpl Outdated
Comment on lines +23 to +25
static TextStyle getFont(String fontFamily) {
return googleFontsTextStyle(fontFamily: fontFamily, fonts: fontsMap[fontFamily]!);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a good suggestion.

Separate from that GoogleFontsLite.getFont currently only accepts String fontFamily, omitting textStyle, fontSize, color, fontWeight, fontStyle, etc. We should accept and forward all optional parameters to googleFontsTextStyle so GoogleFontsLite.getFont shares the same signature as GoogleFonts.getFont.

@TheCarpetMerchant

Copy link
Copy Markdown
Contributor Author

Hi @TheCarpetMerchant, thanks for rebasing this after #11602 landed!

To answer your question regarding testing:

You do not need to set up a full flutter build apk release build in CI. Package unit tests in this repository run under flutter test.

To satisfy the testing requirement, please add a unit test file test/google_fonts_lite_test.dart that tests GoogleFontsLite in scenarios like:

* `GoogleFontsLite.getFont('Lato')` returns a `TextStyle` with the expected font family.

* Styling options (`fontSize`, `color`, `fontWeight`, etc.) are forwarded correctly to the returned `TextStyle`.

* Requesting an unknown font family throws a descriptive error.

* `GoogleFontsLite.fontsMap` is populated.

Thanks!

Done. I've also added the LICENSE mention at the top of the file. If everything looks good I'll make a squash and I suggest you run the generator and subsequently make the release, as I've noticed there's new fonts available.
If you don't plan on updating the fonts I can make the pubspec change. Cheers

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing to iterate on this, @TheCarpetMerchant! This is going to be a substantial improvement for app binary size.

Before landing, there are a few important issues to address, commented inline below.

You should be able to run the generator from packages/google_fonts/, running:
dart generator/generator.dart

Comment thread packages/google_fonts/generator/google_fonts_lite.tmpl Outdated
Comment on lines +58 to +65
if (!fontsMap.containsKey(fontFamily)) {
throw Exception("No font family by name '$fontFamily' was found.");
}

return googleFontsTextStyle(
fontFamily: fontFamily,
fonts: fontsMap[fontFamily]!,
textStyle: textStyle,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When lookups are done using the display name (e.g. 'Open Sans'), fontsMap[fontFamily]! finds the variant map. However, googleFontsTextStyle expects fontFamily without spaces (e.g. 'OpenSans') so that asset path prefixing (toApiFilenamePrefix()) and fallback font family naming match the behavior of GoogleFonts.openSans().

Passing fontFamily: fontFamily.replaceAll(' ', '') to googleFontsTextStyle ensures full parity with GoogleFonts.getFont.

Suggested change
if (!fontsMap.containsKey(fontFamily)) {
throw Exception("No font family by name '$fontFamily' was found.");
}
return googleFontsTextStyle(
fontFamily: fontFamily,
fonts: fontsMap[fontFamily]!,
textStyle: textStyle,
if (!fontsMap.containsKey(fontFamily)) {
throw Exception("No font family by name '$fontFamily' was found.");
}
return googleFontsTextStyle(
fontFamily: fontFamily.replaceAll(' ', ''),
fonts: fontsMap[fontFamily]!,
textStyle: textStyle,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to this: could we add a comment above fontFamily.replaceAll(' ', '') to document this? (e.g. // googleFontsTextStyle expects the font family name to not include spaces.

@@ -4,3 +4,4 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to this file, consider adding a dedicated entry point lib/google_fonts_lite.dart:

// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/google_fonts_config.dart';
export 'src/google_fonts_lite.dart';

This gives developers aiming for minimal binary size a clean public library to import (import 'package:google_fonts/google_fonts_lite.dart';) without having to import google_fonts.dart (which exports google_fonts_all_parts.dart) or importing from src/.

@@ -0,0 +1,92 @@
// Copyright 2013 The Flutter Authors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a few updates for the test file to align with repository standards:

  • Import package:google_fonts/google_fonts.dart rather than importing implementation files from src/.
  • Remove unused package:flutter/cupertino.dart.
  • Clean up dead commented-out foreground code.
  • Use expect(..., throwsA(...)) instead of a manual try/catch block.
  • Add a test verifying lookups for fonts with spaces in their family name (like 'Open Sans').
  • Verify that GoogleFontsLite.fontsMap.keys matches GoogleFonts.asMap().keys exactly.

Some additional tests to include:

Details
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';

void main() {
  testWidgets('GoogleFontsLite getFont returns the correct font with the given parameters', (WidgetTester tester) async {
    const textStyle = TextStyle(
      color: Color(0xAABBCCDD),
      fontSize: 20,
      letterSpacing: 20,
      wordSpacing: 20,
      height: 20,
      decorationThickness: 20,
      fontWeight: FontWeight.w300,
      fontStyle: FontStyle.italic,
      textBaseline: TextBaseline.alphabetic,
      locale: Locale('fr'),
      background: Paint()..color = const Color(0xAABBCCDD),
      shadows: <Shadow>[Shadow(blurRadius: 1)],
      fontFeatures: <FontFeature>[FontFeature.slashedZero()],
      decoration: TextDecoration.lineThrough,
      decorationColor: Color(0xAABBCCDD),
      decorationStyle: TextDecorationStyle.dashed,
    );

    void verifyTextStyle(TextStyle res) {
      expect(res.fontFamily, equals('Lato_300italic'));
      expect(res.color, equals(textStyle.color));
      expect(res.fontSize, equals(textStyle.fontSize));
      expect(res.letterSpacing, equals(textStyle.letterSpacing));
      expect(res.wordSpacing, equals(textStyle.wordSpacing));
      expect(res.decorationThickness, equals(textStyle.decorationThickness));
      expect(res.fontWeight, equals(textStyle.fontWeight));
      expect(res.fontStyle, equals(textStyle.fontStyle));
      expect(res.textBaseline, equals(textStyle.textBaseline));
      expect(res.locale, equals(textStyle.locale));
      expect(res.background, equals(textStyle.background));
      expect(res.shadows, equals(textStyle.shadows));
      expect(res.fontFeatures, equals(textStyle.fontFeatures));
      expect(res.decoration, equals(textStyle.decoration));
      expect(res.decorationColor, equals(textStyle.decorationColor));
      expect(res.decorationStyle, equals(textStyle.decorationStyle));
    }

    verifyTextStyle(GoogleFontsLite.getFont(
      'Lato',
      textStyle: textStyle,
    ));

    verifyTextStyle(GoogleFontsLite.getFont(
      'Lato',
      color: textStyle.color,
      fontSize: textStyle.fontSize,
      letterSpacing: textStyle.letterSpacing,
      wordSpacing: textStyle.wordSpacing,
      height: textStyle.height,
      decorationThickness: textStyle.decorationThickness,
      fontWeight: textStyle.fontWeight,
      fontStyle: textStyle.fontStyle,
      textBaseline: textStyle.textBaseline,
      locale: textStyle.locale,
      background: textStyle.background,
      shadows: textStyle.shadows,
      fontFeatures: textStyle.fontFeatures,
      decoration: textStyle.decoration,
      decorationColor: textStyle.decorationColor,
      decorationStyle: textStyle.decorationStyle,
    ));
  });

  testWidgets('GoogleFontsLite getFont supports fonts with spaces in their family name', (WidgetTester tester) async {
    final TextStyle style = GoogleFontsLite.getFont('Open Sans');
    expect(style.fontFamily, equals('OpenSans_regular'));
    expect(style.fontFamilyFallback, equals(<String>['OpenSans']));
  });

  testWidgets('GoogleFontsLite getFont throws an exception when the fontFamily is unknown', (WidgetTester tester) async {
    expect(
      () => GoogleFontsLite.getFont('ZZZ_NON_EXISTENT_FONT_ZZZ'),
      throwsA(
        isA<Exception>().having(
          (Exception e) => e.toString(),
          'message',
          contains("No font family by name 'ZZZ_NON_EXISTENT_FONT_ZZZ' was found."),
        ),
      ),
    );
  });

  test('GoogleFontsLite.fontsMap keys match GoogleFonts.asMap keys exactly', () {
    expect(GoogleFontsLite.fontsMap.keys, equals(GoogleFonts.asMap().keys));
  });
}

Comment thread packages/google_fonts/CHANGELOG.md Outdated
@TheCarpetMerchant
TheCarpetMerchant force-pushed the main branch 2 times, most recently from debb080 to ba86e04 Compare August 19, 2026 07:09
@TheCarpetMerchant

Copy link
Copy Markdown
Contributor Author

The map can't be const because GoogleFontsVariant overrides '==' and hashCode so we can't make the map const. I've made it final though.
Rest has been added and squashed, I ran the generator & updated the changelog as well.

@Piinks Piinks added the CICD Run CI/CD label Aug 19, 2026
@Piinks

Piinks commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

The map can't be const because GoogleFontsVariant overrides '==' and hashCode so we can't make the map const. I've made it final though. Rest has been added and squashed, I ran the generator & updated the changelog as well.

The const issue causing static analysis to fail is in generator/google_fonts_part.tmpl. Because GoogleFontsFile's constructor was made const, the template for the 26 part files needs const added before GoogleFontsFile:

```diff
// packages/google_fonts/generator/google_fonts_part.tmpl:44
- const GoogleFontsVariant(fontWeight: FontWeight.w{{variantWeight}}, fontStyle:

FontStyle.{{variantStyle}},): GoogleFontsFile('{{hash}}', {{length}},),
+ const GoogleFontsVariant(fontWeight: FontWeight.w{{variantWeight}}, fontStyle:
FontStyle.{{variantStyle}},): const GoogleFontsFile('{{hash}}', {{length}},),


And adding const to the test fixtures in:

- test/google_fonts_text_style_test.dart (line 36)
- test/load_font_if_necessary_test.dart (lines 71, 75)
- test/load_font_if_necessary_with_local_fonts_test.dart (line 58)

After re-running dart generator/generator.dart, dart run script/tool/bin/flutter_plugin_tools.dart analyze --packages google_fonts will pass cleanly.

@Piinks Piinks left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the formatter is failing here, but otherwise is nearly ready to land. Can you run formatting?

@@ -3,6 +3,7 @@ description: A Flutter package to use fonts from fonts.google.com. Supports HTTP
repository: https://github.com/flutter/packages/tree/main/packages/google_fonts
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
version: 8.2.1
publish_to: none

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you

@TheCarpetMerchant

Copy link
Copy Markdown
Contributor Author

It looks like the formatter is failing here, but otherwise is nearly ready to land. Can you run formatting?

Right, didn't run it on the test file. And there was a line in the generator file. Done

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, let me send it out for secondary review

@elliette
elliette self-requested a review August 28, 2026 23:04
@elliette elliette added the CICD Run CI/CD label Aug 31, 2026
Comment thread packages/google_fonts/generator/google_fonts_lite.tmpl
Comment on lines +58 to +65
if (!fontsMap.containsKey(fontFamily)) {
throw Exception("No font family by name '$fontFamily' was found.");
}

return googleFontsTextStyle(
fontFamily: fontFamily,
fonts: fontsMap[fontFamily]!,
textStyle: textStyle,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to this: could we add a comment above fontFamily.replaceAll(' ', '') to document this? (e.g. // googleFontsTextStyle expects the font family name to not include spaces.

…e other huge files

Update templates to generate lib/google_fonts_lite.dart.
Add the generated lib/google_fonts_lite.dart file.
Export the new GoogleFontsLite class from the file lib/google_fonts_lite.dart.
Update README to mention usage of GoogleFontsLite.
Update fonts.

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 3, 2026
@auto-submit
auto-submit Bot merged commit 866678c into flutter:main Sep 4, 2026
14 checks passed
pull Bot pushed a commit to Mattlk13/flutter that referenced this pull request Sep 9, 2026
…er#192485)

flutter/packages@9af9c60...36e088a

2026-09-09 daniel.leon@cloudsufi.com [quick_actions] Adopt code-excerpts
for README (flutter/packages#12643)
2026-09-08 65155920+0xharkirat@users.noreply.github.com [camera_web] Fix
TypeError when reading the torch capability (flutter/packages#12647)
2026-09-08 gibbonsj97@gmail.com [google_maps_flutter_web] Avoid
replacing advanced marker content on move (flutter/packages#11952)
2026-09-08 mit@google.com [material_ui][cupertino_ui] Change issue
tracker label in pubspec.yaml (flutter/packages#12792)
2026-09-08 saurabhmirajkar000@gmail.com [material_ui] Fix FilledButton
Material 3 default style docs (flutter/packages#12620)
2026-09-08 21270878+elliette@users.noreply.github.com [infra] Use a
modified no-response workflow in flutter/packages
(flutter/packages#12745)
2026-09-08 21270878+elliette@users.noreply.github.com [material_ui]
Migrate M3 Banner template to use new gen_defaults
(flutter/packages#12734)
2026-09-08 engine-flutter-autoroll@skia.org Roll Flutter from
63170e9 to b444e78 (13 revisions) (flutter/packages#12791)
2026-09-08 fluttergithubbot@gmail.com Sync release-go_router-18.0.1 to
main (flutter/packages#12725)
2026-09-08 fluttergithubbot@gmail.com Sync release-material_ui-1.1.1 to
main (flutter/packages#12726)
2026-09-08 stuartmorgan@google.com [tool] Adopt `platform` 3.2.0
(flutter/packages#12789)
2026-09-07 50643541+Mairramer@users.noreply.github.com [material_ui] Fix
SliverGeometry maxPaintExtent assertion in CarouselView.weighted
(flutter/packages#12563)
2026-09-05 engine-flutter-autoroll@skia.org Roll Flutter from
5a6cfa7 to 63170e9 (15 revisions) (flutter/packages#12767)
2026-09-04 engine-flutter-autoroll@skia.org Manual roll Flutter from
70797e1 to 5a6cfa7 (52 revisions) (flutter/packages#12760)
2026-09-04 brackenavaron@gmail.com [material_ui] port drawer tests over
from flutter/widgets (flutter/packages#12711)
2026-09-04 tarrinneal@gmail.com add cooldown (flutter/packages#12708)
2026-09-04 joeldumasbg@gmail.com [in_app_purchase] Support StoreKit 2
introductory offer eligibility JWS (flutter/packages#12584)
2026-09-04 21270878+elliette@users.noreply.github.com [material_ui]
Migrate M3 Badge template to use new gen_defaults
(flutter/packages#12733)
2026-09-04 stuartmorgan@google.com [google_maps_flutter] Convert heatmap
controller to Swift (flutter/packages#12713)
2026-09-04 97480502+b-luk@users.noreply.github.com [material_ui] Remove
unused `maintainState` constructor parameter in `scaffold_test.dart`
(flutter/packages#12754)
2026-09-04 a1rwulf@users.noreply.github.com [video_player_avfoundation]
Route video over AirPlay (flutter/packages#12490)
2026-09-04 jerome.dellamaria@proton.me [google_fonts] Add
google_fonts_lite file to allow tree-shaking of the other huge files
(flutter/packages#11433)
2026-09-04 engine-flutter-autoroll@skia.org Roll Flutter from
0cbd1a4 to 70797e1 (27 revisions) (flutter/packages#12727)
2026-09-04 stuartmorgan@google.com Update Chrome for stable tests
(flutter/packages#12747)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…e other huge files (flutter#11433)

Adds a `google_fonts_lite.dart` generated file, which contains a map of `fontFamily` to fonts variants and a `getFont` function that simply forwards the call to the internal `googleFontsTextStyle` function which does the downloading and loading of the font.

*List which issues are fixed by this PR. You must list at least one issue.*
flutter/flutter#184337

I have not done documentation, testing etc because this PR is for discussion purposes. I'd like approval of the concept before doing the paperwork.

The idea is to provide a _lite_ version of the `GoogleFonts` class. This lite version does not depend on any of the other generated code, which is absolutely huge and takes up a massive amount of space (8MB on android for v8.0.0). By using this lite version only, the compiler is able to tree-shake all that additionnal code while you retain the ability to invoke any font from the package via `getFont`.

For me this brings the package's footprint from 8MB/target platform to less than a 1MB/target when building a release apk.
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…e other huge files (flutter#11433)

Adds a `google_fonts_lite.dart` generated file, which contains a map of `fontFamily` to fonts variants and a `getFont` function that simply forwards the call to the internal `googleFontsTextStyle` function which does the downloading and loading of the font.

*List which issues are fixed by this PR. You must list at least one issue.*
flutter/flutter#184337

I have not done documentation, testing etc because this PR is for discussion purposes. I'd like approval of the concept before doing the paperwork.

The idea is to provide a _lite_ version of the `GoogleFonts` class. This lite version does not depend on any of the other generated code, which is absolutely huge and takes up a massive amount of space (8MB on android for v8.0.0). By using this lite version only, the compiler is able to tree-shake all that additionnal code while you retain the ability to invoke any font from the package via `getFont`.

For me this brings the package's footprint from 8MB/target platform to less than a 1MB/target when building a release apk.
auto-submit Bot pushed a commit that referenced this pull request Sep 23, 2026
… full feature parity (#12830)

In PR #11433 #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.

#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: google_fonts triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants