diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index 4b19b9b432..d118e620bd 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -972,10 +972,7 @@ class _DropdownMenuState extends State> { ), ), ), - child: Align( - alignment: AlignmentDirectional.topStart, - child: menuAnchor, - ), + child: menuAnchor, ); } diff --git a/packages/flutter/test/material/dropdown_menu_test.dart b/packages/flutter/test/material/dropdown_menu_test.dart index 5ed70d1bd7..ab0992a833 100644 --- a/packages/flutter/test/material/dropdown_menu_test.dart +++ b/packages/flutter/test/material/dropdown_menu_test.dart @@ -3415,6 +3415,43 @@ void main() { tester.getRect(find.byType(TextField).first).bottom, ); }); + + testWidgets('DropdownMenu with expandedInsets can be aligned', (WidgetTester tester) async { + Widget buildMenuAnchor({ AlignmentGeometry alignment = Alignment.topCenter }) { + return MaterialApp( + home: Scaffold( + body: Row( + children: [ + Expanded( + child: Align( + alignment: alignment, + child: DropdownMenu( + expandedInsets: const EdgeInsets.all(16), + dropdownMenuEntries: menuChildren, + ), + ), + ), + ], + ), + ), + ); + } + + await tester.pumpWidget(buildMenuAnchor()); + + Offset textFieldPosition = tester.getTopLeft(find.byType(TextField)); + expect(textFieldPosition, equals(const Offset(16.0, 0.0))); + + await tester.pumpWidget(buildMenuAnchor(alignment: Alignment.center)); + + textFieldPosition = tester.getTopLeft(find.byType(TextField)); + expect(textFieldPosition, equals(const Offset(16.0, 272.0))); + + await tester.pumpWidget(buildMenuAnchor(alignment: Alignment.bottomCenter)); + + textFieldPosition = tester.getTopLeft(find.byType(TextField)); + expect(textFieldPosition, equals(const Offset(16.0, 544.0))); + }); } enum TestMenu {