diff --git a/packages/flutter/lib/src/cupertino/search_field.dart b/packages/flutter/lib/src/cupertino/search_field.dart index 39920234f9..b26963183b 100644 --- a/packages/flutter/lib/src/cupertino/search_field.dart +++ b/packages/flutter/lib/src/cupertino/search_field.dart @@ -108,6 +108,7 @@ class CupertinoSearchTextField extends StatefulWidget { this.decoration, this.backgroundColor, this.borderRadius, + this.keyboardType = TextInputType.text, this.padding = const EdgeInsetsDirectional.fromSTEB(3.8, 8, 5, 8), this.itemColor = CupertinoColors.secondaryLabel, this.itemSize = 20.0, @@ -195,6 +196,11 @@ class CupertinoSearchTextField extends StatefulWidget { // https://github.com/flutter/flutter/issues/13914. final BorderRadius? borderRadius; + /// The keyboard type for this search field. + /// + /// Defaults to TextInputType.text. + final TextInputType? keyboardType; + /// Sets the padding insets for the text and placeholder. /// /// Cannot be null. Defaults to padding that replicates the @@ -440,6 +446,7 @@ class _CupertinoSearchTextFieldState extends State style: widget.style, prefix: prefix, suffix: suffix, + keyboardType: widget.keyboardType, onTap: widget.onTap, enabled: widget.enabled, suffixMode: widget.suffixMode, diff --git a/packages/flutter/test/cupertino/search_field_test.dart b/packages/flutter/test/cupertino/search_field_test.dart index 34ccb9d350..c6d5daa596 100644 --- a/packages/flutter/test/cupertino/search_field_test.dart +++ b/packages/flutter/test/cupertino/search_field_test.dart @@ -112,6 +112,22 @@ void main() { }, ); + testWidgets('can change keyboard type', (WidgetTester tester) async { + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoSearchTextField( + keyboardType: TextInputType.number, + ), + ), + ), + ); + await tester.tap(find.byType(CupertinoSearchTextField)); + await tester.showKeyboard(find.byType(CupertinoSearchTextField)); + expect((tester.testTextInput.setClientArgs!['inputType'] as Map)['name'], equals('TextInputType.number')); + }, + ); + testWidgets( 'can control text content via controller', (WidgetTester tester) async {