Browse Source

feat(live): 增加礼物弹窗类型区分功能

- 在 LiveGiftPopup 中新增 type 参数用于区分送礼场景
- 修改 _handleSendGift 方法支持传递 type 参数
- 更新 roomController.sendGift 方法调用增加 type 参数
- 在 LiveRoomAnchorShowcase 和 LiveRoomChatItem 中调用礼物弹窗时传入不同 type 值
- 优化聊天界面用户信息展示及送礼流程
- 完善送礼逻辑以支持不同的业务类型区分
ios
Jolie 3 months ago
parent
commit
3d145c8e56
4 changed files with 266 additions and 15 deletions
  1. 3
      lib/controller/discover/room_controller.dart
  2. 8
      lib/widget/live/live_gift_popup.dart
  3. 21
      lib/widget/live/live_room_anchor_showcase.dart
  4. 249
      lib/widget/live/live_room_chat_item.dart

3
lib/controller/discover/room_controller.dart

@ -368,6 +368,7 @@ class RoomController extends GetxController with WidgetsBindingObserver {
Future<void> 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,

8
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<int?> 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<LiveGiftPopup> createState() => _LiveGiftPopupState();
@ -63,7 +65,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
//
Future<void> _handleSendGift() async {
Future<void> _handleSendGift(int type) async {
//
final activeIndex = widget.activeGift.value;
if (activeIndex == null ||
@ -107,7 +109,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
//
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<LiveGiftPopup> {
return Row(
children: [
GestureDetector(
onTap: () => _handleSendGift(),
onTap: () => _handleSendGift(widget.type ?? 0),
child: Container(
width: 63.w,
height: 30.w,

21
lib/widget/live/live_room_anchor_showcase.dart

@ -81,7 +81,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
.value
?.anchorInfo;
if (anchorInfo != null) {
_showGiftPopupForUser(anchorInfo);
_showGiftPopupForUser(anchorInfo, 1);
}
}),
),
@ -106,7 +106,15 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
),
),
),
),
).onTap((){
final anchorInfo = _roomController
.rtcChannelDetail
.value
?.anchorInfo;
if (anchorInfo != null) {
_showGiftPopupForUser(anchorInfo, 2);
}
}),
),
],
),
@ -251,7 +259,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
width: 19.w,
height: 19.w,
).onTap(() {
_showGiftPopupForUser(userInfo);
_showGiftPopupForUser(userInfo, 1);
}),
),
),
@ -277,7 +285,9 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
),
),
),
),
).onTap((){
_showGiftPopupForUser(userInfo, 2);
}),
),
Positioned(
left: 5.w,
@ -355,7 +365,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
);
}
void _showGiftPopupForUser(RtcSeatUserInfo? userInfo) {
void _showGiftPopupForUser(RtcSeatUserInfo? userInfo, int type) {
if (userInfo == null) {
return;
}
@ -388,6 +398,7 @@ class _LiveRoomAnchorShowcaseState extends State<LiveRoomAnchorShowcase> {
changeActive: (index) {
activeGift.value = index;
},
type: type,
showHeader: false, //
targetUserId: targetUserId, // ID
);

249
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<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(
@ -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 {
);
}
}
Loading…
Cancel
Save