buildMessageContent method
Implementation
@override
Widget buildMessageContent(BuildContext context, String? refName) {
final editScope = RCKMessageEditScope.maybeOf(context);
final displayMessage =
RCKMessageEditStatus.messageForDisplay(context, message)
as RCIMIWReferenceMessage;
final refMsg = displayMessage.referenceMessage;
// 使用工具函数获取引用消息内容
String referenceContent = getReferenceMessageContent(
refMsg,
useModifiedContent: editScope?.enabled == true,
);
var referenceState = displayMessage.referMsgStatus ??
RCIMIWReferenceMessageStatus.defaultValue;
final baseState = (message as RCIMIWReferenceMessage).referMsgStatus ??
RCIMIWReferenceMessageStatus.defaultValue;
if (baseState.index > referenceState.index) {
referenceState = baseState;
}
if (editScope?.enabled == true) {
final cachedState = context
.read<RCKChatProvider?>()
?.referenceMessageState(refMsg?.messageUId) ??
RCIMIWReferenceMessageStatus.defaultValue;
if (cachedState.index > referenceState.index) {
referenceState = cachedState;
}
if (referenceState == RCIMIWReferenceMessageStatus.deleted) {
referenceContent = editScope!.config.strings.referenceDeleted;
} else if (referenceState == RCIMIWReferenceMessageStatus.recalled) {
referenceContent = editScope!.config.strings.referenceRecalled;
}
}
final String messageText = displayMessage.text ?? "";
if (refName == null || refName.isEmpty) {
refName = refMsg?.senderUserId;
}
final isMe = message.direction == RCIMIWMessageDirection.send;
// 使用配置的引用和文本样式
final refConfig = config?.referenceStyleConfig;
final textConfig = config?.textStyleConfig;
final linkConfig = config?.linkStyleConfig;
final backgroundColor = refConfig?.backgroundColor;
final refTextStyle = refConfig?.textStyle ??
TextStyle(
color: isMe
? RCKThemeProvider().themeColor.textInverse
: RCKThemeProvider().themeColor.textSecondary,
fontSize: kBubbleRefTextFontSize);
final padding = refConfig?.padding ?? const EdgeInsets.all(8.0);
final spacingToContent =
refConfig?.spacingToContent ?? kBubbleRefTextPadding;
final textStyle =
isMe ? textConfig?.senderTextStyle : textConfig?.receiverTextStyle;
final linkStyle =
isMe ? linkConfig?.senderTextStyle : linkConfig?.receiverTextStyle;
final effectiveTextStyle =
textStyle ?? const TextStyle(color: Colors.black, fontSize: 16);
final effectiveLinkStyle = linkStyle?.copyWith(
decoration: linkConfig?.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),
);
final messageContent = Text.rich(
TextSpan(
children: [
LinkifySpan(
text: messageText,
options: const LinkifyOptions(humanize: false),
style: effectiveTextStyle,
linkStyle: effectiveLinkStyle,
onOpen: _onOpen,
useMouseRegion: true,
),
if (editedSpan != null) editedSpan,
],
),
);
final referenceEditedSpan = refMsg != null &&
referenceState == RCIMIWReferenceMessageStatus.modified
? RCKMessageEditStatus.buildEditedTextSpan(
context,
refMsg,
forceEdited: true,
fallbackColor: RCKMessageEditStatus.bubbleEditedColor(message),
)
: null;
final referenceContentWidget = Text.rich(
TextSpan(
style: refTextStyle,
children: [
TextSpan(text: '| 回复 $refName:$referenceContent'),
if (referenceEditedSpan != null) referenceEditedSpan,
],
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: padding,
margin: EdgeInsets.only(
bottom: spacingToContent, right: spacingToContent),
color: backgroundColor,
child: referenceContentWidget,
),
messageContent,
],
);
}