createSpan method

TextSpan createSpan({
  1. bool useChild = true,
})

Implementation

TextSpan createSpan({bool useChild = true}) {
  var curFontSize = _fontSize;

  var shadowList = <Shadow>[];
  if (_textShadowOffsetDx != 0 || _textShadowOffsetDy != 0) {
    shadowList.add(
      Shadow(
        blurRadius: _textShadowRadius,
        color: Color(_textShadowColor),
        offset: Offset(_textShadowOffsetDx, _textShadowOffsetDy),
      ),
    );
  }

  var childrenSpan = <InlineSpan>[];
  if (useChild) {
    _placeholderDimensions = [];
    for (var i = 0; i < childCount; i++) {
      var node = getChildAt(i);
      if (node != null) {
        if (node is TextVirtualNode) {
          var styleNode = node;
          childrenSpan.add(styleNode.createSpan(useChild: useChild));
        } else if (node is ImageVirtualNode) {
          _placeholderDimensions.add(
            PlaceholderDimensions(
              size: Size(node.mWidth, node.mHeight),
              alignment: node.verticalAlignment,
            ),
          );
          childrenSpan.add(node.createSpan());
        } else {
          // throw StateError("${node.name} is not support in Text");
        }
      }
    }
  }

  var textDecoration = TextDecoration.none;
  if (_isUnderlineTextDecorationSet) {
    textDecoration = TextDecoration.underline;
  }
  if (_isLineThroughTextDecorationSet) {
    if (textDecoration != TextDecoration.none) {
      textDecoration = TextDecoration.combine(
        [
          TextDecoration.underline,
          TextDecoration.lineThrough,
        ],
      );
    } else {
      textDecoration = TextDecoration.lineThrough;
    }
  }

  if (!isEmpty(_text) || childrenSpan.isNotEmpty) {
    return TextSpan(
      text: _text,
      style: TextStyle(
        leadingDistribution: TextLeadingDistribution.even,
        color: Color(_color),
        letterSpacing: _letterSpacing,
        fontSize: curFontSize,
        fontStyle: _fontStyle,
        fontWeight: _fontWeight,
        fontFamily: _fontFamily,
        shadows: shadowList,
        height: _lineHeightFactor(),
        decoration: textDecoration,
        decorationStyle: _textDecorationStyle,
        decorationColor: Color(_textDecorationColor),
      ),
      children: childrenSpan,
      recognizer: nativeGestureDispatcher.needListener() ? _tapGestureRecognizer : null,
    );
  }
  return const TextSpan(text: "");
}