Skip to content

Conversation

@mateusfccp
Copy link
Contributor

@mateusfccp mateusfccp commented Sep 28, 2023

Provide a parameter applyTextScaling to both Icon and IconDataTheme. When true, the context's TextScaler will apply it's scale method to the icon size.

Fixes #115466

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Sep 28, 2023
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch 9 times, most recently from 6778b63 to a03fac6 Compare October 5, 2023 15:53
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch 4 times, most recently from 63ba379 to 0dc3b18 Compare October 14, 2023 23:39
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch 2 times, most recently from 79b2ef2 to 2e80306 Compare October 19, 2023 13:22
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch 3 times, most recently from 143ec93 to 4053e4d Compare October 29, 2023 22:05
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch 2 times, most recently from 3542d60 to a6478b2 Compare November 9, 2023 22:33
@MitchellGoodwin MitchellGoodwin self-requested a review November 10, 2023 18:32
@HansMuller
Copy link
Contributor

CC @LongCatIsLooong - please take a look at this - TextScaler dependency.

@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch from a6478b2 to 50b58d0 Compare November 10, 2023 18:48
Copy link
Contributor

@MitchellGoodwin MitchellGoodwin left a comment

Choose a reason for hiding this comment

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

Tentative LGTM, depending on textScaler dependency.

Thank you for putting this together. Apologies that it's slipped through the cracks for so long.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just be bool?

Copy link
Contributor Author

@mateusfccp mateusfccp Nov 11, 2023

Choose a reason for hiding this comment

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

If the passed value is null, the value will be obtained through the context, while if it's not null the passed value will be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should default to 14 when null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity, why?

I can't see anything in the current code that makes it default to 14.0, so this is essentially a new behavior, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the default font size the text layout libraries use when the font size isn't specified (it currently happens in flutter/engine so you probably won't find that logic in flutter/flutter).

Copy link
Contributor Author

@mateusfccp mateusfccp Nov 14, 2023

Choose a reason for hiding this comment

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

If the engine handles it, why should we specify it now?

Copy link
Contributor

Choose a reason for hiding this comment

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

because we are using the font size to scale the icon right? It doesn't make sense to skip scaling because there's no explicitly specified font size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I get what you are saying now... In this case, do we have any way to knowing this value instead of hardcoding it?

I mean, if the engine ever changes its "internal value" from 14.0 to anything else, it's not hard to forget to update it here, so we could potentially and silently introduce a regression here...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah good point. There's a private constant defined in text_painter.dart and another one in widget_span.dart. You could make the text_painter one public and remove the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch from 50b58d0 to 28ce18e Compare November 11, 2023 23:17
Copy link
Contributor

Choose a reason for hiding this comment

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

If applyingTextScaling == null then it's treated as if it was set to false. Then why are we allowing setting the value to null in the theme? It doesn't have a different meaning than setting the value to false in the theme right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I am actually following the pattern established for other properties of the theme. Take, for instance, size. It is also nullable, and the default value (24.0) is set in the fallback() constructor. Then, in the Icon widget, we simply take it as nullable and pass down to the text style.

It happens with all other properties of the theme, so I feel it's reasonable to follow it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok makes sense to me. But in that case I think you'll have to change the implementation of a few more methods (==, merge for example).

Copy link
Contributor Author

@mateusfccp mateusfccp Nov 14, 2023

Choose a reason for hiding this comment

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

== already considers applyTextScaling.

merge was unintentionally left out, so I am going to work on it.

Finally, there's lerp, but I am not sure how I should handle it. Should I scale the size within the lerp method? Like, for instance, lerping from (size: 10.0) to (size: 10.0, applyTextScaling: true) with a scale factor of 2.0 will yield a size of 15.0 when t is 0.5 or something like this... WDYT?

I think this would also fall in the aforementioned problem of size being null... I mean, if size is null, lerp wouldn't be able to scale it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented both merge and lerp. For lerp, I looked at how it's done in other themes' lerp methods, and all of them simply do t < 0.5 ? a?.property : b?.property, so I went with this.

I am a little confused with isConcrete, though. I couldn't understand why shadows are not considered int it. It's used in two places, and one of them is in IconTheme.of:

  static IconThemeData of(BuildContext context) {
    final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context);
    return iconThemeData.isConcrete
      ? iconThemeData
      : iconThemeData.copyWith(
        size: iconThemeData.size ?? const IconThemeData.fallback().size,
        fill: iconThemeData.fill ?? const IconThemeData.fallback().fill,
        weight: iconThemeData.weight ?? const IconThemeData.fallback().weight,
        grade: iconThemeData.grade ?? const IconThemeData.fallback().grade,
        opticalSize: iconThemeData.opticalSize ?? const IconThemeData.fallback().opticalSize,
        color: iconThemeData.color ?? const IconThemeData.fallback().color,
        opacity: iconThemeData.opacity ?? const IconThemeData.fallback().opacity,
        shadows: iconThemeData.shadows ?? const IconThemeData.fallback().shadows,
        applyTextScaling: iconThemeData.applyTextScaling ?? const IconThemeData.fallback().applyTextScaling,
      );
  }

