-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[material/menu_anchor.dart] Create internal menu controller if external controller is changed to null. #176375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material/menu_anchor.dart] Create internal menu controller if external controller is changed to null. #176375
Conversation
There was a problem hiding this comment.
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 correctly fixes a bug in MenuAnchor where an internal MenuController was not being created when an external controller was removed during a widget update. The logic in didUpdateWidget is now correct, and the addition of a regression test is a great way to prevent this issue from recurring. I have one minor suggestion to make the code slightly more concise.
| if (widget.controller == null) { | ||
| _internalMenuController = MenuController(); | ||
| } else { | ||
| _internalMenuController = null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this if/else block is correct, you can achieve the same result more concisely by using a ternary operator. This also makes the logic clearer at a glance, as the original bug was a simple != null check instead of == null in a similar ternary expression.
_internalMenuController = widget.controller == null ? MenuController() : null;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it easier to read blocks, which may be why I introduced the bug in the first place 😞
dkwingsmt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
| super.didUpdateWidget(oldWidget); | ||
| if (oldWidget.controller != widget.controller) { | ||
| _internalMenuController = widget.controller != null ? MenuController() : null; | ||
| if (widget.controller == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is ok, I find the following logic slightly easier to understand:
Change MenuController get _menuController this way:
MenuController get _menuController {
if (widget.controller != null)
return widget.controller;
return _internalMenuController ??= MenuController();
}Then change didUpdateWidget this way:
@override
void didUpdateWidget(MenuAnchor oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
// Use a separate line to rebuild _internalMenuController when necessary
final MenuController effectiveController = _menuController;
if (effectiveController != _internalMenuController)
_internalMenuController = null;
}
}What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the update a little harder to follow since it requires jumping between two parts of the code and adds an additional variable (effectiveController). But, that could be because I'm looking at it with fresh eyes.
Not that performance is too concerning in this situation, but wouldn't _internalMenuController ??= MenuController(); require an additional null check every time _menuController is accessed?
Either way, your call! I don't mind as long as I fix the bug I introduced 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go ahead and merge, but let me know if you want me to update this later!
… if external controller is changed to null. (flutter/flutter#176375)
… if external controller is changed to null. (flutter/flutter#176375)
… if external controller is changed to null. (flutter/flutter#176375)
… if external controller is changed to null. (flutter/flutter#176375)
… if external controller is changed to null. (flutter/flutter#176375)
… if external controller is changed to null. (flutter/flutter#176375)
…10244) Manual roll requested by [email protected] flutter/flutter@7cd821c...a873a27 2025-10-16 [email protected] [tool] makes listing a shader also as an asset a build failure (flutter/flutter#176866) 2025-10-16 [email protected] Roll Packages from d062181 to 835dccb (7 revisions) (flutter/flutter#177100) 2025-10-16 [email protected] Handle the new location of Perfetto in create_updated_flutter_deps.py (flutter/flutter#177099) 2025-10-16 [email protected] Implement dialog windows for the win32 platform (flutter/flutter#176309) 2025-10-16 [email protected] `SelectableRegion` should not show flutter rendered context menu when web context menu is enabled (flutter/flutter#176855) 2025-10-16 [email protected] Manual roll Skia to 2d9df7c70b6f (flutter/flutter#177074) 2025-10-16 [email protected] feat: add `OptionsViewOpenDirection.mostSpace` to `RawAutocomplete` (flutter/flutter#172997) 2025-10-16 [email protected] [Android] Refactor `ImageReaderSurfaceProducer` restoration after app resumes (flutter/flutter#175937) 2025-10-15 [email protected] Refactor: migrate fade upwards page transition builder to widgets (flutter/flutter#175560) 2025-10-15 [email protected] Marks Windows windowing_test to be unflaky (flutter/flutter#176701) 2025-10-15 [email protected] fix: 🐛 Add equality and hashCode implementations to ScrollAwareImageProvider (flutter/flutter#175038) 2025-10-15 [email protected] Updates `sliver_tree.1.dart` to use `MediaQuery.widthOf(context)` (flutter/flutter#176888) 2025-10-15 [email protected] [web] Fix focus issues in newer versions of Chrome (flutter/flutter#176938) 2025-10-15 [email protected] [Android 16] Update `android_engine_vulkan_tests` to Test Against SDK 36 Emulator (flutter/flutter#176985) 2025-10-15 [email protected] Fix key events interception by RadioGroup when no Radio is focused. (flutter/flutter#176335) 2025-10-15 [email protected] Update cherry-pick instructions to include instructions for pre-release CPs (flutter/flutter#177020) 2025-10-15 [email protected] Manual roll Skia to c501c727a007 (flutter/flutter#177015) 2025-10-15 [email protected] Update examples to latest Linux runner style (flutter/flutter#177033) 2025-10-15 [email protected] [material/menu_anchor.dart] Create internal menu controller if external controller is changed to null. (flutter/flutter#176375) 2025-10-15 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix - TalkBack does not announce list information (#174374)" (flutter/flutter#177062) 2025-10-14 [email protected] Implement Regular Windows for Linux (flutter/flutter#176187) 2025-10-14 [email protected] Fix - TalkBack does not announce list information (flutter/flutter#174374) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
…al controller is changed to null. (flutter#176375) <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> When removing a MenuController from a MenuAnchor, an internal MenuController was not being made. <img width="600" alt="image" src="https://github.com/user-attachments/assets/85078f18-3316-45c9-a2c9-d7f4c5d1c73e" /> My bad for introducing the bug! Fixes flutter#176374 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. 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](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
When removing a MenuController from a MenuAnchor, an internal MenuController was not being made.
My bad for introducing the bug!
Fixes #176374
Pre-launch 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-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.