You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

307 lines
10 KiB

import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart';
import 'package:dating_touchme_app/generated/assets.dart';
import 'package:dating_touchme_app/model/live/live_chat_message.dart';
import 'package:dating_touchme_app/widget/live/live_gift_popup.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';
import '../../pages/message/chat_page.dart';
class LiveRoomChatItem extends StatelessWidget {
const LiveRoomChatItem({super.key, required this.message});
final LiveChatMessage message;
void _showGiftPopup(BuildContext context, int type) {
final roomController = Get.find<RoomController>();
// 尝试从频道详情中根据 userId 找到对应的用户信息
final channelDetail = roomController.rtcChannelDetail.value;
int? targetUid;
// 尝试匹配用户
if (channelDetail?.anchorInfo?.userId == message.userId) {
targetUid = channelDetail?.anchorInfo?.uid;
} else if (channelDetail?.maleInfo?.userId == message.userId) {
targetUid = channelDetail?.maleInfo?.uid;
} else if (channelDetail?.femaleInfo?.userId == message.userId) {
targetUid = channelDetail?.femaleInfo?.uid;
}
if (targetUid == null) {
SmartDialog.showToast('无法获取用户信息');
return;
}
// 创建必要的 ValueNotifier
final activeGift = ValueNotifier<int?>(null);
final giftNum = ValueNotifier<int>(1);
SmartDialog.show(
alignment: Alignment.bottomCenter,
maskColor: Colors.black.withOpacity(0.5),
builder: (context) {
return Obx(() {
// 获取礼物列表
final giftProducts = roomController.giftProducts;
final giftList = giftProducts.toList();
return LiveGiftPopup(
activeGift: activeGift,
giftNum: giftNum,
giftList: giftList,
changeActive: (index) {
activeGift.value = index;
},
type: type,
showHeader: false,
targetUserId: targetUid,
);
});
},
);
}
void _showUserProfileDialog(BuildContext context) {
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();
_showGiftPopup(context, 1);
},
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();
_showGiftPopup(context, 1);
}),
],
),
],
),
),
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),
),
),
);
}
@override
Widget build(BuildContext context) {
return Container(
width: 260.w,
margin: EdgeInsets.only(bottom: 15.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 头像
ClipOval(
child: message.avatar != null && message.avatar!.isNotEmpty
? Image.network(
message.avatar!,
width: 25.w,
height: 25.w,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Image.asset(
Assets.imagesUserAvatar,
width: 25.w,
height: 25.w,
);
},
).onTap(() {
_showUserProfileDialog(context);
})
: Image.asset(
Assets.imagesUserAvatar,
width: 25.w,
height: 25.w,
),
),
SizedBox(width: 10.w),
// 消息内容
Expanded(
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "${message.userName}",
style: TextStyle(
fontSize: 11.w,
color: const Color.fromRGBO(155, 138, 246, 1),
),
),
TextSpan(
text: message.content,
style: TextStyle(fontSize: 11.w, color: Colors.white),
),
],
),
),
),
],
),
);
}
}