Skip to content

[material/menu_anchor.dart] Ensure positioned menus always begin animating at the target position#182932

Merged
davidhicks980 merged 5 commits into
flutter:masterfrom
davidhicks980:menu_anchor_animation_fix
Mar 10, 2026
Merged

[material/menu_anchor.dart] Ensure positioned menus always begin animating at the target position#182932
davidhicks980 merged 5 commits into
flutter:masterfrom
davidhicks980:menu_anchor_animation_fix

Conversation

@davidhicks980

@davidhicks980 davidhicks980 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

This PR makes animated positioned menus (usually context menus that treat the whole screen as a menu anchor) begin opening at the user's pointer rather than the top or bottom of the menu anchor.

Fixes #182929

Before:

Screen.Recording.2026-02-26.at.12.46.32.AM.mov

After (the menu closes on left-click, but repositions on right-click, unless it is external to the red menu anchor surface)

Screen.Recording.2026-02-26.at.2.03.44.AM.mov

If possible, we should make sure this lands in stable when the menu animations land in stable.

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

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Feb 26, 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 adjusts the positioning logic for animated menus in _MenuLayout. In getPositionForChild, it now checks if menuPosition is provided. If so, it returns the calculated finalPosition immediately, which prevents the menu from animating its position from the anchor's edge. This ensures menus opened at a specific coordinate start their animation at that target position. A new widget test is added to confirm this behavior.

@dkwingsmt

Copy link
Copy Markdown
Contributor

In your "after" video, I noticed that the menu repositions when you click outside. Is it intentional or a bug? It feels like a bug to me. (According to your video, it seems that this only happens if you click after the animation has settled.)

@davidhicks980

Copy link
Copy Markdown
Contributor Author

@dkwingsmt That's because I recorded a dumb video where I mixed right and left clicks. I'll update the video.

@dkwingsmt

dkwingsmt commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

@dkwingsmt That's because I recorded a dumb video where I mixed right and left clicks. I'll update the video.

I thought about it. But honestly I think this isn't the right behavior for either right clicks and left clicks.

@davidhicks980

Copy link
Copy Markdown
Contributor Author

@dkwingsmt This is currently how MacOS menus work and Angular Material menus work: https://rc.material.angular.dev/components/menu/overview#context-menu. However, we can always change the behavior with another PR. The main purpose of this PR is to fix the position where the menu opens.

@dkwingsmt dkwingsmt 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 for the fix!

@davidhicks980 davidhicks980 enabled auto-merge March 10, 2026 20:41
@davidhicks980 davidhicks980 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into flutter:master with commit 3c16f55 Mar 10, 2026
72 checks passed
@davidhicks980 davidhicks980 deleted the menu_anchor_animation_fix branch March 10, 2026 22:29
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Mar 11, 2026
flutter/flutter@195ae7b...3f400d7

