Skip to content

Commit 39dad99

Browse files
authored
Add one MenuAnchor alignment test (#158915)
This PR adds a `MenuAnchor` test to check that `MenuAnchor.alignmentOffset` is correctly applied when `MenuAnchor.layerlink` is provided. While reviewing flutter/flutter#158255, I found that this new test would be useful.
1 parent c1ee381 commit 39dad99

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/flutter/test/material/menu_anchor_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,46 @@ void main() {
39203920
tester.getRect(find.byKey(contentKey)).bottom,
39213921
);
39223922
});
3923+
3924+
testWidgets('Menu is correctly offsetted when a LayerLink is provided and alignmentOffset is set', (WidgetTester tester) async {
3925+
final MenuController controller = MenuController();
3926+
final UniqueKey contentKey = UniqueKey();
3927+
const double horizontalOffset = 16.0;
3928+
const double verticalOffset = 20.0;
3929+
3930+
await tester.pumpWidget(MaterialApp(
3931+
home: Scaffold(
3932+
body: Center(
3933+
child: MenuAnchor(
3934+
controller: controller,
3935+
layerLink: LayerLink(),
3936+
alignmentOffset: const Offset(horizontalOffset, verticalOffset),
3937+
menuChildren: <Widget>[
3938+
MenuItemButton(
3939+
onPressed: () {},
3940+
child: const Text('Button 1'),
3941+
),
3942+
],
3943+
builder: (BuildContext context, MenuController controller, Widget? child) {
3944+
return SizedBox(key: contentKey, width: 100, height: 100);
3945+
},
3946+
),
3947+
),
3948+
),
3949+
));
3950+
3951+
controller.open();
3952+
await tester.pump();
3953+
3954+
expect(
3955+
tester.getRect(findMenuPanels()).top,
3956+
tester.getRect(find.byKey(contentKey)).bottom + verticalOffset,
3957+
);
3958+
expect(
3959+
tester.getRect(findMenuPanels()).left,
3960+
tester.getRect(find.byKey(contentKey)).left + horizontalOffset,
3961+
);
3962+
});
39233963
});
39243964

39253965
group('LocalizedShortcutLabeler', () {

0 commit comments

Comments
 (0)