getChildTextSpan method

void getChildTextSpan(
  1. List<InlineSpan> inlineList,
  2. String elementText,
  3. TextStyle? textStyle,
  4. SpecialTextGestureTapCallback? onTap,
  5. int count,
)

Implementation

void getChildTextSpan(List<InlineSpan> inlineList, String elementText, TextStyle? textStyle,
    SpecialTextGestureTapCallback? onTap, int count) {
  var textStack = "";
  var content = "$elementText${count > 1 ? "\n        " : ""}"
      .replaceAll("</p>", "\n        ")
      .replaceAll("<br>", "\n")
      .replaceAll("<p>", "");
  for (int i = 0; i < content.length; i++) {
    var styleMap = spanStyleMap[i];
    String char = content[i];
    if ((char.isChineseCharacter &&
            customIndexList.isNotEmptyList &&
            customCall != null &&
            (customIndexList?.contains(i) ?? false)) ||
        (char.isChineseCharacter)) {
      textStack += char;
      EySpecialText? specialText =
          findSpecialText(data: content, textStack: textStack, index: i, textStyle: textStyle, tapCallback: onTap);
      if (specialText?.isMarkPinyin ?? false) {
        var sText = specialText!.finishText();
        inlineList.add(sText);
        specialText = null;
        textStack = "";
      } else {
        int startLen = specialText?.startFlag?.length ?? 0;
        if (startLen > 0 && (textStack.length - startLen >= 0)) {
          i = i - startLen;
          textStack = textStack.substring(0, textStack.length - startLen);
          if (textStack.isNotEmptyString) {
            inlineList.add(TextSpan(
              text: textStack,
              style: styleMap == null
                  ? textStyle
                  : TextStyle(color: styleMap.color, fontSize: styleMap.fontSize, fontWeight: styleMap.fontWeight),
            ));
            textStack = "";
          }
        } else {
          var content = specialText?.getContent() ?? "";
          if (content == textStack) {
            inlineList.add(TextSpan(
              text: textStack,
              style: styleMap == null
                  ? textStyle
                  : TextStyle(color: styleMap.color, fontSize: styleMap.fontSize, fontWeight: styleMap.fontWeight),
            ));
          } else {
            i = i + content.length;
            var len = specialText?.offset ?? 0;
            if (len > 0) {
              content = content.replaceRange(i, i + len, "");
              i = i + len;
            }
            var fText = specialText?.finishText();
            if (fText != null) {
              inlineList.add(fText);
              textStack = "";
            }
            specialText?.setOffset(0);
            specialText = null;
          }
        }
      }
    } else {
      textStack = char;
    }
    if (textStack == " ") {
      inlineList.add(TextSpan(text: textStack));
      textStack = "";
    } else {
      if (textStack == "\n" || textStack.isNotEmptyString) {
        if (textStack == "\n") {
          inlineList.add(TextSpan(
            text: textStack,
            style: styleMap == null
                ? textStyle
                : TextStyle(color: styleMap.color, fontSize: styleMap.fontSize, fontWeight: styleMap.fontWeight),
          ));
        } else {
          inlineList.add(WidgetSpan(
            child: Padding(
              padding: EdgeInsets.only(bottom: lineSpacingSize),
              child: Text(textStack,
                  style: styleMap == null
                      ? textStyle
                      : TextStyle(
                          color: styleMap.color, fontSize: styleMap.fontSize, fontWeight: styleMap.fontWeight)),
            ),
          ));
        }
        textStack = "";
      }
    }
  }
}