2026-03-11 jason-simmons@users.noreply.github.com Roll Clang to 80743bd43fd5b38fedc503308e7a652e23d3ec93 (flutter/flutter#182919)
2026-03-11 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 8C_qfgWgoNhkV0_Mn... to QD887D4OanteB7UKM... (flutter/flutter#183492)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from fecf806be5d0 to 8531f7c2bdae (2 revisions) (flutter/flutter#183489)
2026-03-11 planetmarshall@users.noreply.github.com [impeller] Use the GLES3 shaders in the embedder if supported (flutter/flutter#180072)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from ae2be9700800 to fecf806be5d0 (1 revision) (flutter/flutter#183482)
2026-03-11 97480502+b-luk@users.noreply.github.com Add GLES support for the same pixel formats for copying texture -> buffer as when copying buffer -> texture (flutter/flutter#183428)
2026-03-11 engine-flutter-autoroll@skia.org Roll Skia from 257d04225d0c to 0cab3e4ee34b (8 revisions) (flutter/flutter#183476)
2026-03-10 jacksongardner@google.com Fix GitHub workflows to use the `flutteractionsbot` mirror for PR branches. (flutter/flutter#183470)
2026-03-10 59215665+davidhicks980@users.noreply.github.com [material/menu_anchor.dart] Ensure positioned menus always begin animating at the target position (flutter/flutter#182932)
2026-03-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183467)
2026-03-10 engine-flutter-autoroll@skia.org Roll Dart SDK from ebef6c849489 to ae2be9700800 (4 revisions) (flutter/flutter#183460)
2026-03-10 engine-flutter-autoroll@skia.org Roll Skia from 4b35832cc7ea to 257d04225d0c (5 revisions) (flutter/flutter#183457)
2026-03-10 srawlins@google.com dev: Use a super-parameter in several missed cases (flutter/flutter#182251)

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 stuartmorgan@google.com 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
okorohelijah pushed a commit to okorohelijah/packages that referenced this pull request Mar 26, 2026
…r#11228)

flutter/flutter@195ae7b...3f400d7

2026-03-11 jason-simmons@users.noreply.github.com Roll Clang to 80743bd43fd5b38fedc503308e7a652e23d3ec93 (flutter/flutter#182919)
2026-03-11 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 8C_qfgWgoNhkV0_Mn... to QD887D4OanteB7UKM... (flutter/flutter#183492)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from fecf806be5d0 to 8531f7c2bdae (2 revisions) (flutter/flutter#183489)
2026-03-11 planetmarshall@users.noreply.github.com [impeller] Use the GLES3 shaders in the embedder if supported (flutter/flutter#180072)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from ae2be9700800 to fecf806be5d0 (1 revision) (flutter/flutter#183482)
2026-03-11 97480502+b-luk@users.noreply.github.com Add GLES support for the same pixel formats for copying texture -> buffer as when copying buffer -> texture (flutter/flutter#183428)
2026-03-11 engine-flutter-autoroll@skia.org Roll Skia from 257d04225d0c to 0cab3e4ee34b (8 revisions) (flutter/flutter#183476)
2026-03-10 jacksongardner@google.com Fix GitHub workflows to use the `flutteractionsbot` mirror for PR branches. (flutter/flutter#183470)
2026-03-10 59215665+davidhicks980@users.noreply.github.com [material/menu_anchor.dart] Ensure positioned menus always begin animating at the target position (flutter/flutter#182932)
2026-03-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183467)
2026-03-10 engine-flutter-autoroll@skia.org Roll Dart SDK from ebef6c849489 to ae2be9700800 (4 revisions) (flutter/flutter#183460)
2026-03-10 engine-flutter-autoroll@skia.org Roll Skia from 4b35832cc7ea to 257d04225d0c (5 revisions) (flutter/flutter#183457)
2026-03-10 srawlins@google.com dev: Use a super-parameter in several missed cases (flutter/flutter#182251)

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 stuartmorgan@google.com 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
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…ating at the target position (flutter#182932)

This PR makes animated positioned menus (usually context menus that
treat the whole screen as a menu anchor) begin opening at the user's
pointer rather than the top or bottom of the menu anchor.

Fixes flutter#182929

Before: 


https://github.com/user-attachments/assets/5e536db6-2903-463c-82d1-9f8e8a304bd2

After (the menu closes on left-click, but repositions on right-click,
unless it is external to the red menu anchor surface)


https://github.com/user-attachments/assets/52597be3-2bfe-441c-b962-52b47f69b413

If possible, we should make sure this lands in stable when the menu
animations land in stable.

## 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
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…ating at the target position (flutter#182932)

This PR makes animated positioned menus (usually context menus that
treat the whole screen as a menu anchor) begin opening at the user's
pointer rather than the top or bottom of the menu anchor.

Fixes flutter#182929

Before: 


https://github.com/user-attachments/assets/5e536db6-2903-463c-82d1-9f8e8a304bd2

After (the menu closes on left-click, but repositions on right-click,
unless it is external to the red menu anchor surface)


https://github.com/user-attachments/assets/52597be3-2bfe-441c-b962-52b47f69b413

If possible, we should make sure this lands in stable when the menu
animations land in stable.

## 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
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11228)

flutter/flutter@195ae7b...3f400d7

2026-03-11 jason-simmons@users.noreply.github.com Roll Clang to 80743bd43fd5b38fedc503308e7a652e23d3ec93 (flutter/flutter#182919)
2026-03-11 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 8C_qfgWgoNhkV0_Mn... to QD887D4OanteB7UKM... (flutter/flutter#183492)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from fecf806be5d0 to 8531f7c2bdae (2 revisions) (flutter/flutter#183489)
2026-03-11 planetmarshall@users.noreply.github.com [impeller] Use the GLES3 shaders in the embedder if supported (flutter/flutter#180072)
2026-03-11 engine-flutter-autoroll@skia.org Roll Dart SDK from ae2be9700800 to fecf806be5d0 (1 revision) (flutter/flutter#183482)
2026-03-11 97480502+b-luk@users.noreply.github.com Add GLES support for the same pixel formats for copying texture -> buffer as when copying buffer -> texture (flutter/flutter#183428)
2026-03-11 engine-flutter-autoroll@skia.org Roll Skia from 257d04225d0c to 0cab3e4ee34b (8 revisions) (flutter/flutter#183476)
2026-03-10 jacksongardner@google.com Fix GitHub workflows to use the `flutteractionsbot` mirror for PR branches. (flutter/flutter#183470)
2026-03-10 59215665+davidhicks980@users.noreply.github.com [material/menu_anchor.dart] Ensure positioned menus always begin animating at the target position (flutter/flutter#182932)
2026-03-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#183467)
2026-03-10 engine-flutter-autoroll@skia.org Roll Dart SDK from ebef6c849489 to ae2be9700800 (4 revisions) (flutter/flutter#183460)
2026-03-10 engine-flutter-autoroll@skia.org Roll Skia from 4b35832cc7ea to 257d04225d0c (5 revisions) (flutter/flutter#183457)
2026-03-10 srawlins@google.com dev: Use a super-parameter in several missed cases (flutter/flutter#182251)

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 stuartmorgan@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[material/menu_anchor.dart] Positioned menu anchor does not animate from position.

2 participants