buildTextSpan method
TextSpan
buildTextSpan({
- required BuildContext context,
- TextStyle? style,
- 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,
}) {
int lastStartingRunStart = 0;
final List<InlineSpan> inlineSpans = <InlineSpan>[];
for (final _TextMention mention in _cachedMentions) {
final int indexToEndRegular = mention.start;
if (indexToEndRegular != lastStartingRunStart) {
inlineSpans.add(
_createSpanForNonMatchingRange(
style: style,
start: lastStartingRunStart,
end: indexToEndRegular,
),
);
}
inlineSpans.add(
TextSpan(
text: text.substring(mention.start, mention.end),
style: (style?.merge(mentionTextStyle) ?? mentionTextStyle)?.copyWith(
backgroundColor: mentionBgColor,
color: mentionTextColor,
),
),
);
lastStartingRunStart = mention.end;
}
if (lastStartingRunStart < text.length) {
inlineSpans.add(
_createSpanForNonMatchingRange(
style: style,
start: lastStartingRunStart,
end: text.length,
),
);
}
return TextSpan(children: inlineSpans);
}