buildTextSpan method

  1. @override
TextSpan buildTextSpan({
  1. required BuildContext context,
  2. required bool withComposing,
  3. TextStyle? style,
})
override

Builds TextSpan from current editing value.

By default makes text in composing range appear as underlined. Descendants can override this method to customize appearance of text.

Implementation

@override
TextSpan buildTextSpan({required BuildContext context, required bool withComposing, TextStyle? style}) {
  assert(!value.composing.isValid || !withComposing || value.isComposingRangeValid);
  // If the composing range is out of range for the current text, ignore it to preserve the tree integrity, otherwise
  // in release mode a RangeError will be thrown and this EditableText will be built with a broken subtree.
  final bool composingRegionOutOfRange = !value.isComposingRangeValid || !withComposing;
  final (textStyle, composingStyle, completionStyle) = _textStyles(context);

  return TextSpan(
    children: [
      if (composingRegionOutOfRange)
        TextSpan(text: text, style: style)
      else ...[
        TextSpan(text: value.composing.textBefore(value.text), style: style),
        TextSpan(text: value.composing.textInside(value.text), style: composingStyle),
        TextSpan(text: value.composing.textAfter(value.text), style: style),
      ],
      if (current case (:final completion, replacement: final _)) TextSpan(text: completion, style: completionStyle),
    ],
  );
}