diff --git a/lib/controller/discover/room_controller.dart b/lib/controller/discover/room_controller.dart index 7be37ee..0d60866 100644 --- a/lib/controller/discover/room_controller.dart +++ b/lib/controller/discover/room_controller.dart @@ -368,6 +368,7 @@ class RoomController extends GetxController with WidgetsBindingObserver { Future sendGift({ required GiftProductModel gift, required int targetUserId, + required int type, }) async { try { // 先调用消费接口 @@ -380,7 +381,7 @@ class RoomController extends GetxController with WidgetsBindingObserver { // 准备请求参数 final requestData = { 'channelId': int.tryParse(channelId) ?? 0, - 'type': 1, // 1.送礼 2.添加好友 + 'type': type, // 1.送礼 2.添加好友 'toUId': targetUserId, 'productSpecId': int.tryParse(gift.productSpecId) ?? 0, 'quantity': 1, diff --git a/lib/widget/live/live_gift_popup.dart b/lib/widget/live/live_gift_popup.dart index 19c5890..e5eebd9 100644 --- a/lib/widget/live/live_gift_popup.dart +++ b/lib/widget/live/live_gift_popup.dart @@ -19,6 +19,7 @@ class LiveGiftPopup extends StatefulWidget { required this.changeActive, this.showHeader = true, this.targetUserId, + this.type, }); final ValueNotifier activeGift; @@ -27,6 +28,7 @@ class LiveGiftPopup extends StatefulWidget { final void Function(int) changeActive; final bool showHeader; // 是否显示头部(用户选择部分) final int? targetUserId; // 预设的目标用户ID + final int? type; @override State createState() => _LiveGiftPopupState(); @@ -63,7 +65,7 @@ class _LiveGiftPopupState extends State { } // 处理赠送礼物 - Future _handleSendGift() async { + Future _handleSendGift(int type) async { // 检查是否选中了礼物 final activeIndex = widget.activeGift.value; if (activeIndex == null || @@ -107,7 +109,7 @@ class _LiveGiftPopupState extends State { } // 发送礼物 - await roomController.sendGift(gift: gift, targetUserId: _selectedUserId ?? 0); + await roomController.sendGift(gift: gift, targetUserId: _selectedUserId ?? 0, type: type); SmartDialog.dismiss(); } @@ -391,7 +393,7 @@ class _LiveGiftPopupState extends State { return Row( children: [ GestureDetector( - onTap: () => _handleSendGift(), + onTap: () => _handleSendGift(widget.type ?? 0), child: Container( width: 63.w, height: 30.w, diff --git a/lib/widget/live/live_room_anchor_showcase.dart b/lib/widget/live/live_room_anchor_showcase.dart index 57212b0..7ccc634 100644 --- a/lib/widget/live/live_room_anchor_showcase.dart +++ b/lib/widget/live/live_room_anchor_showcase.dart @@ -81,7 +81,7 @@ class _LiveRoomAnchorShowcaseState extends State { .value ?.anchorInfo; if (anchorInfo != null) { - _showGiftPopupForUser(anchorInfo); + _showGiftPopupForUser(anchorInfo, 1); } }), ), @@ -106,7 +106,15 @@ class _LiveRoomAnchorShowcaseState extends State { ), ), ), - ), + ).onTap((){ + final anchorInfo = _roomController + .rtcChannelDetail + .value + ?.anchorInfo; + if (anchorInfo != null) { + _showGiftPopupForUser(anchorInfo, 2); + } + }), ), ], ), @@ -251,7 +259,7 @@ class _LiveRoomAnchorShowcaseState extends State { width: 19.w, height: 19.w, ).onTap(() { - _showGiftPopupForUser(userInfo); + _showGiftPopupForUser(userInfo, 1); }), ), ), @@ -277,7 +285,9 @@ class _LiveRoomAnchorShowcaseState extends State { ), ), ), - ), + ).onTap((){ + _showGiftPopupForUser(userInfo, 2); + }), ), Positioned( left: 5.w, @@ -355,7 +365,7 @@ class _LiveRoomAnchorShowcaseState extends State { ); } - void _showGiftPopupForUser(RtcSeatUserInfo? userInfo) { + void _showGiftPopupForUser(RtcSeatUserInfo? userInfo, int type) { if (userInfo == null) { return; } @@ -388,6 +398,7 @@ class _LiveRoomAnchorShowcaseState extends State { changeActive: (index) { activeGift.value = index; }, + type: type, showHeader: false, // 不显示头部 targetUserId: targetUserId, // 设置目标用户ID ); diff --git a/lib/widget/live/live_room_chat_item.dart b/lib/widget/live/live_room_chat_item.dart index b555ff0..a71348f 100644 --- a/lib/widget/live/live_room_chat_item.dart +++ b/lib/widget/live/live_room_chat_item.dart @@ -1,16 +1,252 @@ +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, - }); + const LiveRoomChatItem({super.key, required this.message}); final LiveChatMessage message; + void _showGiftPopup(BuildContext context, int type) { + final roomController = Get.find(); + + // 尝试从频道详情中根据 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(null); + final giftNum = ValueNotifier(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( @@ -34,7 +270,9 @@ class LiveRoomChatItem extends StatelessWidget { height: 25.w, ); }, - ) + ).onTap(() { + _showUserProfileDialog(context); + }) : Image.asset( Assets.imagesUserAvatar, width: 25.w, @@ -67,4 +305,3 @@ class LiveRoomChatItem extends StatelessWidget { ); } } -