Repository navigation
[material_ui] Ensure textScaler is taken into account for SnackBar action overflow - #12737
Conversation
…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.
There was a problem hiding this comment.
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.
|
@Piinks This has now been ported over from flutter/flutter#181959 with unit tests and pending changelog following #188444. Ready for review! |
Piinks
left a comment
There was a problem hiding this comment.
Thanks for porting this over and adding tests! :)
Some tests are failing, but I left info on how to fix below:
| if (!willOverflowAction) ...maybeActionAndIcon, | ||
| if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4), | ||
| ], |
There was a problem hiding this comment.
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:
| if (!willOverflowAction) ...maybeActionAndIcon, | |
| if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4), | |
| ], | |
| if (!willOverflowAction) ...maybeActionAndIcon, | |
| if (willOverflowAction && widget.padding == null) | |
| SizedBox(width: horizontalPadding), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We should also add a unit test to verify the SnackBar.padding is respected.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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:
| data: MediaQueryData(size: const Size(400, 800), textScaler: textScaler), | |
| data: MediaQueryData(size: const Size(800, 600), textScaler: textScaler), |
… horizontalPadding
Piinks
left a comment
There was a problem hiding this comment.
LGTM thank you! Let me get a second reviewer for this
QuncCccccc
left a comment
There was a problem hiding this comment.
Overall looks good. Just left a few comments.
| if (!willOverflowAction) ...maybeActionAndIcon, | ||
| if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4), | ||
| ], |
There was a problem hiding this comment.
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.
| if (!willOverflowAction) ...maybeActionAndIcon, | ||
| if (willOverflowAction) SizedBox(width: snackBarWidth * 0.4), | ||
| ], |
There was a problem hiding this comment.
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.
|
Hi! Seems |
|
@QuncCccccc Fixed the 3 |
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
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
Port of flutter/flutter#181959 to
flutter/packagesas 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
MediaQuery.textScalerOf(context)toactionTextPainterso thatactionAndIconWidthproperly scales with accessibility text scaling.SizedBox(width: snackBarWidth * 0.4)when the action overflows, eliminating unintended blank space on the right of multi-line content.snack_bar_test.dartverifyingtextScaleroverflow calculation and layout.Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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