diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index e9b32eb037..975b7e7876 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1526,7 +1526,9 @@ class _DropdownButtonState extends State> with WidgetsBindi } final EdgeInsetsGeometry padding = - ButtonTheme.of(context).alignedDropdown ? _kAlignedButtonPadding : _kUnalignedButtonPadding; + ButtonTheme.of(context).alignedDropdown && widget._inputDecoration == null + ? _kAlignedButtonPadding + : _kUnalignedButtonPadding; // If value is null (then _selectedIndex is null) then we // display the hint or nothing at all. diff --git a/packages/flutter/test/material/dropdown_form_field_test.dart b/packages/flutter/test/material/dropdown_form_field_test.dart index 554e4f43ac..4282aaf747 100644 --- a/packages/flutter/test/material/dropdown_form_field_test.dart +++ b/packages/flutter/test/material/dropdown_form_field_test.dart @@ -1253,4 +1253,45 @@ void main() { expect(find.text('**Required**'), findsOneWidget); }); + + testWidgets('ButtonTheme.alignedDropdown does not affect the field content position', ( + WidgetTester tester, + ) async { + Widget buildFrame({required bool alignedDropdown, required TextDirection textDirection}) { + return MaterialApp( + home: Directionality( + textDirection: textDirection, + child: ButtonTheme( + alignedDropdown: alignedDropdown, + child: Material( + child: DropdownButtonFormField( + value: menuItems.first, + items: + menuItems.map((String value) { + return DropdownMenuItem(value: value, child: Text(value)); + }).toList(), + onChanged: onChanged, + ), + ), + ), + ), + ); + } + + final Finder findSelectedValue = find.text(menuItems.first).first; + + await tester.pumpWidget(buildFrame(alignedDropdown: false, textDirection: TextDirection.ltr)); + Rect contentRectForUnalignedDropdown = tester.getRect(findSelectedValue); + + // When alignedDropdown is true, the content should be at the same position. + await tester.pumpWidget(buildFrame(alignedDropdown: true, textDirection: TextDirection.ltr)); + expect(tester.getRect(findSelectedValue), contentRectForUnalignedDropdown); + + await tester.pumpWidget(buildFrame(alignedDropdown: false, textDirection: TextDirection.rtl)); + contentRectForUnalignedDropdown = tester.getRect(findSelectedValue); + + // When alignedDropdown is true, the content should be at the same position. + await tester.pumpWidget(buildFrame(alignedDropdown: true, textDirection: TextDirection.rtl)); + expect(tester.getRect(findSelectedValue), contentRectForUnalignedDropdown); + }); }