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.
 
 
 
 
 

128 lines
4.4 KiB

import 'package:dating_touchme_app/controller/discover/room_controller.dart';
import 'package:dating_touchme_app/controller/global.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:dating_touchme_app/widget/live/live_room_user_profile_dialog.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 'package:cached_network_image/cached_network_image.dart';
class LiveRoomChatItem extends StatelessWidget {
const LiveRoomChatItem({super.key, required this.message});
final LiveChatMessage message;
void _showGiftPopup(BuildContext context, int type) async {
final roomController = Get.find<RoomController>();
// 刷新玫瑰数量
await roomController.getVirtualAccount();
// 尝试从频道详情中根据 userId 找到对应的用户信息
int? targetUid = message.uid;
// 创建必要的 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,
);
});
},
);
}
@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
? CachedNetworkImage(
imageUrl: message.avatar!,
width: 25.w,
height: 25.w,
fit: BoxFit.cover,
placeholder: (context, url) => Image.asset(
Assets.imagesUserAvatar,
width: 25.w,
height: 25.w,
),
errorWidget: (context, url, error) => Image.asset(
Assets.imagesUserAvatar,
width: 25.w,
height: 25.w,
),
).onTap(() {
// 检查是否是当前用户自己的消息
final currentUserId = GlobalData().userId ?? GlobalData().userData?.id;
if (currentUserId != null && currentUserId == message.userId) {
// 是自己的头像,不显示弹框
return;
}
// 不是自己的消息,显示用户资料对话框
showUserProfileDialog(
context,
message,
() => _showGiftPopup(context, 1),
);
})
: 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),
),
],
),
),
),
],
),
);
}
}