Skip to content

[rfw] Fix fontWeight not applied in release mode - #11581

Merged
auto-submit[bot] merged 3 commits into
flutter:mainfrom
iam-abhijha:fix/rfw-font-weight-release-mode
Sep 17, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:mainfrom
iam-abhijha:fix/rfw-font-weight-release-mode

Conversation

@iam-abhijha

@iam-abhijha iam-abhijha commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the fontWeight property of RFW TextStyle (and StrutStyle) not being applied in release mode for Text widgets.

Fixes flutter/flutter#180223

Root cause

ArgumentDecoders.textStyle (and strutStyle) decoded fontWeight using enumValue(FontWeight.values, ...), which matched the input string against FontWeight.value.toString().split('.').last. FontWeight is not a real Dart enum; it is a hand-crafted class with static const members. In AOT/release builds, toString() for such classes is not guaranteed to return the same human-readable name (tree-shaking can strip debug labels), so all matches silently fail and null is returned, causing Flutter to fall back to the default weight (w400).

Fix

Added a new ArgumentDecoders.fontWeight static method that maps strings ("w100"–"w900", "normal", "bold") and integers (100–900) to the correct FontWeight constant using an explicit switch, without relying on toString(). Updated both textStyle and strutStyle to use this new decoder.

Pre-Review Checklist

@google-cla

google-cla Bot commented Apr 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the p: rfw Remote Flutter Widgets label Apr 25, 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 dedicated fontWeight decoder to handle FontWeight values as strings or integers, ensuring stability in release mode. It updates strutStyle and textStyle to utilize this new decoder and includes comprehensive tests. Feedback identifies several instances where absolute keys are used for property lookups—specifically textDirection in the sweep shader, and textBaseline and overflow in textStyle—instead of relative keys, which prevents correct resolution when these structures are nested.

Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from d9c573b to a8bd4b5 Compare April 25, 2026 17:11
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Thanks for the contribution!

In the future, please do not delete the checklist that is in the PR template; it is there for a reason. This PR is missing required elements described in the checklist, which need to be addressed before it moves forward with review.

I am marking the PR as a Draft. Please re-add and complete the checklist, updating the PR as appropriate, and when that’s complete please feel free to mark the PR as ready for review.

@stuartmorgan-g
stuartmorgan-g marked this pull request as draft April 28, 2026 18:22
@iam-abhijha
iam-abhijha marked this pull request as ready for review April 29, 2026 05:28
@iam-abhijha

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g

Thanks for the feedback! I've re added the PR template checklist and completed all applicable items. I have marked PR as Ready for review. Also this is my first time contributing to open source, so I appreciate the guidance!

@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 dedicated fontWeight decoder to resolve issues with FontWeight stability in release mode, updating TextStyle and StrutStyle to utilize it. It also fixes a key resolution bug in the sweep shader decoder and includes comprehensive unit tests for the new decoding logic. Feedback suggests simplifying the numeric FontWeight mapping by leveraging the FontWeight.values list for improved conciseness and robustness.

Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart
@stuartmorgan-g
stuartmorgan-g requested a review from Hixie April 29, 2026 14:14
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

It looks like you've run the autoformatter on some files that don't use it (look for the // This file is hand-formatted. comment at the start of the file), causing a lot of unrelated changes. Those should be reverted so reviewers can see what's actually changed.

@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from 524ee17 to 1944db2 Compare April 29, 2026 14:32
@iam-abhijha

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files. I've reverted all unrelated formatting changes; the PR now only touches argument_decoders.dart (new fontWeight decoder + two call site updates), argument_decoders_test.dart (regression test), CHANGELOG.md, and pubspec.yaml.

@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch from f919678 to 359bc88 Compare April 29, 2026 14:38
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files.

Please don't just repost AI-generated comments verbatim; reviewers don't need to have their review feedback repeated back to them.

@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 3 times, most recently from 869467b to a41ff8d Compare April 29, 2026 15:01
@iam-abhijha

Copy link
Copy Markdown
Contributor Author

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files.

Please don't just repost AI-generated comments verbatim; reviewers don't need to have their review feedback repeated back to them.

Sorry about that It's my first pr not much aware of rules.

return gradient(source, key)!.createShader(
rect(source, [...key, 'rect']) ?? Rect.zero,
textDirection: enumValue<TextDirection>(TextDirection.values, source, ['textDirection']) ?? TextDirection.ltr,
textDirection: enumValue<TextDirection>(TextDirection.values, source, [...key, 'textDirection']) ?? TextDirection.ltr,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This path-scoping fix (and the two similar ones below at textBaseline L1416 and overflow L1430) is a real bug fix but is unrelated to the fontWeight AOT issue this PR targets, and it isn't mentioned in the description or CHANGELOG. It changes behavior for any caller that previously relied on the (broken) root-level lookup, so consider splitting it into a separate PR with its own CHANGELOG entry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added those fixes in response to gemini comments but you're right they're not in scope of this issue. So As of now I have removed those path scoping fixes from this pr.

@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from 2210bcc to 4bd046a Compare May 17, 2026 08:13

@yjbanov yjbanov 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

return null;
}

/// Returns a [FontWeight] from the specified string or integer.

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.

Bonus points for explaining the condition when the function returns null.

@yjbanov

yjbanov commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What's left to land this?

@iam-abhijha
iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch from 4bd046a to 1107151 Compare July 31, 2026 15:29
@iam-abhijha

Copy link
Copy Markdown
Contributor Author

@Hixie @yjbanov Conflicts resolved

@Piinks
Piinks self-requested a review September 8, 2026 20:52
@Piinks
Piinks force-pushed the fix/rfw-font-weight-release-mode branch from 1107151 to 4612ab1 Compare September 8, 2026 20:53
@Piinks Piinks added the CICD Run CI/CD label Sep 8, 2026
@Piinks

Piinks commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Hey @iam-abhijha it looks like this fell through the review cracks. Sorry about that. Would you like to still land this change? If so, can you rebase with the tip of tree?

FontWeight is not a real Dart enum; it is a hand-crafted class with
static const members. The previous implementation decoded fontWeight via
enumValue(), which matched strings against FontWeight.value.toString().
In AOT/release builds this is not guaranteed to be stable, so matches
silently failed and fontWeight defaulted to null (rendered as w400).

Add a dedicated ArgumentDecoders.fontWeight() method that maps strings
("w100"-"w900", "normal", "bold") and integers (100-900) to the correct
FontWeight constant using an explicit switch, without relying on
toString(). Update textStyle and strutStyle to use it.

Fixes flutter/flutter#180223
@Piinks
Piinks force-pushed the fix/rfw-font-weight-release-mode branch from 4612ab1 to 7401b19 Compare September 17, 2026 17:51
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 17, 2026
@Piinks Piinks added the CICD Run CI/CD label Sep 17, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 17, 2026

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

LGTM

@Piinks Piinks added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Sep 17, 2026
@auto-submit
auto-submit Bot merged commit 9b86d89 into flutter:main Sep 17, 2026
14 checks passed
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: rfw Remote Flutter Widgets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFW] Text widget fontWeight not applied in release mode

5 participants