[google_fonts] Add WOFF and WOFF2 font format support for web (#10703)

# Description

Web applications benefit significantly from using WOFF2 font files instead of TTF/OTF. WOFF2 is a compressed format
   specifically designed for web delivery, resulting in smaller file sizes and faster load times. This is especially
   important for Flutter web apps where every byte counts for initial page load performance.

   **Size comparison (Roboto Regular):**
   - TTF: 146,004 bytes
   - WOFF2: 63,424 bytes (~56% smaller)

   Currently, `google_fonts` only supports TTF and OTF formats, even on web platforms where WOFF2 would be more efficient.
   This PR adds support for WOFF2 and WOFF formats on web, allowing developers to bundle more efficient font files for their
   web applications.

   ## What

   This PR adds support for `.woff2` and `.woff` font file extensions when running on web platforms, while maintaining
   backward compatibility with `.ttf` and `.otf` files.

   **Changes:**
   - Add `kIsWeb` check to support web-optimized font formats (`.woff2`, `.woff`) in addition to `.ttf` and `.otf`
   - Make `findFamilyWithVariantAssetPath` testable by adding an optional `isWeb` parameter (defaults to `kIsWeb`)
   - Add `@visibleForTesting` annotation to enable comprehensive testing without exposing internal API
   - Add 20 tests covering web-specific, non-web-specific, and common behavior

   **Platform behavior:**
   - **Web:** Supports `.woff2`, `.woff`, `.ttf`, `.otf`
   - **Non-web:** Supports `.ttf`, `.otf` (unchanged)

   ## Implementation Notes

   The implementation maintains the existing behavior where **the order of assets in the manifest determines which file type
   is chosen** when multiple formats are available for the same font. While this feels a bit odd (ideally, there would be a
   preference order), this is how the function already works for TTF/OTF. In practice, this is not an issue when only one
   file type per font is bundled, which is the common case.

   ## Getting WOFF2 Files

   Developers can convert TTF/OTF fonts to WOFF2 using Google's `woff2_compress` tool:
   https://github.com/google/woff2

   Example:
   ```bash
   woff2_compress Roboto-Regular.ttf
   ```

   ## Testing

   All existing tests pass, plus 20 new tests that verify:
   - ✅ WOFF2 and WOFF formats work on web
   - ✅ WOFF2 and WOFF formats are ignored on non-web platforms
   - ✅ TTF and OTF continue to work on all platforms
   - ✅ Common behavior (null handling, family/variant matching) works consistently

   ## Breaking Changes

   None. This is a backward-compatible addition that only expands the supported file formats on web platforms.
   EOF

## 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.
4 files changed
tree: 20c209f19ed163d0ab1b81509187c8e0a892fd48
  1. .ci/
  2. .gemini/
  3. .github/
  4. packages/
  5. script/
  6. third_party/
  7. .ci.yaml
  8. .clang-format
  9. .gitattributes
  10. .gitignore
  11. .metadata
  12. AGENTS.md
  13. analysis_options.yaml
  14. AUTHORS
  15. CODEOWNERS
  16. CONTRIBUTING.md
  17. customer_testing.bat
  18. customer_testing.sh
  19. LICENSE
  20. README.md
README.md

Flutter Packages

Release Status Flutter CI Status

This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.

These packages are also available on pub.

Issues

Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.

Contributing

If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.

If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.

Packages

These are the packages hosted in this repository:

PackagePubPointsUsageIssuesPull requests
animationspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
camerapub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
cross_filepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
cupertino_iconspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
espressopub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
extension_google_sign_in_as_googleapis_authpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
file_selectorpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_lintspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_plugin_android_lifecyclepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_svgpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_svg_testpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
flutter_template_imagespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
go_routerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
go_router_builderpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_adsensepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_fontspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_maps_flutterpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_sign_inpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
image_pickerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
interactive_media_adspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
in_app_purchasepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
local_authpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
metrics_centerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
multicast_dnspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
path_parsingpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
path_providerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
pigeonpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
pointer_interceptorpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
plugin_platform_interfacepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
quick_actionspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
google_identity_services_webpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
mustache_templatepub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
rfwpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
shared_preferencespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
standard_message_codecpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
two_dimensional_scrollablespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
url_launcherpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphicspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphics_codecpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
vector_graphics_compilerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
video_playerpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
web_benchmarkspub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
webview_flutterpub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label
xdg_directoriespub packagepub pointsdownloadsGitHub issues by-labelGitHub pull requests by-label