From 1511370a92ea81a2e47ea27470d3748df75ac324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Stein?= Date: Fri, 8 Nov 2024 15:26:05 -0300 Subject: [PATCH] [TextInput] Add TextInputType.webSearch (#15762) (#158323) This PR adds `TextInputType.webSearch` that allows to show a keyboard with ready access to a "." key on iOS. On Android this is re-mapped to `url` which shows the same behaviour as `webSearch` on iOS. This fixes issue #157562. There also is a [corresponding *engine* PR](https://github.com/flutter/engine/pull/56428). Screenshot from iOS demo app: ![image](https://github.com/user-attachments/assets/94d48752-4cfe-4113-acf9-b3a981952dc7) --- packages/flutter/lib/src/services/text_input.dart | 14 ++++++++++++-- .../flutter/test/services/text_input_test.dart | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index eb8d91a542..890b4933f4 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -194,14 +194,24 @@ class TextInputType { /// Prevent the OS from showing the on-screen virtual keyboard. static const TextInputType none = TextInputType._(10); + /// Optimized for web searches. + /// + /// Requests a keyboard that includes keys useful for web searches as well as URLs. + /// + /// On iOS, requests a default keyboard with ready access to the "." key. In contrast to + /// [url], a space bar is available. + /// + /// On Android this is remapped to the [url] keyboard type as it always shows a space bar. + static const TextInputType webSearch = TextInputType._(11); + /// All possible enum values. static const List values = [ - text, multiline, number, phone, datetime, emailAddress, url, visiblePassword, name, streetAddress, none, + text, multiline, number, phone, datetime, emailAddress, url, visiblePassword, name, streetAddress, none, webSearch, ]; // Corresponding string name for each of the [values]. static const List _names = [ - 'text', 'multiline', 'number', 'phone', 'datetime', 'emailAddress', 'url', 'visiblePassword', 'name', 'address', 'none', + 'text', 'multiline', 'number', 'phone', 'datetime', 'emailAddress', 'url', 'visiblePassword', 'name', 'address', 'none', 'webSearch', ]; // Enum value name, this is what enum.toString() would normally return. diff --git a/packages/flutter/test/services/text_input_test.dart b/packages/flutter/test/services/text_input_test.dart index 215e9dc0c1..f369272d56 100644 --- a/packages/flutter/test/services/text_input_test.dart +++ b/packages/flutter/test/services/text_input_test.dart @@ -348,6 +348,7 @@ void main() { expect(TextInputType.name.toString(), 'TextInputType(name: TextInputType.name, signed: null, decimal: null)'); expect(TextInputType.streetAddress.toString(), 'TextInputType(name: TextInputType.address, signed: null, decimal: null)'); expect(TextInputType.none.toString(), 'TextInputType(name: TextInputType.none, signed: null, decimal: null)'); + expect(TextInputType.webSearch.toString(), 'TextInputType(name: TextInputType.webSearch, signed: null, decimal: null)'); expect(text == number, false); expect(number == number2, true); @@ -376,6 +377,7 @@ void main() { expect(TextInputType.name.index, 8); expect(TextInputType.streetAddress.index, 9); expect(TextInputType.none.index, 10); + expect(TextInputType.webSearch.index, 11); expect(TextEditingValue.empty.toString(), 'TextEditingValue(text: \u2524\u251C, selection: ${const TextSelection.collapsed(offset: -1)}, composing: ${TextRange.empty})');