From b150d62d92dd32fc46d0a7fcfb80c8067ea3ac80 Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Tue, 11 Nov 2025 15:55:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(message):=20=E5=AE=9E=E7=8E=B0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=A1=B5=E9=9D=A2=E5=9F=BA=E7=A1=80UI=E4=B8=8E?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A0=8F=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -组件ChatInputBar 添加聊天输入栏 - 重构聊天页面布局,使用Column替代Container - 设置聊天背景色为#F5F5F5 - 添加消息列表展示区域,包含头像与消息气泡 - 实现消息时间戳展示 - 添加IM管理器用户信息获取方法 - 优化ChatPage构造函数为常量构造函数 - 导入聊天输入栏组件文件 --- lib/im/im_manager.dart | 6 +++ lib/pages/message/chat_page.dart | 80 ++++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/lib/im/im_manager.dart b/lib/im/im_manager.dart index af4a8f2..84d4d77 100644 --- a/lib/im/im_manager.dart +++ b/lib/im/im_manager.dart @@ -228,6 +228,12 @@ class IMManager { return cursor.data; } + /// 获取用户信息 + Future getUserInfo(String userId) async { + var data = await EMClient.getInstance.userInfoManager.fetchUserInfoById([userId]); + return data[userId]; + } + /// 清理资源 void dispose() { try { diff --git a/lib/pages/message/chat_page.dart b/lib/pages/message/chat_page.dart index 165c8b6..14c23fe 100644 --- a/lib/pages/message/chat_page.dart +++ b/lib/pages/message/chat_page.dart @@ -4,12 +4,13 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../generated/assets.dart'; +import '../../../widget/message/chat_input_bar.dart'; class ChatPage extends StatefulWidget { - String userId; + final String userId; - ChatPage({required this.userId, super.key}); + const ChatPage({required this.userId, super.key}); @override State createState() => _ChatPageState(); @@ -19,6 +20,7 @@ class _ChatPageState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Color(0xffF5F5F5), appBar: AppBar( title: Text("Chat"), centerTitle: true, @@ -37,8 +39,78 @@ class _ChatPageState extends State { }, ), ), - body: Container( - + body: Column( + children: [ + // 消息列表区域 + Expanded( + child: SingleChildScrollView( + reverse: true, + padding: EdgeInsets.all(16.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 时间戳 + Text( + "昨天下午14:46", + style: TextStyle( + fontSize: 12.sp, + color: Colors.grey, + ), + textAlign: TextAlign.center, + ), + SizedBox(height: 16.h), + // 消息项 + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 头像 + Container( + width: 40.w, + height: 40.w, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20.w), + image: DecorationImage( + image: AssetImage(Assets.imagesAvatarsExample), + fit: BoxFit.cover, + ), + ), + ), + SizedBox(width: 8.w), + // 消息气泡 + Container( + padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topRight: Radius.circular(12.w), + bottomLeft: Radius.circular(12.w), + bottomRight: Radius.circular(12.w), + ), + ), + child: Text( + "你好", + style: TextStyle( + fontSize: 14.sp, + color: Colors.black, + ), + ), + ), + ], + ), + ], + ), + ), + ), + // 使用抽离的聊天输入栏组件 + ChatInputBar( + onSendMessage: (message) { + // 处理发送消息 + if (Get.isLogEnable) { + Get.log("接收到消息: $message"); + } + }, + ), + ], ), ); }