buildTextSpan method

  1. @override
TextSpan buildTextSpan({
  1. required BuildContext context,
  2. TextStyle? style,
  3. required bool withComposing,
})
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,
  TextStyle? style,
  required bool withComposing,
}) {
  if (spans.iter.isEmpty) {
    return _textController.buildTextSpan(
      context: context,
      style: style,
      withComposing: withComposing,
    );
  }

  final Iterable<AttributeSegment> segments;

  if (!value.isComposingRangeValid ||
      !withComposing ||
      value.composing.isCollapsed) {
    segments = spans.getSegments(text.characters);
  } else {
    final composingRange = _convertRange(value.composing);
    segments = (spans.merge(
      AttributeSpan(
        compositionAttribute,
        composingRange.start,
        composingRange.end,
      ),
    )).getSegments(text.characters);
  }

  // We don't pass gesture recognizers here, because we don't
  // want gestures on spans to be handled while editing.
  return segments.buildTextSpan(
    style: style ?? const TextStyle(),
    context: context,
  );
}