allow changing textAlign of TextField in DropdownMenu (#148074)
PR for #147991
This commit is contained in:
committed by
GitHub
parent
02739d737b
commit
11cbe41555
@@ -154,6 +154,7 @@ class DropdownMenu<T> extends StatefulWidget {
|
||||
this.enableFilter = false,
|
||||
this.enableSearch = true,
|
||||
this.textStyle,
|
||||
this.textAlign = TextAlign.start,
|
||||
this.inputDecorationTheme,
|
||||
this.menuStyle,
|
||||
this.controller,
|
||||
@@ -264,6 +265,11 @@ class DropdownMenu<T> extends StatefulWidget {
|
||||
/// if the dropdown menu theme's value is null.
|
||||
final TextStyle? textStyle;
|
||||
|
||||
/// The text align for the [TextField] of the [DropdownMenu].
|
||||
///
|
||||
/// Defaults to [TextAlign.start].
|
||||
final TextAlign textAlign;
|
||||
|
||||
/// Defines the default appearance of [InputDecoration] to show around the text field.
|
||||
///
|
||||
/// By default, shows a outlined text field.
|
||||
@@ -754,6 +760,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
focusNode: widget.focusNode,
|
||||
canRequestFocus: canRequestFocus(),
|
||||
enableInteractiveSelection: canRequestFocus(),
|
||||
textAlign: widget.textAlign,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
style: effectiveTextStyle,
|
||||
controller: _localTextEditingController,
|
||||
|
||||
@@ -2293,6 +2293,29 @@ void main() {
|
||||
// One is layout for the _DropdownMenuBody, the other one is the real button item in the menu.
|
||||
expect(find.widgetWithText(MenuItemButton, labelText), findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('DropdownMenu allows customizing text field text align', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: <DropdownMenu<int>>[
|
||||
DropdownMenu<int>(
|
||||
dropdownMenuEntries: <DropdownMenuEntry<int>>[],
|
||||
),
|
||||
DropdownMenu<int>(
|
||||
textAlign: TextAlign.center,
|
||||
dropdownMenuEntries: <DropdownMenuEntry<int>>[],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final List<TextField> fields = tester.widgetList<TextField>(find.byType(TextField)).toList();
|
||||
|
||||
expect(fields[0].textAlign, TextAlign.start);
|
||||
expect(fields[1].textAlign, TextAlign.center);
|
||||
});
|
||||
}
|
||||
|
||||
enum TestMenu {
|
||||
|
||||
Reference in New Issue
Block a user