From 1e0f259d7ac0ebca364684f7c7739e8cb11d2be6 Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Tue, 11 Nov 2025 14:10:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(message):=20=E6=B7=BB=E5=8A=A0=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=BC=9A=E8=AF=9D=E5=8F=91=E9=80=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 导入 IM 管理器和扩展组件- 在会话列表项上添加点击手势识别器 - 点击时调用 IM 管理器发送文本消息方法 - 发送固定内容“来了”作为测试消息- 保留原有未读计数显示逻辑不变 --- lib/pages/message/conversation_tab.dart | 141 +++++++++++++----------- 1 file changed, 74 insertions(+), 67 deletions(-) diff --git a/lib/pages/message/conversation_tab.dart b/lib/pages/message/conversation_tab.dart index 7a20406..c0b9d63 100644 --- a/lib/pages/message/conversation_tab.dart +++ b/lib/pages/message/conversation_tab.dart @@ -1,3 +1,5 @@ +import 'package:dating_touchme_app/extension/ex_widget.dart'; +import 'package:dating_touchme_app/im/im_manager.dart'; import 'package:flutter/material.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:get/get.dart'; @@ -147,83 +149,88 @@ class _ConversationTabState extends State with AutomaticKeepAli future: controller.getUnreadCount(conversation), builder: (context, snapshot){ int unreadCount = snapshot.data ?? 0; - return Container( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(16)), - ), - margin: const EdgeInsets.only(bottom: 8, left: 16, right: 16), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // 头像 - Container( - width: 56, - height: 56, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(28), - image: DecorationImage( - image: userInfo?.avatarUrl != '' ? NetworkImage(userInfo?.avatarUrl ?? '') : AssetImage(Assets.imagesAvatarsExample), - fit: BoxFit.cover, + return GestureDetector( + onTap: () async{ + await IMManager.instance.sendTextMessage('来了', conversation.id); + }, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + decoration: const BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(16)), + ), + margin: const EdgeInsets.only(bottom: 8, left: 16, right: 16), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 头像 + Container( + width: 56, + height: 56, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(28), + image: DecorationImage( + image: userInfo?.avatarUrl != '' ? NetworkImage(userInfo?.avatarUrl ?? '') : AssetImage(Assets.imagesAvatarsExample), + fit: BoxFit.cover, + ), ), ), - ), - const SizedBox(width: 12), - // 会话信息 - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - userInfo?.nickName ?? '联系人', - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Colors.black, + const SizedBox(width: 12), + // 会话信息 + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + userInfo?.nickName ?? '联系人', + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Colors.black, + ), ), - ), - Text( - controller.formatMessageTime(message?.serverTime ?? 0), - style: const TextStyle( - fontSize: 12, - color: Colors.grey, + Text( + controller.formatMessageTime(message?.serverTime ?? 0), + style: const TextStyle( + fontSize: 12, + color: Colors.grey, + ), ), + ], + ), + const SizedBox(height: 4), + Text( + controller.getLastMessageContent(message), + style: const TextStyle( + fontSize: 14, + color: Colors.grey, ), - ], + overflow: TextOverflow.ellipsis, + ), + ], + ), + ), + // 未读消息数 + if (unreadCount > 0) + Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(10), ), - const SizedBox(height: 4), - Text( - controller.getLastMessageContent(message), + child: Text( + unreadCount.toString(), style: const TextStyle( - fontSize: 14, - color: Colors.grey, + fontSize: 12, + color: Colors.white, ), - overflow: TextOverflow.ellipsis, - ), - ], - ), - ), - // 未读消息数 - if (unreadCount > 0) - Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(10), - ), - child: Text( - unreadCount.toString(), - style: const TextStyle( - fontSize: 12, - color: Colors.white, ), ), - ), - ], + ], + ), ), ); }