diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index 7e634cd2aa..2e8b442dc2 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -159,6 +159,7 @@ class DropdownMenu 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 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 extends State> { focusNode: widget.focusNode, canRequestFocus: canRequestFocus(), enableInteractiveSelection: canRequestFocus(), + keyboardType: widget.keyboardType, textAlign: widget.textAlign, textAlignVertical: TextAlignVertical.center, style: effectiveTextStyle, diff --git a/packages/flutter/test/material/dropdown_menu_test.dart b/packages/flutter/test/material/dropdown_menu_test.dart index e9f84e1b0c..ea70dc859e 100644 --- a/packages/flutter/test/material/dropdown_menu_test.dart +++ b/packages/flutter/test/material/dropdown_menu_test.dart @@ -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( + 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( + dropdownMenuEntries: menuChildren, + ), + ), + ), + ), + ); + + final TextField textField = tester.widget(find.byType(TextField)); + expect(textField.keyboardType, TextInputType.text); + }); } enum TestMenu {