Browse Source

feat(live): 优化礼物弹窗支持指定用户赠送

- 新增 showHeader 参数控制是否显示用户选择头部
- 新增 targetUserId 参数用于预设礼物接收用户
- 优化礼物弹窗逻辑,支持直接向指定用户赠送礼物
- 在主播展示页面增加向主播或观众赠送礼物的功能入口
- 修复未选择用户时的提示逻辑,避免重复提醒
- 重构 _showGiftPopupForUser 方法统一处理礼物弹窗展示逻辑
ios
Jolie 4 months ago
parent
commit
b49415550e
2 changed files with 81 additions and 13 deletions
  1. 16
      lib/widget/live/live_gift_popup.dart
  2. 78
      lib/widget/live/live_room_anchor_showcase.dart

16
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<int?> activeGift;
final ValueNotifier<int> giftNum;
final List<dynamic> giftList; // List<Map> List<GiftProductModel>
final void Function(int) changeActive;
final bool showHeader; //
final String? targetUserId; // ID
@override
State<LiveGiftPopup> createState() => _LiveGiftPopupState();
@ -35,6 +39,10 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
@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<LiveGiftPopup> {
return;
}
//
// showHeader为falsetargetUserId
if (_selectedUserId == null || _selectedUserId!.isEmpty) {
SmartDialog.showToast('请先选择接收礼物的用户');
if (widget.showHeader) {
SmartDialog.showToast('请先选择接收礼物的用户');
}
return;
}
@ -110,7 +120,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
height: 363.w,
child: Column(
children: [
_buildHeader(),
if (widget.showHeader) _buildHeader(),
Expanded(
child: Container(
decoration: BoxDecoration(

78
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<LiveRoomAnchorShowcase> {
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<LiveRoomAnchorShowcase> {
),
),
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<LiveRoomAnchorShowcase> {
},
);
}
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<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;
},
showHeader: false, //
targetUserId: targetUserId, // ID
);
});
},
);
}
}
Loading…
Cancel
Save