Skip to content

[material_ui] Add fontFeatures and fontVariations to TextTheme.apply() - #12879

Merged
auto-submit[bot] merged 6 commits into
flutter:mainfrom
nadeemmx:fix/issue-192730-texttheme-apply-fontfeatures
Sep 28, 2026
Merged

auto-submit[bot] merged 6 commits into
flutter:mainfrom
nadeemmx:fix/issue-192730-texttheme-apply-fontfeatures

Conversation

@nadeemmx

@nadeemmx nadeemmx commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR ports flutter/flutter#192730 to flutter/packages.

Adds List<FontFeature>? and List<FontVariation>? parameters to TextTheme.apply(), passing them through to each TextStyle.apply() call. This allows developers to apply font features and variations consistently across an entire text theme without modifying each TextStyle individually.

Related Issue

Fixes flutter/flutter#192692

Ports flutter/flutter#192730

Proposed Change

  • Added List<FontFeature>? and List<FontVariation>? parameters to TextTheme.apply()
  • Both default to null, preserving backward compatibility
  • Each of the 15 TextStyle.apply() calls within TextTheme.apply() now passes these parameters through

Technical Details

The TextStyle class already supports fontFeatures and fontVariations in its own apply() method. The TextTheme.apply() method was missing the ability to pass these through. This is a purely additive change - no existing behavior is modified.

Use Case: Persian Digits

final theme = Theme.of(context).textTheme.apply(
  fontFeatures: const [FontFeature("ss01")],
);

Use Case: Variable Font Grade

final theme = Theme.of(context).textTheme.apply(
  fontVariations: const [FontVariation('GRAD', 40.0)],
);

Testing

Added 2 new tests to text_theme_test.dart:

  1. TextTheme apply fontFeatures fontVariations - verifies all 15 styles receive the parameters
  2. TextTheme apply null fontFeatures fontVariations preserves original - verifies null defaults don't overwrite existing values (fixes incomplete test from original PR)

All 18 tests pass (including existing tests).

Pre-Review Checklist

Note

This PR ports the original flutter/flutter PR #192730. The original PR should be closed with a reference to this new PR.

The original PR had a test that claimed to verify both fontFeatures and fontVariations preservation, but only checked fontFeatures. This has been fixed in this ported version to properly verify both properties.

Footnotes

  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. ↩ ↩2

@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 updates the TextTheme.apply method in packages/material_ui/lib/src/text_theme.dart to include fontFeatures and fontVariations parameters, propagating these settings to all text styles. Corresponding tests have been added to packages/material_ui/test/text_theme_test.dart to verify the functionality. I have no further feedback to provide.

@Mairramer

Mairramer commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

@nadeemmx Thanks for the PR! Please use the Pre-Review Checklist and keep it in the PR rather than deleting it.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. 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.

Footnotes

  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. ↩ ↩2

@Mairramer
Mairramer marked this pull request as draft September 16, 2026 13:06
Ports flutter/flutter#192730 to flutter/packages.

Adds List<FontFeature>? and List<FontVariation>? parameters to
TextTheme.apply(), passing them through to each TextStyle.apply()
call. This allows developers to apply font features and variations
consistently across an entire text theme without modifying each
TextStyle individually.

Fixes flutter/flutter#192692
Adds fontFeatures and fontVariations parameters to TextTheme.apply(),
matching the existing support in TextStyle.apply().

Fixes flutter/flutter#192692

Port of flutter/flutter#192730
@nadeemmx
nadeemmx force-pushed the fix/issue-192730-texttheme-apply-fontfeatures branch from bc4b043 to 6c2790c Compare September 16, 2026 17:59
@Mairramer

Copy link
Copy Markdown
Contributor

@nadeemmx Thanks again for the contribution! If the PR is ready, feel free to put it up for review.

@dkwingsmt dkwingsmt added the CICD Run CI/CD label Sep 25, 2026
@dkwingsmt
dkwingsmt marked this pull request as ready for review September 25, 2026 23:04

@dkwingsmt dkwingsmt 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.

LGTM. Thank you!

@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 adds fontFeatures and fontVariations parameters to TextTheme.apply() in packages/material_ui, updates the changelog, and adds corresponding unit tests. Feedback on the tests suggests replacing list reference equality checks with deep collection comparison using a loop and the expect matcher to ensure robust assertions.

Comment on lines +178 to +179
expect(themeStyles.every((TextStyle style) => style.fontFeatures == fontFeatures), true);
expect(themeStyles.every((TextStyle style) => style.fontVariations == fontVariations), true);

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

Using style.fontFeatures == fontFeatures inside every relies on reference equality for lists in Dart, which is fragile and can break if the underlying implementation of TextStyle copies or wraps the list (e.g., to ensure immutability).

Instead, use the idiomatic equals matcher in a loop, which performs deep collection comparison and provides much better failure diagnostics if the assertion fails.

    for (final TextStyle style in themeStyles) {
      expect(style.fontFeatures, fontFeatures);
      expect(style.fontVariations, fontVariations);
    }

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 27, 2026
@Mairramer Mairramer added the CICD Run CI/CD label Sep 27, 2026

@Mairramer Mairramer 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.

LGTM. Thanks!

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2026
@auto-submit
auto-submit Bot merged commit d01e5bc into flutter:main Sep 28, 2026
14 checks passed
pull Bot pushed a commit to g-star1024/flutter that referenced this pull request Sep 29, 2026
…er#193507)

flutter/packages@ba0364a...3c6ce59

2026-09-29 [email protected] [cupertino_icons] Migrate to
`cupertino_ui` (flutter/packages#12649)
2026-09-29 [email protected] Manual roll Flutter from
4fcd90b to c5a061b (222 revisions) (flutter/packages#13060)
2026-09-28 [email protected] Enable Built-in Kotlin in all Flutter
Android Plugin Example Apps (flutter/packages#12883)
2026-09-28 [email protected] Enable Built-in Kotlin for
`interactive_media_ads` (flutter/packages#12912)
2026-09-28 [email protected] [google_maps_flutter] Adopt Pigeon's
Kotlin 'suspend' support (flutter/packages#12980)
2026-09-28 [email protected] [material_ui] Fix floating-point
rounding errors for discrete Slider and RangeSlider
(flutter/packages#13022)
2026-09-28 [email protected] [google_sign_in] PR 4/4 Convert
the Pigeon host API from Objective-C to Swift (flutter/packages#12658)
2026-09-28 [email protected]
[google_maps_flutter] Disable flaky web tests blocking latest flutter ->
packages roll (flutter/packages#13047)
2026-09-28 [email protected] [material_ui] Add fontFeatures and
fontVariations to TextTheme.apply() (flutter/packages#12879)
2026-09-28 [email protected]
[in_app_purchase_storekit] Disable flaky tests blocking latest flutter
-> packages roll (flutter/packages#13048)
2026-09-28 [email protected] Sync release-material_ui-1.5.0 to
main (flutter/packages#13051)
2026-09-28 [email protected] Sync release-go_router-18.0.2 to
main (flutter/packages#13050)
2026-09-28 [email protected] [google_fonts] Migrate to material_ui &
cupertino_ui (flutter/packages#13006)
2026-09-28 [email protected] [go_router_builder] Reland material_ui
migration (flutter/packages#12995)

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 [email protected] 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
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: material_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fontFeatures and fontVariations to TextTheme.apply()

3 participants