diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index c27e496eef..6deba5033f 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -703,7 +703,7 @@ class _DropdownMenuState extends State> { final double padding = entry.leadingIcon == null ? (leadingPadding ?? _kDefaultHorizontalPadding) - : (_kDefaultHorizontalPadding + _kLeadingIconToInputPadding); + : _kDefaultHorizontalPadding; ButtonStyle effectiveStyle = entry.style ?? switch (textDirection) { @@ -780,7 +780,13 @@ class _DropdownMenuState extends State> { child: MenuItemButton( key: enableScrollToHighlight ? buttonItemKeys[i] : null, style: effectiveStyle, - leadingIcon: entry.leadingIcon, + leadingIcon: + entry.leadingIcon != null + ? Padding( + padding: const EdgeInsetsDirectional.only(end: _kLeadingIconToInputPadding), + child: entry.leadingIcon, + ) + : null, trailingIcon: entry.trailingIcon, closeOnActivate: widget.closeBehavior == DropdownMenuCloseBehavior.all, onPressed: diff --git a/packages/flutter/test/material/dropdown_menu_test.dart b/packages/flutter/test/material/dropdown_menu_test.dart index 0a38c49388..41a253d07e 100644 --- a/packages/flutter/test/material/dropdown_menu_test.dart +++ b/packages/flutter/test/material/dropdown_menu_test.dart @@ -1125,6 +1125,60 @@ void main() { ); }); + testWidgets('The icon in the menu button should be aligned with the icon of ' + 'the text field - LTR', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Directionality( + textDirection: TextDirection.ltr, + child: DropdownMenu( + leadingIcon: const Icon(Icons.search), + label: const Text('label'), + dropdownMenuEntries: menuChildrenWithIcons, + ), + ), + ), + ), + ); + + final Finder dropdownIcon = + find.descendant(of: find.byIcon(Icons.search).first, matching: find.byType(RichText)).last; + + await tester.tap(find.byType(DropdownMenu)); + await tester.pumpAndSettle(); + final Finder itemLeadingIcon = find.byKey(leadingIconKey(TestMenu.mainMenu0)).last; + + expect(tester.getRect(dropdownIcon).left, tester.getRect(itemLeadingIcon).left); + }); + + testWidgets('The icon in the menu button should be aligned with the icon of ' + 'the text field - RTL', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Directionality( + textDirection: TextDirection.rtl, + child: DropdownMenu( + leadingIcon: const Icon(Icons.search), + label: const Text('label'), + dropdownMenuEntries: menuChildrenWithIcons, + ), + ), + ), + ), + ); + + final Finder dropdownIcon = + find.descendant(of: find.byIcon(Icons.search).first, matching: find.byType(RichText)).last; + + await tester.tap(find.byType(DropdownMenu)); + await tester.pumpAndSettle(); + final Finder itemLeadingIcon = find.byKey(leadingIconKey(TestMenu.mainMenu0)).last; + + expect(tester.getRect(dropdownIcon).right, tester.getRect(itemLeadingIcon).right); + }); + testWidgets('DropdownMenu has default trailing icon button', (WidgetTester tester) async { final ThemeData themeData = ThemeData(); await tester.pumpWidget(buildTest(themeData, menuChildren));