From b49415550e2b7efd47ec916ecd81c25a4eda4209 Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Fri, 28 Nov 2025 00:21:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(live):=20=E4=BC=98=E5=8C=96=E7=A4=BC?= =?UTF-8?q?=E7=89=A9=E5=BC=B9=E7=AA=97=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B5=A0=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 showHeader 参数控制是否显示用户选择头部 - 新增 targetUserId 参数用于预设礼物接收用户 - 优化礼物弹窗逻辑,支持直接向指定用户赠送礼物 - 在主播展示页面增加向主播或观众赠送礼物的功能入口 - 修复未选择用户时的提示逻辑,避免重复提醒 - 重构 _showGiftPopupForUser 方法统一处理礼物弹窗展示逻辑 --- lib/widget/live/live_gift_popup.dart | 16 +++- .../live/live_room_anchor_showcase.dart | 78 ++++++++++++++++--- 2 files changed, 81 insertions(+), 13 deletions(-) diff --git a/lib/widget/live/live_gift_popup.dart b/lib/widget/live/live_gift_popup.dart index d53a361..b14cd8a 100644 --- a/lib/widget/live/live_gift_popup.dart +++ b/lib/widget/live/live_gift_popup.dart @@ -17,12 +17,16 @@ class LiveGiftPopup extends StatefulWidget { required this.giftNum, required this.giftList, required this.changeActive, + this.showHeader = true, + this.targetUserId, }); final ValueNotifier activeGift; final ValueNotifier giftNum; final List giftList; // 支持 List 或 List final void Function(int) changeActive; + final bool showHeader; // 是否显示头部(用户选择部分) + final String? targetUserId; // 预设的目标用户ID @override State createState() => _LiveGiftPopupState(); @@ -35,6 +39,10 @@ class _LiveGiftPopupState extends State { @override void initState() { super.initState(); + // 如果传入了目标用户ID,直接设置 + if (widget.targetUserId != null) { + _selectedUserId = widget.targetUserId; + } // 默认选择第一个礼物 if (widget.giftList.isNotEmpty && widget.activeGift.value == null) { widget.activeGift.value = 0; @@ -65,9 +73,11 @@ class _LiveGiftPopupState extends State { return; } - // 检查是否选中了接收用户 + // 检查是否选中了接收用户(如果showHeader为false,则必须有targetUserId) if (_selectedUserId == null || _selectedUserId!.isEmpty) { - SmartDialog.showToast('请先选择接收礼物的用户'); + if (widget.showHeader) { + SmartDialog.showToast('请先选择接收礼物的用户'); + } return; } @@ -110,7 +120,7 @@ class _LiveGiftPopupState extends State { height: 363.w, child: Column( children: [ - _buildHeader(), + if (widget.showHeader) _buildHeader(), Expanded( child: Container( decoration: BoxDecoration( diff --git a/lib/widget/live/live_room_anchor_showcase.dart b/lib/widget/live/live_room_anchor_showcase.dart index 22af563..b5744f5 100644 --- a/lib/widget/live/live_room_anchor_showcase.dart +++ b/lib/widget/live/live_room_anchor_showcase.dart @@ -4,6 +4,7 @@ import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/model/rtc/rtc_channel_detail.dart'; import 'package:dating_touchme_app/rtc/rtc_manager.dart'; +import 'package:dating_touchme_app/widget/live/live_gift_popup.dart'; import 'package:dating_touchme_app/widget/live/live_room_guest_list_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -69,11 +70,20 @@ class _LiveRoomAnchorShowcaseState extends State { color: const Color.fromRGBO(0, 0, 0, .3), ), child: Center( - child: Image.asset( - Assets.imagesGiftIcon, - width: 19.w, - height: 19.w, - ), + child: + Image.asset( + Assets.imagesGiftIcon, + width: 19.w, + height: 19.w, + ).onTap(() { + final anchorInfo = _roomController + .rtcChannelDetail + .value + ?.anchorInfo; + if (anchorInfo != null) { + _showGiftPopupForUser(anchorInfo); + } + }), ), ), ), @@ -221,11 +231,14 @@ class _LiveRoomAnchorShowcaseState extends State { ), ), child: Center( - child: Image.asset( - Assets.imagesGiftIcon, - width: 19.w, - height: 19.w, - ), + child: + Image.asset( + Assets.imagesGiftIcon, + width: 19.w, + height: 19.w, + ).onTap(() { + _showGiftPopupForUser(userInfo); + }), ), ), ), @@ -341,4 +354,49 @@ class _LiveRoomAnchorShowcaseState extends State { }, ); } + + void _showGiftPopupForUser(RtcSeatUserInfo? userInfo) { + if (userInfo == null) { + return; + } + + // 获取目标用户ID(优先使用userId,如果没有则使用miId) + final targetUserId = userInfo.userId.isNotEmpty + ? userInfo.userId + : userInfo.miId.isNotEmpty + ? userInfo.miId + : null; + + if (targetUserId == null) { + SmartDialog.showToast('用户ID不存在'); + 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; + }, + showHeader: false, // 不显示头部 + targetUserId: targetUserId, // 设置目标用户ID + ); + }); + }, + ); + } }