build method

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

Implementation

TextSpan build(String data,
    {TextStyle? textStyle, SpecialTextGestureTapCallback? onTap}) {
  if (data == '') {
    return TextSpan(text: '', style: textStyle);
  }
  final List<InlineSpan> inlineList = <InlineSpan>[];
  if (data.isNotEmpty) {
    SpecialText? specialText;
    String textStack = '';
    //String text
    for (int i = 0; i < data.length; i++) {
      final String char = data[i];
      textStack += char;
      if (specialText != null) {
        // always append
        // and remove endflag in getContent method
        specialText.appendContent(char);
        if (specialText.isEnd(textStack)) {
          inlineList.add(specialText.finishText());
          specialText = null;
          textStack = '';
        }
      } else {
        specialText = createSpecialText(textStack,
            textStyle: textStyle, onTap: onTap, index: i);
        if (specialText != null) {
          if (textStack.length - specialText.startFlag.length >= 0) {
            textStack = textStack.substring(
                0, textStack.length - specialText.startFlag.length);
            if (textStack.isNotEmpty) {
              inlineList.add(TextSpan(text: textStack, style: textStyle));
            }
          }
          textStack = '';
        }
      }
    }

    if (specialText != null) {
      inlineList.add(TextSpan(
          text: specialText.startFlag + specialText.getContent(),
          style: textStyle));
    } else if (textStack.isNotEmpty) {
      inlineList.add(TextSpan(text: textStack, style: textStyle));
    }
  } else {
    inlineList.add(TextSpan(text: data, style: textStyle));
  }

  return TextSpan(children: inlineList, style: textStyle);
}