Commit d18ad52
[widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter#182357)
This PR corrects the order in which onClose() and onCloseRequested() is
called by a RawMenuAnchor tree.
Per @dkwingsmt:
> A close is immediate and should close children immediately before
closing itself, while a closeRequest [can be] async and should
closeRequest children.
Before, calling close() on a parent would call handleCloseRequest() on
its children, leading to children (potentially) finishing their closure
after their parents.
Additionally, if a RawMenuAnchor is already closed, it will not trigger
onCloseRequested.
**Details:**
The handleCloseRequest portion of the
_RawMenuAnchorBaseMixin.closeChildren function has been moved into a
requestChildrenClose function to be more explicit.
Additionally, this PR makes handleCloseRequest call
requestChildrenClose() after calling widget.onCloseRequested on
_RawMenuAnchorState. This makes submenus begin closing after their
parent menu begins closing. I also modified the menu_anchor.dart and
raw_menu_anchor.3.dart code to remove a closeChildren call (now
redundant).
Last, this PR makes handleCloseRequest short-circuit if a menu isn't
open. This prevents unncessary widget.onCloseRequest calls when a
submenu is opened, since all sibling menus call handleCloseRequest
before the submenu begins opening.
This is a breaking change. I had to modify one of the DismissMenuAnchor
tests since onCloseRequested is now called on all descendants when a
dismissal occurs. I think it's best to introduce this change because it
can lead to hard-to-track behavior when creating menus (that's how I
discovered it).
Migration guide: flutter/website#13145
Additional tests were added to check the opening and closing behavior.
Fixes flutter#182355
## 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].
- [] 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
---------
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>1 parent d79a56b commit d18ad52
4 files changed
Lines changed: 340 additions & 66 deletions
File tree
- packages/flutter
- lib/src
- material
- widgets
- test/widgets
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | 184 | | |
188 | 185 | | |
189 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
656 | 656 | | |
657 | 657 | | |
658 | 658 | | |
659 | | - | |
660 | 659 | | |
661 | 660 | | |
662 | 661 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
317 | 330 | | |
318 | 331 | | |
319 | 332 | | |
| |||
600 | 613 | | |
601 | 614 | | |
602 | 615 | | |
603 | | - | |
| 616 | + | |
604 | 617 | | |
605 | | - | |
606 | | - | |
| 618 | + | |
| 619 | + | |
607 | 620 | | |
608 | 621 | | |
609 | 622 | | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
610 | 627 | | |
611 | 628 | | |
612 | 629 | | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
619 | 650 | | |
620 | 651 | | |
621 | 652 | | |
| |||
626 | 657 | | |
627 | 658 | | |
628 | 659 | | |
629 | | - | |
| 660 | + | |
630 | 661 | | |
631 | 662 | | |
632 | 663 | | |
| |||
708 | 739 | | |
709 | 740 | | |
710 | 741 | | |
711 | | - | |
| 742 | + | |
712 | 743 | | |
713 | 744 | | |
714 | 745 | | |
| |||
731 | 762 | | |
732 | 763 | | |
733 | 764 | | |
| 765 | + | |
734 | 766 | | |
| 767 | + | |
735 | 768 | | |
736 | 769 | | |
737 | 770 | | |
| |||
764 | 797 | | |
765 | 798 | | |
766 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
767 | 804 | | |
768 | 805 | | |
769 | 806 | | |
| |||
779 | 816 | | |
780 | 817 | | |
781 | 818 | | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
782 | 822 | | |
783 | 823 | | |
784 | 824 | | |
| |||
939 | 979 | | |
940 | 980 | | |
941 | 981 | | |
942 | | - | |
| 982 | + | |
943 | 983 | | |
944 | 984 | | |
945 | 985 | | |
| |||
1018 | 1058 | | |
1019 | 1059 | | |
1020 | 1060 | | |
1021 | | - | |
| 1061 | + | |
1022 | 1062 | | |
1023 | 1063 | | |
1024 | 1064 | | |
| |||
0 commit comments