diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java index 2c3cf3307b863..641d3f37cc2a9 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java @@ -717,7 +717,8 @@ public enum TextInputType { EMAIL_ADDRESS("TextInputType.emailAddress"), URL("TextInputType.url"), VISIBLE_PASSWORD("TextInputType.visiblePassword"), - NONE("TextInputType.none"); + NONE("TextInputType.none"), + WEB_SEARCH("TextInputType.webSearch"); static TextInputType fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (TextInputType textInputType : TextInputType.values()) { diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 41cd19ed32fc4..4f3adcec4d8a4 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -252,7 +252,8 @@ private static int inputTypeFromTextInputType( textType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE; } else if (type.type == TextInputChannel.TextInputType.EMAIL_ADDRESS) { textType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; - } else if (type.type == TextInputChannel.TextInputType.URL) { + } else if (type.type == TextInputChannel.TextInputType.URL + || type.type == TextInputChannel.TextInputType.WEB_SEARCH) { textType |= InputType.TYPE_TEXT_VARIATION_URI; } else if (type.type == TextInputChannel.TextInputType.VISIBLE_PASSWORD) { textType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 77f71f0aaf923..d10df7bf1aee2 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1356,6 +1356,40 @@ public void showTextInput_textInputTypeNone() { assertEquals(testImm.isSoftInputVisible(), false); } + @Test + public void showTextInput_textInputTypeWebSearch() { + TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); + View testView = new View(ctx); + DartExecutor dartExecutor = mock(DartExecutor.class); + TextInputChannel textInputChannel = new TextInputChannel(dartExecutor); + ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); + TextInputPlugin textInputPlugin = + new TextInputPlugin( + testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + textInputPlugin.setTextInputClient( + 0, + new TextInputChannel.Configuration( + false, + false, + true, + true, + false, + TextInputChannel.TextCapitalization.NONE, + new TextInputChannel.InputType(TextInputChannel.TextInputType.WEB_SEARCH, false, false), + null, + null, + null, + null, + null)); + + EditorInfo editorInfo = new EditorInfo(); + InputConnection connection = + textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), editorInfo); + + assertEquals( + editorInfo.inputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); + } + @Test public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() { // Regression test for https://github.com/flutter/flutter/issues/71679. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 61419ed9cd307..b8a3f64de07a0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -140,6 +140,9 @@ static UIKeyboardType ToUIKeyboardType(NSDictionary* type) { if ([inputType isEqualToString:@"TextInputType.visiblePassword"]) { return UIKeyboardTypeASCIICapable; } + if ([inputType isEqualToString:@"TextInputType.webSearch"]) { + return UIKeyboardTypeWebSearch; + } return UIKeyboardTypeDefault; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index d8c16103b4c77..ec39029c67c8c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -307,6 +307,20 @@ - (void)testKeyboardType { XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeURL); } +- (void)testKeyboardTypeWebSearch { + NSDictionary* config = self.mutableTemplateCopy; + [config setValue:@{@"name" : @"TextInputType.webSearch"} forKey:@"inputType"]; + [self setClientId:123 configuration:config]; + + // Find all the FlutterTextInputViews we created. + NSArray* inputFields = self.installedInputViews; + + FlutterTextInputView* inputView = inputFields[0]; + + // Verify keyboardType is set to the value specified in config. + XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeWebSearch); +} + - (void)testVisiblePasswordUseAlphanumeric { NSDictionary* config = self.mutableTemplateCopy; [config setValue:@{@"name" : @"TextInputType.visiblePassword"} forKey:@"inputType"];