buildTextSpanWithSpellCheckSuggestions function Null safety

TextSpan buildTextSpanWithSpellCheckSuggestions(
  1. TextEditingValue value,
  2. bool composingWithinCurrentTextRange,
  3. TextStyle? style,
  4. TextStyle misspelledTextStyle,
  5. SpellCheckResults spellCheckResults
)

Builds the TextSpan tree given the current state of the text input and spell check results.

The value is the current TextEditingValue requested to be rendered by a text input widget. The composingWithinCurrentTextRange value represents whether or not there is a valid composing region in the value. The style is the TextStyle to render the value's text with, and the misspelledTextStyle is the TextStyle to render misspelled words within the value's text with. The spellCheckResults are the results of spell checking the value's text.

Implementation

TextSpan buildTextSpanWithSpellCheckSuggestions(
    TextEditingValue value,
    bool composingWithinCurrentTextRange,
    TextStyle? style,
    TextStyle misspelledTextStyle,
    SpellCheckResults spellCheckResults) {
  List<SuggestionSpan> spellCheckResultsSpans =
      spellCheckResults.suggestionSpans;
  final String spellCheckResultsText = spellCheckResults.spellCheckedText;

  if (spellCheckResultsText != value.text) {
    spellCheckResultsSpans = _correctSpellCheckResults(
        value.text, spellCheckResultsText, spellCheckResultsSpans);
  }

  return TextSpan(
      style: style,
      children: _buildSubtreesWithMisspelledWordsIndicated(
          spellCheckResultsSpans,
          value,
          style,
          misspelledTextStyle,
          composingWithinCurrentTextRange
      )
    );
}