Skip to content

[material_ui] Ensure textScaler is taken into account for SnackBar action overflow - #12737

Merged
auto-submit[bot] merged 5 commits into
flutter:mainfrom
matasb-google:port-pr-181959-snackbar
Oct 10, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:mainfrom
matasb-google:port-pr-181959-snackbar

Conversation

@matasb-google

Copy link
Copy Markdown
Contributor

Port of flutter/flutter#181959 to flutter/packages as part of the Material decoupling effort (flutter/flutter#188444).

Ensure textScalling is taken into account for Sizing overflow.

Fixes flutter/flutter#192232
Fixes flutter/flutter#181959
Part of flutter/flutter#188444

Description

  • Ensure textScalling is taken into account for Sizing overflow: passes MediaQuery.textScalerOf(context) to actionTextPainter so that actionAndIconWidth properly scales with accessibility text scaling.
  • Removes SizedBox(width: snackBarWidth * 0.4) when the action overflows, eliminating unintended blank space on the right of multi-line content.
  • Adds unit tests in snack_bar_test.dart verifying textScaler overflow calculation and layout.
  • Adds pending changelog entry.

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

…tion overflow

Port of flutter/flutter#181959 to flutter/packages as part of the Material decoupling effort (flutter/flutter#188444).

- Ensure MediaQuery's textScaler is passed to actionTextPainter so that action button width calculation scales appropriately.
- Remove SizedBox(width: snackBarWidth * 0.4) when action overflows, eliminating unintended blank space on the right of multi-line content.
- Add unit tests verifying textScaler overflow calculation and layout.
- Add pending changelog entry.
@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Sep 3, 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 updates the SnackBar implementation to respect the MediaQuery's TextScaler when calculating action overflow, and removes the unnecessary 40% blank right spacing in multi-line layouts. It also adds corresponding widget tests to verify these behaviors. There are no review comments, so I have no feedback to provide.

@matasb-google

Copy link
Copy Markdown
Contributor Author

@Piinks This has now been ported over from flutter/flutter#181959 with unit tests and pending changelog following #188444. Ready for review!

@Piinks Piinks added the CICD Run CI/CD label Sep 8, 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.

Thanks for porting this over and adding tests! :)
Some tests are failing, but I left info on how to fix below:

Comment on lines 796 to 797
if (!willOverflowAction) ...maybeActionAndIcon,
if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4),
],

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.

Because default padding sets end: 0 when widget.action != null, removing the SizedBox leaves Row 1 with 0px right padding when the action wraps to Row 2. We should retain horizontalPadding for the content:

Suggested change
if (!willOverflowAction) ...maybeActionAndIcon,
if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4),
],
if (!willOverflowAction) ...maybeActionAndIcon,
if (willOverflowAction && widget.padding == null)
SizedBox(width: horizontalPadding),

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.

I think the suggested change makes sense. Please fix. When custom padding is provided, we should respect it instead of still using the default horizontalPadding.

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.

We should also add a unit test to verify the SnackBar.padding is respected.

@matasb-google matasb-google Oct 1, 2026 •

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.

Done in 1e622ce — gated the spacer SizedBox on widget.padding == null and added the SnackBar respects custom padding when action overflows unit test.


// Verify there is no SizedBox with width equal to 40% of snackBarWidth.
expect(
find.byWidgetPredicate(

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.

snackBarWidth is screenWidth - margin = 470, so the old sized box was 188px, not screenWidth * 0.4 (200px). This predicate would have returned false and passed even on unfixed code. Consider asserting the content's right padding or layout width directly instead.

expect(find.text('bar2'), findsNothing);
}
}

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.

These tests were placed inside _testSnackBarDismiss (outside main()), causing SnackBar dismiss test to throw Bad state: Can't call test() once tests have begun running.. Please move them into void main() { ... } before line 4400.

Widget buildSnackBar({required TextScaler textScaler}) {
return MaterialApp(
home: MediaQuery(
data: MediaQueryData(size: const Size(400, 800), textScaler: textScaler),

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.

On a 400px screen (snackBarWidth = 370), 'Action Label' (~97px) exceeds the 25% threshold (92.5px) and overflows even with TextScaler.noScaling, failing line 4482. Use Size(800, 600) so it fits on line 1 at 1.0x scale and overflows at 3.0x scale:

Suggested change
data: MediaQueryData(size: const Size(400, 800), textScaler: textScaler),
data: MediaQueryData(size: const Size(800, 600), textScaler: textScaler),

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 9, 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 thank you! Let me get a second reviewer for this

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

Overall looks good. Just left a few comments.

Comment on lines 796 to 797
if (!willOverflowAction) ...maybeActionAndIcon,
if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4),
],

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.

I think the suggested change makes sense. Please fix. When custom padding is provided, we should respect it instead of still using the default horizontalPadding.

Comment on lines 796 to 797
if (!willOverflowAction) ...maybeActionAndIcon,
if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4),
],

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.

