Skip to content

Add fontFeatures and fontVariations to TextTheme.apply() - #192730

Closed
nadeemmx wants to merge 1 commit into
flutter:masterfrom
nadeemmx:fix/issue-192692-texttheme-apply-fontfeatures
Closed

nadeemmx wants to merge 1 commit into
flutter:masterfrom
nadeemmx:fix/issue-192692-texttheme-apply-fontfeatures

Conversation

@nadeemmx

Copy link
Copy Markdown

Description

Adds fontFeatures and fontVariations 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 #192692

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 (see text_style.dart:995-996). 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

All 18 tests pass (including existing tests).

Checklist

  • Tests added
  • Relevant tests pass
  • Formatting verified
  • No unrelated changes
  • Backward compatible (both params default to null)

Adds fontFeatures and fontVariations parameters to TextTheme.apply(),
passing them through to each TextStyle.apply() call.

Fixes flutter#192692
@github-actions

Copy link
Copy Markdown

This pull request contains changes to Material or Cupertino, which are currently frozen in this repository.

Changes should be made in material_ui and/or cupertino_ui in the flutter/packages repository.

Please refer to #188444 for instructions.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Sep 14, 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 adds support for fontFeatures and fontVariations in the TextTheme.apply method, forwarding these properties to all text styles. It also includes unit tests for this new functionality. The review feedback points out that one of the new tests, which claims to verify that both properties are preserved when null, only asserts fontFeatures. It is recommended to update the test to cover fontVariations as well.

Comment on lines +182 to +192
test('TextTheme apply null fontFeatures fontVariations preserves original', () {
const fontFeatures = <FontFeature>[FontFeature.enable('smcp')];
final typography = Typography.material2018();
final TextTheme baseTheme = typography.black.copyWith(
displayLarge: typography.black.displayLarge!.copyWith(fontFeatures: fontFeatures),
);
final TextTheme theme = baseTheme.apply();

expect(theme.displayLarge!.fontFeatures, fontFeatures);
expect(theme.displayMedium!.fontFeatures, isNull);
});

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 test name indicates that it verifies both fontFeatures and fontVariations are preserved when they are null, but the test implementation only sets and asserts fontFeatures.

To ensure complete test coverage and verify that fontVariations is also correctly preserved, please update the test to include fontVariations as well.

  test('TextTheme apply null fontFeatures fontVariations preserves original', () {
    const fontFeatures = <FontFeature>[FontFeature.enable('smcp')];
    const fontVariations = <FontVariation>[FontVariation('wght', 400.0)];
    final typography = Typography.material2018();
    final TextTheme baseTheme = typography.black.copyWith(
      displayLarge: typography.black.displayLarge!.copyWith(
        fontFeatures: fontFeatures,
        fontVariations: fontVariations,
      ),
    );
    final TextTheme theme = baseTheme.apply();

    expect(theme.displayLarge!.fontFeatures, fontFeatures);
    expect(theme.displayLarge!.fontVariations, fontVariations);
    expect(theme.displayMedium!.fontFeatures, isNull);
    expect(theme.displayMedium!.fontVariations, isNull);
  });
References
  1. Verify test validity: Confirm that new or modified tests effectively catch the issue being fixed and would fail if the fix were reverted. (link)

@Mairramer

Mairramer commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

@nadeemmx
This PR should be opened in the flutter/packages repository or ported there.

The guidelines and instructions for porting it can be found in #188444.

@nadeemmx

Copy link
Copy Markdown
Author

This PR has been ported to flutter/packages in flutter/packages#12879.

The ported PR includes:

  • The same fontFeatures and fontVariations parameters for TextTheme.apply()
  • A fix for the incomplete test that only checked fontFeatures but claimed to verify both fontFeatures and fontVariations

Please close this PR and reference the new one in flutter/packages.

nadeemmx added a commit to nadeemmx/packages that referenced this pull request Sep 16, 2026
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 added a commit to nadeemmx/packages that referenced this pull request Sep 16, 2026
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
nadeemmx added a commit to nadeemmx/packages that referenced this pull request Sep 16, 2026
Adds fontFeatures and fontVariations parameters to TextTheme.apply(),
matching the existing support in TextStyle.apply().

Fixes flutter/flutter#192692

Port of flutter/flutter#192730
@dkwingsmt dkwingsmt closed this Sep 23, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 28, 2026
#12879)

## 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

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

### Use Case: Variable Font Grade

```dart
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

[^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.

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

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fontFeatures and fontVariations to TextTheme.apply()

3 participants