diff --git a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java index f74076c7af45b..5688e4fd597ae 100644 --- a/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java @@ -149,10 +149,20 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { spellCheckerSuggestionSpan.put(END_INDEX_KEY, end); ArrayList suggestions = new ArrayList(); + boolean validSuggestionsFound = false; for (int j = 0; j < suggestionsCount; j++) { - suggestions.add(suggestionsInfo.getSuggestionAt(j)); + String suggestion = suggestionsInfo.getSuggestionAt(j); + // TODO(camsim99): Support spell check on Samsung by retrieving accurate spell check + // results, then remove this check: https://github.com/flutter/flutter/issues/120608. + if (!suggestion.equals("")) { + validSuggestionsFound = true; + suggestions.add(suggestion); + } } + if (!validSuggestionsFound) { + continue; + } spellCheckerSuggestionSpan.put(SUGGESTIONS_KEY, suggestions); spellCheckerSuggestionSpans.add(spellCheckerSuggestionSpan); } diff --git a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index 559ebcbae2a7a..97a28a0ca22d7 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -222,4 +222,29 @@ public void onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly() { verify(mockResult).success(expectedResults); } + + @Test + public void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid() { + TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class); + SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class); + SpellCheckPlugin spellCheckPlugin = + spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel)); + MethodChannel.Result mockResult = mock(MethodChannel.Result.class); + spellCheckPlugin.pendingResult = mockResult; + + spellCheckPlugin.onGetSentenceSuggestions( + new SentenceSuggestionsInfo[] { + new SentenceSuggestionsInfo( + (new SuggestionsInfo[] { + new SuggestionsInfo( + SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO, + // This is the suggestion that may be provided by the Samsung spell checker: + new String[] {""}) + }), + new int[] {7}, + new int[] {5}) + }); + + verify(mockResult).success(new ArrayList>()); + } }