We should also add a unit test to verify the SnackBar.padding is respected.

Only insert the trailing spacer SizedBox when the default padding is
used, since a caller-supplied padding already applies its own end inset.

Adds a unit test covering asymmetric SnackBar.padding with an
overflowing action.
@Piinks
Piinks requested a review from QuncCccccc September 24, 2026 21:40

@QuncCccccc QuncCccccc 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!

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Oct 2, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 2, 2026
@QuncCccccc QuncCccccc added the CICD Run CI/CD label Oct 2, 2026
@QuncCccccc

Copy link
Copy Markdown
Contributor

Hi! Seems Dashboard Checks has some failures, could you help fix them?

Analyzing material_ui...

   info - test/snack_bar_test.dart:4444:11 - Omit the type annotation on a local variable when the type is obvious. Try removing the type annotation. - omit_obvious_local_variable_types
   info - test/snack_bar_test.dart:4495:11 - Omit the type annotation on a local variable when the type is obvious. Try removing the type annotation. - omit_obvious_local_variable_types
   info - test/snack_bar_test.dart:4496:11 - Omit the type annotation on a local variable when the type is obvious. Try removing the type annotation. - omit_obvious_local_variable_types

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 9, 2026
@matasb-google

Copy link
Copy Markdown
Contributor Author

@QuncCccccc Fixed the 3 omit_obvious_local_variable_types lints in ddaff91 and verified with dart analyze --fatal-infos. Thank you!

@QuncCccccc QuncCccccc added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Oct 9, 2026
@auto-submit
auto-submit Bot merged commit b3d80fe into flutter:main Oct 10, 2026
13 checks passed
@matasb-google
matasb-google deleted the port-pr-181959-snackbar branch October 10, 2026 17:46
andywolff pushed a commit to andywolff/flutter that referenced this pull request Oct 13, 2026
flutter/packages@d8d9e97...a1ed23c

2026-10-13 [email protected] [material_ui] Clarify Slider labels
for continuous sliders (flutter/packages#13121)
2026-10-12 [email protected] [in_app_purchase_storekit] Remove
availability checks below the package minimum iOS 13 and macOS 10.15
(flutter/packages#13217)
2026-10-12 [email protected] [google_sign_in] Convert unit tests
to Kotlin (flutter/packages#13000)
2026-10-12 [email protected]
[vector_graphics_compiler] Support SVG alpha masks (mask-type="alpha")
(flutter/packages#13025)
2026-10-11 [email protected] [camera_platform_interface] Add
zero-shutter-lag API (flutter/packages#12996)
2026-10-10 [email protected] [material_ui]
Ensure textScaler is taken into account for SnackBar action overflow
(flutter/packages#12737)
2026-10-10 [email protected] [material_ui] Add more 0x0 size tests
part 14 (flutter/packages#13107)
2026-10-10 [email protected]
[cupertino_ui] Fix CupertinoPicker throwing when disposed during the
tap-to-select animation (flutter/packages#13012)
2026-10-09 [email protected] Roll Flutter (stable) from
5fc3468 to abaf9c5 (3 revisions) (flutter/packages#13186)

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
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@d8d9e97...a1ed23c

2026-10-13 [email protected] [material_ui] Clarify Slider labels
for continuous sliders (flutter/packages#13121)
2026-10-12 [email protected] [in_app_purchase_storekit] Remove
availability checks below the package minimum iOS 13 and macOS 10.15
(flutter/packages#13217)
2026-10-12 [email protected] [google_sign_in] Convert unit tests
to Kotlin (flutter/packages#13000)
2026-10-12 [email protected]
[vector_graphics_compiler] Support SVG alpha masks (mask-type="alpha")
(flutter/packages#13025)
2026-10-11 [email protected] [camera_platform_interface] Add
zero-shutter-lag API (flutter/packages#12996)
2026-10-10 [email protected] [material_ui]
Ensure textScaler is taken into account for SnackBar action overflow
(flutter/packages#12737)
2026-10-10 [email protected] [material_ui] Add more 0x0 size tests
part 14 (flutter/packages#13107)
2026-10-10 [email protected]
[cupertino_ui] Fix CupertinoPicker throwing when disposed during the
tap-to-select animation (flutter/packages#13012)
2026-10-09 [email protected] Roll Flutter (stable) from
5fc3468 to abaf9c5 (3 revisions) (flutter/packages#13186)

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.

[material_ui] SnackBar action overflow calculation does not account for MediaQuery textScaler

3 participants