buildMessageContent method

  1. @override
Widget buildMessageContent(
  1. BuildContext context,
  2. String? refName
)
override

Implementation

@override
Widget buildMessageContent(BuildContext context, String? refName) {
  final displayMessage =
      RCKMessageEditStatus.messageForDisplay(context, message);
  final String messageText = displayMessage is RCIMIWTextMessage
      ? displayMessage.text ?? ""
      : message.toJson().toString();

  // 使用配置的文本和链接样式
  final textStyleConfig = config?.textStyleConfig;
  final linkStyleConfig = config?.linkStyleConfig;

  final textStyle = (message.direction == RCIMIWMessageDirection.send)
      ? textStyleConfig?.senderTextStyle
      : textStyleConfig?.receiverTextStyle;

  final linkStyle = (message.direction == RCIMIWMessageDirection.send)
      ? linkStyleConfig?.senderTextStyle
      : linkStyleConfig?.receiverTextStyle;

  final effectiveTextStyle =
      textStyle ?? const TextStyle(color: Colors.black, fontSize: 16);
  final effectiveLinkStyle = linkStyle?.copyWith(
        decoration: linkStyleConfig?.showUnderline ?? false
            ? TextDecoration.underline
            : TextDecoration.none,
        decorationColor: linkStyle.color ?? Colors.blue,
      ) ??
      TextStyle(
        color: Colors.blue,
        fontSize: textStyle?.fontSize,
        decoration: TextDecoration.underline,
        decorationColor: linkStyle?.color ?? Colors.blue,
      );
  final editedSpan = RCKMessageEditStatus.buildEditedTextSpan(
    context,
    message,
    fallbackColor: RCKMessageEditStatus.bubbleEditedColor(message),
  );

  return Text.rich(
    TextSpan(
      children: [
        LinkifySpan(
          text: messageText,
          options: const LinkifyOptions(humanize: false),
          style: effectiveTextStyle,
          linkStyle: effectiveLinkStyle,
          onOpen: _onOpen,
          useMouseRegion: true,
        ),
        if (editedSpan != null) editedSpan,
      ],
    ),
    textAlign: TextAlign.start,
    strutStyle: textStyleConfig?.lineSpacing == null
        ? null
        : StrutStyle(
            height: textStyleConfig!.lineSpacing!,
            forceStrutHeight: true,
          ),
  );
}