Repository navigation
[material_ui] Fix MenuAnchor scrollbar safe-area padding - #12470
auto-submit[bot] merged 4 commits into
Conversation
|
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. |
There was a problem hiding this comment.
Code Review
This pull request prevents MenuAnchor scrollbars from inheriting system safe-area padding by removing padding from the MediaQuery surrounding the Scrollbar and restoring it for the inner scroll view. A regression test and a changelog entry are also included. The feedback suggests optimizing the implementation by using mediaQuery.removePadding(...) directly on the already retrieved MediaQueryData instance, avoiding redundant MediaQuery.of(context) lookups.
| final EdgeInsetsGeometry padding = | ||
| resolve<EdgeInsetsGeometry?>((MenuStyle? style) => style?.padding) ?? EdgeInsets.zero; | ||
| final Offset densityAdjustment = visualDensity.baseSizeAdjustment; | ||
| final MediaQueryData mediaQuery = MediaQuery.of(context); |
There was a problem hiding this comment.
Thank you! Removing the system padding for just the scrollbar looks good to me. To make it clear why we are doing so, do you mind adding a comment here and renaming the two MediaQuery instances to something like ambientMediaQuery and scrollbarMediaQuery?
There was a problem hiding this comment.
Done. Added a comment explaining why the padding is dropped for the scrollbar, and renamed the values to ambientMediaQuery and scrollbarMediaQuery.
| testWidgets('Menu scrollbar does not inherit MediaQuery padding', (WidgetTester tester) async { | ||
| addTearDown(tester.view.reset); | ||
| tester.view.devicePixelRatio = 1.0; | ||
| tester.view.padding = const FakeViewPadding(bottom: 24.0); |
There was a problem hiding this comment.
Maybe add padding on all four sides to verify they are all removed for the scrollbar but retained on menuItemPadding.
There was a problem hiding this comment.
Done. The view padding is now FakeViewPadding(left: 8, top: 16, right: 32, bottom: 24), and the test asserts scrollbarPainter.padding is EdgeInsets.zero while menuItemPadding is still EdgeInsets.fromLTRB(8, 16, 32, 24). Without the source change the painter padding comes back as EdgeInsets(8.0, 16.0, 32.0, 24.0).
| }, variant: TargetPlatformVariant.desktop()); | ||
|
|
||
| // Regression test for https://github.com/flutter/flutter/issues/188155. | ||
| testWidgets('Menu scrollbar does not inherit MediaQuery padding', (WidgetTester tester) async { |
There was a problem hiding this comment.
Consider testing that we can scroll all the way to the bottom as well since the issue mentions the scrollbar getting stuck there.
There was a problem hiding this comment.
Done. The test now drags the menu to the end and asserts position.pixels == position.maxScrollExtent, then checks that the painted thumb ends at the bottom of the scrollbar box. I verified that last assertion is not vacuous: with the source change reverted it fails on its own, because the track stops 24 logical pixels short and the thumb never reaches the end.
3db34ec to
bdc4cc4
Compare
|
Thanks for the review @elliette — all three comments are addressed, and the branch is rebased onto current Validation on the new head:
Reverting only the One note on CI: the only red job on the previous run was The push also cleared the |
QuncCccccc
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the fix!
| // Material's Scrollbar uses the ambient MediaQuery padding as its painter | ||
| // padding when no explicit padding is given, so that the thumb clears | ||
| // system intrusions such as a gesture bar. The menu overlay is already | ||
| // positioned inside the safe area, so honoring that padding a second time | ||
| // shortens the scrollbar track and stops the thumb from reaching the end of | ||
| // the menu. The padding is therefore removed for the Scrollbar only and | ||
| // restored below it, so menu children keep observing the ambient values. |
There was a problem hiding this comment.
| // Material's Scrollbar uses the ambient MediaQuery padding as its painter | |
| // padding when no explicit padding is given, so that the thumb clears | |
| // system intrusions such as a gesture bar. The menu overlay is already | |
| // positioned inside the safe area, so honoring that padding a second time | |
| // shortens the scrollbar track and stops the thumb from reaching the end of | |
| // the menu. The padding is therefore removed for the Scrollbar only and | |
| // restored below it, so menu children keep observing the ambient values. | |
| // Scrollbar uses the `MadiaQuery.padding` as its painter | |
| // padding by default. Menu overlays are already | |
| // positioned within the safe area, so applying that padding again | |
| // shortens the scrollbar track and stops the thumb from reaching the end of | |
| // the menu. Remove the padding only for the Scrollbar and restore the ambient MediaQuery for menu children. |
There was a problem hiding this comment.
Thanks for the suggestion. I left the existing comment in place: this wording uses MadiaQuery, and the current comment already explains why the padding is removed only for the scrollbar.
I did not push a follow-up. This head is approved with green CI, and a new push clears the CICD label, which I cannot restore. Happy to apply a corrected comment if you want that wording — it would need CICD added again. Otherwise this looks ready to land.
There was a problem hiding this comment.
Please update the comment to reflect @QuncCccccc's suggestion. MadiaQuery is a typo, it should be MediaQuery. We will re-add the CICD label after.
There was a problem hiding this comment.
Done in 0f6d17b — the comment now uses @QuncCccccc's wording, with the typo fixed to MediaQuery.padding and the lines rewrapped to 80 columns. No code changes; menu_anchor_test.dart still passes (171 passed, 1 skipped) and dart format / flutter analyze are clean.
Thanks for re-adding CICD!
Explain why the menu Scrollbar drops the ambient MediaQuery padding and name the two MediaQueryData values after their roles. Extend the regression test to pad all four sides, and assert that the menu still scrolls to the very bottom with the scrollbar thumb reaching the end of its track.
0f6d17b to
f304493
Compare
elliette
left a comment
There was a problem hiding this comment.
Thanks for your patience! Looks good
flutter/packages@93baed9...108dad0 2026-10-22 [email protected] [material_ui] Migrate M3 IconButton template to use new gen_defaults (flutter/packages#12922) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationBar template to use new gen_defaults (flutter/packages#13067) 2026-10-22 [email protected] [material_ui] Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276) 2026-10-22 [email protected] [material_ui] Migrate M3 Radio template to use new gen_defaults (flutter/packages#13210) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationDrawer template to use new gen_defaults (flutter/packages#13068) 2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split SPM packaging and migrate the plugin class to Swift (flutter/packages#13235) 2026-10-22 [email protected] [ci] Increase check-discovery timeout in release workflows (flutter/packages#13392) 2026-10-22 [email protected] [material_ui] Migrate M3 `Switch` template to use new gen_defaults (flutter/packages#13274) 2026-10-22 [email protected] [material_ui] Migrate M3 PopupMenu template to use new gen_defaults (flutter/packages#13209) 2026-10-22 [email protected] [material_ui] Add day and weekday builders to CalendarDatePicker and showDatePicker (flutter/packages#12587) 2026-10-22 [email protected] [material_ui] Migrate M3 `SearchView` template to use new gen_defaults (flutter/packages#13272) 2026-10-22 [email protected] [material_ui] Migrate M3 `TextField` template to use new gen_defaults (flutter/packages#13275) 2026-10-22 [email protected] [material_ui] Migrate M3 RangeSlider template to use new gen_defaults (flutter/packages#13215) 2026-10-22 [email protected] [go_router] Keep web autocomplete focused in shell routes (flutter/packages#13348) 2026-10-22 [email protected] [shared_preferences_android] Fix web compilation of apps that import the package (flutter/packages#13380) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationRail template to use new gen_defaults (flutter/packages#13069) 2026-10-22 [email protected] [material_ui] Migrate M3 SearchBar template to use new gen_defaults (flutter/packages#13216) 2026-10-22 [email protected] [material_ui] Fix for time picker error in locales that do not use Latin digits (flutter/packages#13035) 2026-10-22 [email protected] [material_ui] Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470) 2026-10-22 [email protected] [material_ui] Document Material 3 fallback for Divider.color and VerticalDivider.color (flutter/packages#12967) 2026-10-22 [email protected] [material_ui] Migrate M3 tabs template to use new gen_defaults (flutter/packages#13139) 2026-10-22 [email protected] [material_ui] Migrate M3 progress indicator defaults to new gen_defaults (flutter/packages#13026) 2026-10-22 [email protected] [google_sign_in] Convert the iOS example app and UI tests to Swift (flutter/packages#13271) 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@93baed9...108dad0 2026-10-22 [email protected] [material_ui] Migrate M3 IconButton template to use new gen_defaults (flutter/packages#12922) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationBar template to use new gen_defaults (flutter/packages#13067) 2026-10-22 [email protected] [material_ui] Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276) 2026-10-22 [email protected] [material_ui] Migrate M3 Radio template to use new gen_defaults (flutter/packages#13210) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationDrawer template to use new gen_defaults (flutter/packages#13068) 2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split SPM packaging and migrate the plugin class to Swift (flutter/packages#13235) 2026-10-22 [email protected] [ci] Increase check-discovery timeout in release workflows (flutter/packages#13392) 2026-10-22 [email protected] [material_ui] Migrate M3 `Switch` template to use new gen_defaults (flutter/packages#13274) 2026-10-22 [email protected] [material_ui] Migrate M3 PopupMenu template to use new gen_defaults (flutter/packages#13209) 2026-10-22 [email protected] [material_ui] Add day and weekday builders to CalendarDatePicker and showDatePicker (flutter/packages#12587) 2026-10-22 [email protected] [material_ui] Migrate M3 `SearchView` template to use new gen_defaults (flutter/packages#13272) 2026-10-22 [email protected] [material_ui] Migrate M3 `TextField` template to use new gen_defaults (flutter/packages#13275) 2026-10-22 [email protected] [material_ui] Migrate M3 RangeSlider template to use new gen_defaults (flutter/packages#13215) 2026-10-22 [email protected] [go_router] Keep web autocomplete focused in shell routes (flutter/packages#13348) 2026-10-22 [email protected] [shared_preferences_android] Fix web compilation of apps that import the package (flutter/packages#13380) 2026-10-22 [email protected] [material_ui] Migrate M3 NavigationRail template to use new gen_defaults (flutter/packages#13069) 2026-10-22 [email protected] [material_ui] Migrate M3 SearchBar template to use new gen_defaults (flutter/packages#13216) 2026-10-22 [email protected] [material_ui] Fix for time picker error in locales that do not use Latin digits (flutter/packages#13035) 2026-10-22 [email protected] [material_ui] Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470) 2026-10-22 [email protected] [material_ui] Document Material 3 fallback for Divider.color and VerticalDivider.color (flutter/packages#12967) 2026-10-22 [email protected] [material_ui] Migrate M3 tabs template to use new gen_defaults (flutter/packages#13139) 2026-10-22 [email protected] [material_ui] Migrate M3 progress indicator defaults to new gen_defaults (flutter/packages#13026) 2026-10-22 [email protected] [google_sign_in] Convert the iOS example app and UI tests to Swift (flutter/packages#13271) 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
Material
Scrollbaruses the surroundingMediaQuery.paddingas painter padding when no explicit padding is provided. AMenuAnchoroverlay is already positioned within the safe area, so inheriting the view padding again shortens the scrollbar track and prevents the thumb from reaching its visual end.This change removes safe-area padding only for the menu's
Scrollbar, then restores the originalMediaQueryDatabelow it so custom menu children continue to observe the same media query values as before. It also adds a regression test and a patch changelog entry.Fixes flutter/flutter#188155.
This supersedes flutter/flutter#191085, which cannot land in
flutter/flutterbecause Material framework changes have moved tomaterial_ui.Validation:
flutter test test/menu_anchor_test.dart(171 passed, 1 skipped)flutter analyze --no-pubflutter_plugin_tools format --packages=material_uiflutter_plugin_tools validate --packages=material_ui --check-for-missing-changesPre-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