build method

  1. @override
TextSpan build(
  1. String data, {
  2. TextStyle? textStyle,
  3. SpecialTextGestureTapCallback? onTap,
})

Implementation

@override
TextSpan build(String data, {TextStyle? textStyle, SpecialTextGestureTapCallback? onTap}) {
  List<InlineSpan> inlineList = [];
  //tag
  var startSpecialText = findStartSpecialText(onTap);
  var finishText = startSpecialText?.finishText();
  if (finishText != null) {
    inlineList.add(finishText);
  }
  //text @ emoji link
  if (data.isEmptyString) {
    inlineList.add(TextSpan(text: data, style: textStyle));
    return TextSpan(children: inlineList, style: textStyle);
  }
  var copy = data.replaceAll("&quot;", "");
  var regExp = RegExp(r"(?<=>)[^<>]+(?=<)");
  if (regExp.hasMatch(copy)) {
    var matches = regExp.allMatches(copy);
    var count = 0;
    for (var element in matches) {
      count++;
      var contentBuffer = StringBuffer();
      if (element.start > 0) {
        var startContent = element.input.substring(0, element.start);
        if (count == 1 && !startContent.startsWith("<")) {
          contentBuffer.write(startContent);
        }
      }
      var groupCount = element.groupCount;
      for (var i = 0; i <= groupCount; i++) {
        try {
          contentBuffer.write(element.group(i) ?? "");
        } catch (e) {
          Logger.instance.error(e);
        }
      }
      if (count == matches.length && element.end < element.input.length) {
        var endContent = element.input.substring(element.end);
        contentBuffer.write(endContent);
      }
      getChildTextSpan(inlineList, contentBuffer.toString(), textStyle, onTap, matches.length);
    }
  } else {
    getChildTextSpan(inlineList, copy, textStyle, onTap, 0);
  }
  return TextSpan(children: inlineList, style: textStyle);
}