buildSpanForLinkText method

InlineSpan buildSpanForLinkText(
  1. BuildContext context,
  2. bool tappedGetter(),
  3. dynamic tappedSetter(
    1. bool
    )
)

Builds InlineSpan, or said TextSpan or WidgetSpan, for LinkTextItem.

Implementation

InlineSpan buildSpanForLinkText(BuildContext context, bool Function() tappedGetter, Function(bool) tappedSetter) {
  TextStyle? textStyle;
  if (normalStyle != null || pressedStyle != null) {
    textStyle = !tappedGetter() ? normalStyle : pressedStyle;
  } else {
    var textColor = !tappedGetter() ? normalColor : pressedColor;
    textStyle = basicStyle ?? const TextStyle();
    textStyle = !(showUnderline ?? true)
        ? textStyle.copyWith(
            color: textColor,
            decoration: TextDecoration.none,
          )
        : textStyle.copyWith(
            color: Colors.transparent,
            decoration: TextDecoration.underline,
            decorationColor: textColor ?? Colors.black, // colorized underline
            shadows: [
              Shadow(
                offset: const Offset(0, -1), // text offset
                color: textColor ?? Colors.black,
              ),
            ],
          );
  }
  var recognizer = TapGestureRecognizer()
    ..onTap = onTap
    ..onTapDown = ((_) => tappedSetter(true))
    ..onTapUp = ((_) => tappedSetter(false))
    ..onTapCancel = (() => tappedSetter(false));

  if (wrapperBuilder == null) {
    return TextSpan(
      text: text,
      style: textStyle,
      recognizer: recognizer,
    );
  }
  return wrapperBuilder!(
    context,
    GestureDetector(
      child: Text(text, style: textStyle),
      onTap: recognizer.onTap,
      onTapDown: recognizer.onTapDown,
      onTapUp: recognizer.onTapUp,
      onTapCancel: recognizer.onTapCancel,
    ),
    tappedGetter(),
  );
}