Fix DropdownButtonFormField padding when ButtonTheme.alignedDropdown is true (#162810)
## Description This PR fixes `DropdownButtonFormField` content padding when `ButtonTheme.alignedDropdown` is true. ### Before: An extra padding is added before the content when `alignedDropdown` is true:  ### After: The content has the same position whether `alignedDropdown` is true or false:  ## Related Issue Fixes https://github.com/flutter/flutter/issues/123783 ## Tests Adds 1 test.
This commit is contained in:
parent
055f6c1a49
commit
7e9ba43698
@ -1526,7 +1526,9 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
|||||||
}
|
}
|
||||||
|
|
||||||
final EdgeInsetsGeometry padding =
|
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
|
// If value is null (then _selectedIndex is null) then we
|
||||||
// display the hint or nothing at all.
|
// display the hint or nothing at all.
|
||||||
|
@ -1253,4 +1253,45 @@ void main() {
|
|||||||
|
|
||||||
expect(find.text('**Required**'), findsOneWidget);
|
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<String>(
|
||||||
|
value: menuItems.first,
|
||||||
|
items:
|
||||||
|
menuItems.map((String value) {
|
||||||
|
return DropdownMenuItem<String>(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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user