
custom_message_widget.dart. The message content is stored as a String in customMessage.data, and it's recommended to use JSON format.fromJSON method to create an instance from a Map.class CustomMessage {String? link;String? text;String? businessID;CustomMessage.fromJSON(Map json) {link = json["link"];text = json["text"];businessID = json["businessID"];}}
_buildDefaultCustomMessage method, parse the custom message to create a CustomMessage object, then render the message using _buildTextLinkMessage.Widget _buildDefaultCustomMessage(BuildContext context,SemanticColorScheme colorsTheme,AtomicLocalizations atomicLocale,) {final customMessageData = message.messageBody?.customMessage;final customContent = ChatUtil.jsonData2Dictionary(customMessageData?.data);// Handle custom messages of type text_linkif (customContent != null) {final customMessage = CustomMessage.fromJSON(customContent);if (customMessage.businessID == 'text_link') {return _buildTextLinkMessage(context, colorsTheme, customMessage);}}}Widget _buildTextLinkMessage(BuildContext context,SemanticColorScheme colorsTheme,CustomMessage customMessage,) {final text = customMessage.text ?? '';final link = customMessage.link ?? '';return Container(constraints: BoxConstraints(maxWidth: maxWidth * 0.7,),padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),decoration: BoxDecoration(color: isSelf ? colorsTheme.buttonColorPrimaryDefault : colorsTheme.bgColorDefault,borderRadius: BorderRadius.circular(12),),child: Column(crossAxisAlignment: CrossAxisAlignment.start,mainAxisSize: MainAxisSize.min,children: [Text(text,style: TextStyle(color: isSelf ? colorsTheme.textColorAntiPrimary : colorsTheme.textColorPrimary,fontSize: 14,fontWeight: FontWeight.w500,),),const SizedBox(height: 8),GestureDetector(onTap: () => _launchUrl(link),child: Text('View Details',style: TextStyle(color: isSelf ? colorsTheme.textColorAntiPrimary : colorsTheme.buttonColorPrimaryDefault,fontSize: 14,fontWeight: FontWeight.w400,decoration: TextDecoration.underline,decorationColor: isSelf ? colorsTheme.textColorAntiPrimary : colorsTheme.buttonColorPrimaryDefault,),),),],),);}
getMessageAbstract method in message_utils.dart, parse the new custom message type to generate a summary for the conversation list.static String getMessageAbstract(MessageInfo? messageInfo,BuildContext context,{bool showMergedTitle = false}) {switch (messageInfo.messageType) {// Other message types omitted// Custom message text summarycase MessageType.custom:final customMessage = messageInfo.messageBody?.customMessage;if (customMessage == null) {return localizations.messageTypeCustom;}// Some code omittedfinal customInfo = ChatUtil.jsonData2Dictionary(customMessage.data);if (customInfo != null) {// Other custom message parsing omitted// Parse the added custom messageif (customInfo['businessID'] == 'text_link') {return customInfo['text']?.toString() ?? localizations.messageTypeCustom;}}return localizations.messageTypeCustom;default:return '';}}

data, then use the sendMessage method of MessageInputStore to send it.// Create a MessageInputStore objectMessageInputStore _messageInputStore = MessageInputStore.create(conversationID: widget.conversationID);// Construct a custom messagefinal messageInfo = MessageInfo();messageInfo.messageType = MessageType.custom;MessageBody messageBody = MessageBody();messageBody.customMessage = CustomMessageInfo(data: '{"businessID":"text_link","link":"https://www.tencentcloud.com/document/product/269/3794?from_cn_redirect=1","text":"Welcome to Tencent Cloud Chat!"}',);messageInfo.messageBody = messageBody;// Send the messageawait _messageInputStore.sendMessage(message: messageInfo);
フィードバック