As shadows are not included in isConcrete, if all properties are non-null but shadows are null, the fallback shadows won't be passed. I think this is not the intended behavior. (BTW, I implemented the shadow property in IconTheme, and not passing it to isConcrete was probably because I overlooked it. However, it was later changed to include other properties and purposely left out, as shown by the documentation)

Why is shadows not included? What defines what should be included in it or not? And, ultimately, should I include applyScalingFactor in it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Shadow == null means it's off (although it feels a bit strange). So the fallback value of applyScalingFactor shouldn't be null (being null typically means it should fall back to the default value).

Copy link
Contributor

Choose a reason for hiding this comment

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

So yes I think should be taken into account by the isConcrete implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch from 3d11d03 to 0f6f910 Compare November 14, 2023 20:17
@LongCatIsLooong
Copy link
Contributor

LGTM, thank you for contributing! The Google testing failure does not look related. I'll sync the branch to retest.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 28, 2023
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
@mateusfccp mateusfccp force-pushed the icon_text_scale_factor branch from 717965c to 52314ee Compare November 28, 2023 22:09
@auto-submit auto-submit bot merged commit 49632fc into flutter:master Nov 29, 2023
@mateusfccp mateusfccp deleted the icon_text_scale_factor branch November 29, 2023 09:08
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 29, 2023
Roll Flutter from 6bf3ccd to 5e5b529 (58 revisions)

flutter/flutter@6bf3ccd...5e5b529

