Skip to content
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

Fix: Menu anchor respect alignment offset for right #164858

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rkishan516
Copy link
Contributor

Fix: Menu anchor respect alignment offset for right
fixes: #159413

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • 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.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Mar 9, 2025
@rkishan516 rkishan516 force-pushed the menu-anchor-alignment branch 2 times, most recently from 41c35b8 to 4a8f410 Compare March 9, 2025 08:48
await changeSurfaceSize(tester, const Size(800, 600));
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be omitted if this is not specific to M2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be consistent with other tests, specifically alignment test of menu anchor.

Copy link
Member

@TahaTesser TahaTesser Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem like old tests, not yet migrated to M3.

For your new tests, if the results are different in M2 and M3, please split them two tests. Each test should you should the following naming scheme.

Material 2 - xxx

Material3 - xxx

Otherwise, if the results are same in both M2 and M3 then you can remove ThemeData(useMaterial3: false) from this test.

home: Builder(
builder: (BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directionality is provided by MaterialApp, this can be skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

expect(find.byType(MenuItemButton), findsOneWidget);
expect(
collectSubmenuRects(),
equals(const <Rect>[Rect.fromLTRB(634.0, 488.0, 756.0, 552.0)]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could please add a comment on how these numbers verify "menus should respect overflow on right with the provided offset"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@rkishan516 rkishan516 force-pushed the menu-anchor-alignment branch from 4a8f410 to 4e37fcd Compare March 12, 2025 01:56
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running test code without this PR and with this PR has no difference. In fact, the PR test also passes without the fix.

Code Sample

expand to view the code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: false),
      home: Align(
        alignment: Alignment.bottomRight,
        child: MenuAnchor(
          alignmentOffset: const Offset(-50, 0),
          menuChildren: const <Widget>[MenuItemButton(child: Text('Button1'))],
          builder: (BuildContext context, MenuController controller, Widget? child) {
            return FilledButton(
              onPressed: () {
                if (controller.isOpen) {
                  controller.close();
                } else {
                  controller.open();
                }
              },
              child: const Text('Tap me'),
            );
          },
        ),
      ),
    );
  }
}
Screenshot 2025-03-12 at 16 38 53

Please make sure the fix is effective. Update PR description with before and after to showcase the fix visually.

await changeSurfaceSize(tester, const Size(800, 600));
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
Copy link
Member

@TahaTesser TahaTesser Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem like old tests, not yet migrated to M3.

For your new tests, if the results are different in M2 and M3, please split them two tests. Each test should you should the following naming scheme.

Material 2 - xxx

Material3 - xxx

Otherwise, if the results are same in both M2 and M3 then you can remove ThemeData(useMaterial3: false) from this test.

@rkishan516
Copy link
Contributor Author

Running test code without this PR and with this PR has no difference. In fact, the PR test also passes without the fix.

Code Sample

expand to view the code sample
Screenshot 2025-03-12 at 16 38 53
Please make sure the fix is effective. Update PR description with before and after to showcase the fix visually.

Ohh, I think this need to have one change to see effect that offset should be positive.
Also, for both M2 and M3 result is going to be same, so i will remove material2 condition.

@rkishan516 rkishan516 force-pushed the menu-anchor-alignment branch 3 times, most recently from be239dd to 119e0cf Compare March 12, 2025 15:55
@rkishan516 rkishan516 force-pushed the menu-anchor-alignment branch from 119e0cf to 20778fa Compare March 12, 2025 16:06
@rkishan516 rkishan516 requested a review from TahaTesser March 12, 2025 16:07
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.

Menu Anchor alignment offset does not work when right alignment is set
2 participants