buildTextSpan method

  1. @override
TextSpan buildTextSpan({
  1. required BuildContext context,
  2. TextStyle? style,
  3. 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, bool? withComposing}) {
  // Retrieve pattern regexp
  final patternList = <String>[];
  if (_webSpaceFix) {
    patternList.add("(" + _MIDDLE_DOT + ")");
    styleList.add(TextStyle(color: Colors.transparent));
  }
  if (stringMap != null) {
    patternList.addAll(stringMap!.keys.map((e) => r'(\b' + e + r'\b)'));
    styleList.addAll(stringMap!.values);
  }
  if (patternMap != null) {
    patternList.addAll(patternMap!.keys.map((e) => "(" + e + ")"));
    styleList.addAll(patternMap!.values);
  }
  styleRegExp = RegExp(patternList.join('|'), multiLine: true);

  // Return parsing
  if (language != null)
    return _processLanguage(text, style);
  else if (styleRegExp != null)
    return _processPatterns(text, style);
  else
    return TextSpan(text: text, style: style);
}