2023-11-29 [email protected] Roll Flutter Engine from 60b963930202 to 222beb28a8eb (2 revisions) (flutter/flutter#139242)
2023-11-29 [email protected] Roll Flutter Engine from eebbe7e15c7d to 60b963930202 (2 revisions) (flutter/flutter#139237)
2023-11-29 [email protected] Roll Packages from 3c05466 to e4aaba8 (5 revisions) (flutter/flutter#139232)
2023-11-29 [email protected] Update VelocityTracker (4) (flutter/flutter#139166)
2023-11-29 [email protected] Analyze against using Stopwatches in the framework (flutter/flutter#138507)
2023-11-29 [email protected] Roll Flutter Engine from ecc9c7b6be7d to eebbe7e15c7d (1 revision) (flutter/flutter#139225)
2023-11-29 [email protected] Roll Flutter Engine from 28aae2d29822 to ecc9c7b6be7d (1 revision) (flutter/flutter#139210)
2023-11-29 [email protected] Improve documentation of CardTheme.shape (flutter/flutter#139096)
2023-11-29 [email protected] Simplify devicelab logic and fix tests (flutter/flutter#139122)
2023-11-29 [email protected] implemented leadingWidth and automaticallyImplyLeading options  (flutter/flutter#136165)
2023-11-29 [email protected] TextField and TextFormField can use a MaterialStatesController (flutter/flutter#133977)
2023-11-29 [email protected] Provide parameter to Icon and IconThemeData for they to consider the context's text scaler (flutter/flutter#135708)
2023-11-29 [email protected] Roll Flutter Engine from be4d7c8b760c to 28aae2d29822 (1 revision) (flutter/flutter#139204)
2023-11-29 [email protected] Update `ButtonStyleButton.scaledPadding` documentation. Migrate callers in flutter/flutter (flutter/flutter#139014)
2023-11-29 [email protected] Roll Flutter Engine from de99c71c598f to be4d7c8b760c (1 revision) (flutter/flutter#139199)
2023-11-29 [email protected] Roll Flutter Engine from 9a840e8dba40 to de99c71c598f (2 revisions) (flutter/flutter#139195)
2023-11-29 [email protected] Roll Flutter Engine from fbb2b1e880fa to 9a840e8dba40 (1 revision) (flutter/flutter#139192)
2023-11-29 [email protected] Roll Flutter Engine from 4beaa1195b74 to fbb2b1e880fa (1 revision) (flutter/flutter#139191)
2023-11-29 [email protected] Roll Flutter Engine from 570fec4fa92c to 4beaa1195b74 (3 revisions) (flutter/flutter#139190)
2023-11-29 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reland Add platform view wide gamut test" (flutter/flutter#139189)
2023-11-28 [email protected] Move analysis test to shard tests. (flutter/flutter#139161)
2023-11-28 [email protected] Write Tests for API Examples of `snack_bar.0`, `elevated_button.0`, `stepper.0`, `radio.0`, `filled_button.0`, `outlined_button.0` & `card.0` (flutter/flutter#138987)
2023-11-28 [email protected] Implement `switch` expressions in `dev/` (flutter/flutter#139048)
2023-11-28 [email protected] Roll Flutter Engine from 01fcec7214db to 570fec4fa92c (2 revisions) (flutter/flutter#139178)
2023-11-28 [email protected] Fix comment (flutter/flutter#138973)
2023-11-28 [email protected] Added some documentation for OverlayPortal (flutter/flutter#138934)
2023-11-28 [email protected] feature(table-widget): Added intrinsicHeight to TableCellVerticalAlignment enum. (flutter/flutter#130264)
2023-11-28 [email protected] Roll Flutter Engine from 97ede154dcd8 to 01fcec7214db (1 revision) (flutter/flutter#139172)
2023-11-28 [email protected] Ensure Icon vertically centers its icon glyph. (flutter/flutter#138937)
2023-11-28 [email protected] Roll Flutter Engine from fd3a33f8b239 to 97ede154dcd8 (2 revisions) (flutter/flutter#139168)
2023-11-28 [email protected] Roll Flutter Engine from d375d5b95d59 to fd3a33f8b239 (2 revisions) (flutter/flutter#139163)
2023-11-28 [email protected] Roll Flutter Engine from e4b18fa3661e to d375d5b95d59 (2 revisions) (flutter/flutter#139157)
2023-11-28 [email protected] Added keyboardType & textInputAction props to SearchBar, SearchAnchor & SearchAnchor.bar (flutter/flutter#138553)
2023-11-28 [email protected] Fix header formatting typo in PopupMenuButton docs (flutter/flutter#139084)
2023-11-28 [email protected] Fix turbulence seed for all tests with ink sparkles (flutter/flutter#138757)
2023-11-28 [email protected] Renable macOS 13 tests (flutter/flutter#139083)
2023-11-28 [email protected] Roll Flutter Engine from 8715e9b9119d to e4b18fa3661e (1 revision) (flutter/flutter#139142)
2023-11-28 [email protected] Roll Packages from e774e88 to 3c05466 (2 revisions) (flutter/flutter#139140)
2023-11-28 [email protected] Roll Flutter Engine from 6ad827e9a71b to 8715e9b9119d (1 revision) (flutter/flutter#139136)
2023-11-28 [email protected] Roll Flutter Engine from c18d3df967dc to 6ad827e9a71b (1 revision) (flutter/flutter#139135)
2023-11-28 [email protected] Roll Flutter Engine from 1caa7478db0d to c18d3df967dc (1 revision) (flutter/flutter#139133)
2023-11-28 [email protected] Roll Flutter Engine from 4f217e1f9afe to 1caa7478db0d (1 revision) (flutter/flutter#139129)
2023-11-28 [email protected] Fix textScalerOf and maybeTextScalerOf documentations (flutter/flutter#139123)
2023-11-28 [email protected] Roll Flutter Engine from c25cc65720de to 4f217e1f9afe (1 revision) (flutter/flutter#139126)
2023-11-28 [email protected] Roll Flutter Engine from 3381d3ff0df7 to c25cc65720de (1 revision) (flutter/flutter#139121)
2023-11-28 [email protected] Roll Flutter Engine from 96137d05fabc to 3381d3ff0df7 (4 revisions) (flutter/flutter#139119)
...
caseycrogers pushed a commit to caseycrogers/flutter that referenced this pull request Dec 29, 2023
…context's text scaler (flutter#135708)

Provide a parameter `applyTextScaling` to both `Icon` and `IconDataTheme`. When `true`, the context's `TextScaler` will apply it's `scale` method to the icon size.

Fixes flutter#115466
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2024
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 autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Icon widget does not scale with textScaleFactor

4 participants