This PR exposes the `keyboardType` parameter in DropdownMenu, allowing the type of keyboard to be used for the text input to be changed. fixes #150894
This commit is contained in:
@@ -159,6 +159,7 @@ class DropdownMenu<T> extends StatefulWidget {
|
||||
this.selectedTrailingIcon,
|
||||
this.enableFilter = false,
|
||||
this.enableSearch = true,
|
||||
this.keyboardType,
|
||||
this.textStyle,
|
||||
this.textAlign = TextAlign.start,
|
||||
this.inputDecorationTheme,
|
||||
@@ -266,6 +267,11 @@ class DropdownMenu<T> extends StatefulWidget {
|
||||
/// Defaults to true as the search function could be commonly used.
|
||||
final bool enableSearch;
|
||||
|
||||
/// The type of keyboard to use for editing the text.
|
||||
///
|
||||
/// Defaults to [TextInputType.text].
|
||||
final TextInputType? keyboardType;
|
||||
|
||||
/// The text style for the [TextField] of the [DropdownMenu];
|
||||
///
|
||||
/// Defaults to the overall theme's [TextTheme.bodyLarge]
|
||||
@@ -804,6 +810,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
|
||||
focusNode: widget.focusNode,
|
||||
canRequestFocus: canRequestFocus(),
|
||||
enableInteractiveSelection: canRequestFocus(),
|
||||
keyboardType: widget.keyboardType,
|
||||
textAlign: widget.textAlign,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
style: effectiveTextStyle,
|
||||
|
||||
@@ -2397,6 +2397,41 @@ void main() {
|
||||
expect(fields[0].textAlign, TextAlign.start);
|
||||
expect(fields[1].textAlign, TextAlign.center);
|
||||
});
|
||||
|
||||
testWidgets('DropdownMenu correctly sets keyboardType on TextField', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SafeArea(
|
||||
child: DropdownMenu<TestMenu>(
|
||||
dropdownMenuEntries: menuChildren,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TextField textField = tester.widget(find.byType(TextField));
|
||||
expect(textField.keyboardType, TextInputType.number);
|
||||
});
|
||||
|
||||
testWidgets('DropdownMenu keyboardType defaults to TextInputType.text', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SafeArea(
|
||||
child: DropdownMenu<TestMenu>(
|
||||
dropdownMenuEntries: menuChildren,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TextField textField = tester.widget(find.byType(TextField));
|
||||
expect(textField.keyboardType, TextInputType.text);
|
||||
});
|
||||
}
|
||||
|
||||
enum TestMenu {
|
||||
|
||||
Reference in New Issue
Block a user