Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 247931d

Browse files
blerouxharryterkelsen
authored andcommitted
[Android] Fix enableSuggestions set to false not honored (#46037)
## Description This PR fixes an issue where setting `TextField.enableSuggestions` to false was not honored on Android. Several Android devices (Samsung) and/or IMEs (including GBoard) does not disabled suggestions when `InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS `flag is set. The common solution is to rely on the following flag: ~~`InputType.TYPE_TEXT_VARIATION_PASSWORD`~~ `InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD`. Reference: - https://issuetracker.google.com/issues/36934423#comment4 - https://stackoverflow.com/questions/33148168/inputtype-type-text-flag-no-suggestions-in-samsung/33227237#33227237 - Existing comment on the codebase: https://github.com/flutter/engine/blob/53430c7c96a3ef1fc78d63ea6b0c35e5ff46c45e/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java#L270 ## Related Issue Fixes flutter/flutter#71679. ## Tests Adds 1 test.
1 parent f7a8076 commit 247931d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ private static int inputTypeFromTextInputType(
272272
textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
273273
} else {
274274
if (autocorrect) textType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
275-
if (!enableSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
275+
if (!enableSuggestions) {
276+
// Note: both required. Some devices ignore TYPE_TEXT_FLAG_NO_SUGGESTIONS.
277+
textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
278+
textType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
279+
}
276280
}
277281

278282
if (textCapitalization == TextInputChannel.TextCapitalization.CHARACTERS) {

shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,42 @@ public void showTextInput_textInputTypeNone() {
13061306
assertEquals(testImm.isSoftInputVisible(), false);
13071307
}
13081308

1309+
@Test
1310+
public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() {
1311+
// Regression test for https://github.com/flutter/flutter/issues/71679.
1312+
View testView = new View(ctx);
1313+
DartExecutor dartExecutor = mock(DartExecutor.class);
1314+
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
1315+
TextInputPlugin textInputPlugin =
1316+
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
1317+
textInputPlugin.setTextInputClient(
1318+
0,
1319+
new TextInputChannel.Configuration(
1320+
false,
1321+
false,
1322+
false, // Disable suggestions.
1323+
true,
1324+
false,
1325+
TextInputChannel.TextCapitalization.NONE,
1326+
new TextInputChannel.InputType(TextInputChannel.TextInputType.MULTILINE, false, false),
1327+
null,
1328+
null,
1329+
null,
1330+
null,
1331+
null));
1332+
1333+
EditorInfo editorInfo = new EditorInfo();
1334+
InputConnection connection =
1335+
textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), editorInfo);
1336+
1337+
assertEquals(
1338+
editorInfo.inputType,
1339+
InputType.TYPE_CLASS_TEXT
1340+
| InputType.TYPE_TEXT_FLAG_MULTI_LINE
1341+
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
1342+
| InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
1343+
}
1344+
13091345
// -------- Start: Autofill Tests -------
13101346
@Test
13111347
public void autofill_enabledByDefault() {

0 commit comments

Comments
 (0)