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,
}) {
final children = <TextSpan>[];
text.splitMapJoin(
RegExp(_listPatternStyle.map((it) => it.regExp.pattern).join('|')),
onMatch: (match) {
final text = match[0]!;
final style = _listPatternStyle
.firstWhere((element) => element.regExp.hasMatch(text))
.textStyle;
final span = TextSpan(text: match.group(0), style: style);
children.add(span);
return span.toPlainText();
},
onNonMatch: (text) {
final span = TextSpan(text: text, style: style);
children.add(span);
return span.toPlainText();
},
);
return TextSpan(style: style, children: children);
}