Browse Source
feat(live): 添加用户ID支持并重构聊天消息功能
feat(live): 添加用户ID支持并重构聊天消息功能
- 在 LiveChatMessage 模型中添加 uid 字段支持 - 更新消息序列化逻辑以包含用户ID信息 - 重构用户资料对话框为独立组件并优化显示逻辑 - 改进聊天消息滚动和自动定位到底部的机制 - 优化礼物赠送消息的发送和显示逻辑 - 移除过时的用户信息查找代码并提升性能 - 调整直播间页面布局结构和组件组织方式master
7 changed files with 336 additions and 294 deletions
Unified View
Diff Options
-
118lib/controller/discover/room_controller.dart
-
13lib/model/live/live_chat_message.dart
-
69lib/pages/discover/live_room_page.dart
-
4lib/service/live_chat_message_service.dart
-
208lib/widget/live/live_room_chat_item.dart
-
23lib/widget/live/live_room_notice_chat_panel.dart
-
195lib/widget/live/live_room_user_profile_dialog.dart
@ -0,0 +1,195 @@ |
|||||
|
import 'package:dating_touchme_app/generated/assets.dart'; |
||||
|
import 'package:dating_touchme_app/model/live/live_chat_message.dart'; |
||||
|
import 'package:dating_touchme_app/pages/message/chat_page.dart'; |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
/// 显示用户资料对话框 |
||||
|
void showUserProfileDialog( |
||||
|
BuildContext context, |
||||
|
LiveChatMessage message, |
||||
|
VoidCallback onShowGiftPopup, |
||||
|
) { |
||||
|
SmartDialog.show( |
||||
|
alignment: Alignment.bottomCenter, |
||||
|
builder: (context) { |
||||
|
return Stack( |
||||
|
children: [ |
||||
|
Container( |
||||
|
decoration: BoxDecoration( |
||||
|
color: Colors.white, |
||||
|
borderRadius: BorderRadius.only( |
||||
|
topLeft: Radius.circular(20.w), |
||||
|
topRight: Radius.circular(20.w), |
||||
|
), |
||||
|
), |
||||
|
height: 200.w, |
||||
|
margin: EdgeInsets.only(top: 40.w), |
||||
|
padding: EdgeInsets.symmetric(horizontal: 15.w), |
||||
|
child: Column( |
||||
|
mainAxisSize: MainAxisSize.min, |
||||
|
children: [ |
||||
|
SizedBox(height: 10.w), |
||||
|
// 用户头像和信息 |
||||
|
Row( |
||||
|
children: [ |
||||
|
SizedBox(width: 110.w), |
||||
|
// 用户名和标签 |
||||
|
Expanded( |
||||
|
child: Column( |
||||
|
crossAxisAlignment: CrossAxisAlignment.start, |
||||
|
children: [ |
||||
|
Text( |
||||
|
message.userName, |
||||
|
style: TextStyle( |
||||
|
fontSize: 18.w, |
||||
|
fontWeight: FontWeight.w600, |
||||
|
color: const Color.fromRGBO(51, 51, 51, 1), |
||||
|
), |
||||
|
), |
||||
|
SizedBox(height: 8.w), |
||||
|
// 标签 |
||||
|
Wrap( |
||||
|
spacing: 6.w, |
||||
|
runSpacing: 6.w, |
||||
|
children: [ |
||||
|
_buildTag( |
||||
|
'在线', |
||||
|
const Color.fromRGBO(198, 246, 213, 1), |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
GestureDetector( |
||||
|
onTap: () => SmartDialog.dismiss(), |
||||
|
child: Icon( |
||||
|
Icons.close, |
||||
|
size: 24.w, |
||||
|
color: const Color.fromRGBO(153, 153, 153, 1), |
||||
|
), |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
SizedBox(height: 25.w), |
||||
|
// 送礼物按钮 |
||||
|
GestureDetector( |
||||
|
onTap: () { |
||||
|
SmartDialog.dismiss(); |
||||
|
onShowGiftPopup(); |
||||
|
}, |
||||
|
child: Container( |
||||
|
width: double.infinity, |
||||
|
height: 44.w, |
||||
|
decoration: BoxDecoration( |
||||
|
gradient: const LinearGradient( |
||||
|
colors: [ |
||||
|
Color.fromRGBO(117, 98, 249, 1), |
||||
|
Color.fromRGBO(152, 124, 255, 1), |
||||
|
], |
||||
|
begin: Alignment.centerLeft, |
||||
|
end: Alignment.centerRight, |
||||
|
), |
||||
|
borderRadius: BorderRadius.circular(22.w), |
||||
|
), |
||||
|
child: Center( |
||||
|
child: Text( |
||||
|
'送礼物', |
||||
|
style: TextStyle( |
||||
|
fontSize: 16.w, |
||||
|
color: Colors.white, |
||||
|
fontWeight: FontWeight.w500, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
SizedBox(height: 15.w), |
||||
|
// 底部操作链接 |
||||
|
Row( |
||||
|
mainAxisAlignment: MainAxisAlignment.center, |
||||
|
children: [ |
||||
|
_buildActionLink('私聊', () { |
||||
|
SmartDialog.dismiss(); |
||||
|
Get.to(() => ChatPage( |
||||
|
userId: message.userId, |
||||
|
)); |
||||
|
}), |
||||
|
Container( |
||||
|
width: 1.w, |
||||
|
height: 12.w, |
||||
|
color: const Color.fromRGBO(229, 229, 229, 1), |
||||
|
margin: EdgeInsets.symmetric(horizontal: 15.w), |
||||
|
), |
||||
|
_buildActionLink('送礼物加好友', () { |
||||
|
SmartDialog.dismiss(); |
||||
|
onShowGiftPopup(); |
||||
|
}), |
||||
|
], |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
Container( |
||||
|
margin: EdgeInsets.only(left: 30.w), |
||||
|
child: ClipOval( |
||||
|
child: message.avatar != null && message.avatar!.isNotEmpty |
||||
|
? Image.network( |
||||
|
message.avatar!, |
||||
|
width: 80.w, |
||||
|
height: 80.w, |
||||
|
fit: BoxFit.cover, |
||||
|
errorBuilder: (context, error, stackTrace) { |
||||
|
return Image.asset( |
||||
|
Assets.imagesUserAvatar, |
||||
|
width: 60.w, |
||||
|
height: 60.w, |
||||
|
); |
||||
|
}, |
||||
|
) |
||||
|
: Image.asset( |
||||
|
Assets.imagesUserAvatar, |
||||
|
width: 60.w, |
||||
|
height: 60.w, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
], |
||||
|
); |
||||
|
}, |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
Widget _buildTag(String text, Color bgColor) { |
||||
|
return Container( |
||||
|
padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 3.w), |
||||
|
decoration: BoxDecoration( |
||||
|
color: bgColor, |
||||
|
borderRadius: BorderRadius.circular(10.w), |
||||
|
), |
||||
|
child: Text( |
||||
|
text, |
||||
|
style: TextStyle( |
||||
|
fontSize: 11.w, |
||||
|
color: const Color.fromRGBO(51, 51, 51, 1), |
||||
|
), |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
Widget _buildActionLink(String text, VoidCallback onTap) { |
||||
|
return GestureDetector( |
||||
|
onTap: onTap, |
||||
|
child: Text( |
||||
|
text, |
||||
|
style: TextStyle( |
||||
|
fontSize: 12.w, |
||||
|
color: const Color.fromRGBO(153, 153, 153, 1), |
||||
|
), |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save