|
|
|
@ -2,10 +2,12 @@ import 'package:cached_network_image/cached_network_image.dart'; |
|
|
|
import 'package:dating_touchme_app/controller/discover/room_controller.dart'; |
|
|
|
import 'package:dating_touchme_app/controller/global.dart'; |
|
|
|
import 'package:dating_touchme_app/generated/assets.dart'; |
|
|
|
import 'package:dating_touchme_app/model/live/gift_product_model.dart'; |
|
|
|
import 'package:dating_touchme_app/model/rtc/rtc_channel_detail.dart'; |
|
|
|
import 'package:dating_touchme_app/widget/live/live_room_gift_item.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart'; |
|
|
|
@ -29,34 +31,71 @@ class LiveGiftPopup extends StatefulWidget { |
|
|
|
} |
|
|
|
|
|
|
|
class _LiveGiftPopupState extends State<LiveGiftPopup> { |
|
|
|
// 选中的用户ID集合 |
|
|
|
final Set<String> _selectedUserIds = <String>{}; |
|
|
|
// 选中的用户ID(单选) |
|
|
|
String? _selectedUserId; |
|
|
|
|
|
|
|
// 切换用户选中状态 |
|
|
|
// 切换用户选中状态(单选模式) |
|
|
|
void _toggleUserSelection(String userId) { |
|
|
|
setState(() { |
|
|
|
if (_selectedUserIds.contains(userId)) { |
|
|
|
_selectedUserIds.remove(userId); |
|
|
|
if (_selectedUserId == userId) { |
|
|
|
// 如果点击的是已选中的用户,则取消选中 |
|
|
|
_selectedUserId = null; |
|
|
|
} else { |
|
|
|
_selectedUserIds.add(userId); |
|
|
|
// 否则选中该用户(自动取消之前的选中) |
|
|
|
_selectedUserId = userId; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 全选/取消全选 |
|
|
|
void _toggleSelectAll(List<RtcSeatUserInfo> users) { |
|
|
|
setState(() { |
|
|
|
if (_selectedUserIds.length == users.length) { |
|
|
|
// 如果已全选,则取消全选 |
|
|
|
_selectedUserIds.clear(); |
|
|
|
} else { |
|
|
|
// 否则全选 |
|
|
|
_selectedUserIds.clear(); |
|
|
|
for (var user in users) { |
|
|
|
_selectedUserIds.add(user.userId); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
// 处理赠送礼物 |
|
|
|
Future<void> _handleSendGift() async { |
|
|
|
// 检查是否选中了礼物 |
|
|
|
final activeIndex = widget.activeGift.value; |
|
|
|
if (activeIndex == null || |
|
|
|
activeIndex < 0 || |
|
|
|
activeIndex >= widget.giftList.length) { |
|
|
|
SmartDialog.showToast('请先选择礼物'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否选中了接收用户 |
|
|
|
if (_selectedUserId == null || _selectedUserId!.isEmpty) { |
|
|
|
SmartDialog.showToast('请先选择接收礼物的用户'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取选中的礼物 |
|
|
|
final giftItem = widget.giftList[activeIndex]; |
|
|
|
GiftProductModel? gift; |
|
|
|
|
|
|
|
if (giftItem is GiftProductModel) { |
|
|
|
gift = giftItem; |
|
|
|
} else if (giftItem is Map) { |
|
|
|
// 如果是 Map,需要从 RoomController 的 giftProducts 中查找 |
|
|
|
SmartDialog.showToast('礼物数据格式错误'); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
SmartDialog.showToast('礼物数据格式错误'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取 RoomController |
|
|
|
final roomController = Get.isRegistered<RoomController>() |
|
|
|
? Get.find<RoomController>() |
|
|
|
: null; |
|
|
|
|
|
|
|
if (roomController == null) { |
|
|
|
SmartDialog.showToast('房间控制器未初始化'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 发送礼物 |
|
|
|
await roomController.sendGift(gift: gift, targetUserId: _selectedUserId); |
|
|
|
|
|
|
|
// 关闭弹窗 |
|
|
|
SmartDialog.dismiss(); |
|
|
|
|
|
|
|
SmartDialog.showToast('礼物已送出'); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
@ -141,7 +180,7 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> { |
|
|
|
...displayUsers.asMap().entries.map((entry) { |
|
|
|
final index = entry.key; |
|
|
|
final user = entry.value; |
|
|
|
final isSelected = _selectedUserIds.contains(user.userId); |
|
|
|
final isSelected = _selectedUserId == user.userId; |
|
|
|
return GestureDetector( |
|
|
|
onTap: () => _toggleUserSelection(user.userId), |
|
|
|
child: Padding( |
|
|
|
@ -228,27 +267,6 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> { |
|
|
|
}), |
|
|
|
], |
|
|
|
), |
|
|
|
// 如果列表为空,不显示全选按钮 |
|
|
|
if (displayUsers.isNotEmpty) |
|
|
|
GestureDetector( |
|
|
|
onTap: () => _toggleSelectAll(displayUsers), |
|
|
|
child: Container( |
|
|
|
width: 63.w, |
|
|
|
height: 30.w, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30.w)), |
|
|
|
color: const Color.fromRGBO(117, 98, 249, 1), |
|
|
|
), |
|
|
|
child: Center( |
|
|
|
child: Text( |
|
|
|
_selectedUserIds.length == displayUsers.length |
|
|
|
? "取消全选" |
|
|
|
: "全选", |
|
|
|
style: TextStyle(fontSize: 13.w, color: Colors.white), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
@ -371,49 +389,27 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> { |
|
|
|
builder: (context, num, _) { |
|
|
|
return Row( |
|
|
|
children: [ |
|
|
|
_buildAdjustButton( |
|
|
|
label: "-", |
|
|
|
enabled: num > 1, |
|
|
|
onTap: () { |
|
|
|
if (widget.giftNum.value <= 1) return; |
|
|
|
widget.giftNum.value -= 1; |
|
|
|
}, |
|
|
|
), |
|
|
|
SizedBox( |
|
|
|
width: 23.w, |
|
|
|
child: Center( |
|
|
|
child: Text( |
|
|
|
"$num", |
|
|
|
style: TextStyle(fontSize: 13.w, color: Colors.white), |
|
|
|
GestureDetector( |
|
|
|
onTap: () => _handleSendGift(), |
|
|
|
child: Container( |
|
|
|
width: 63.w, |
|
|
|
height: 30.w, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30.w)), |
|
|
|
gradient: const LinearGradient( |
|
|
|
begin: Alignment.centerLeft, |
|
|
|
end: Alignment.centerRight, |
|
|
|
colors: [ |
|
|
|
Color.fromRGBO(61, 138, 224, 1), |
|
|
|
Color.fromRGBO(131, 89, 255, 1), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
_buildAdjustButton( |
|
|
|
label: "+", |
|
|
|
enabled: true, |
|
|
|
onTap: () { |
|
|
|
widget.giftNum.value += 1; |
|
|
|
}, |
|
|
|
), |
|
|
|
SizedBox(width: 9.w), |
|
|
|
Container( |
|
|
|
width: 63.w, |
|
|
|
height: 30.w, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30.w)), |
|
|
|
gradient: const LinearGradient( |
|
|
|
begin: Alignment.centerLeft, |
|
|
|
end: Alignment.centerRight, |
|
|
|
colors: [ |
|
|
|
Color.fromRGBO(61, 138, 224, 1), |
|
|
|
Color.fromRGBO(131, 89, 255, 1), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
child: Center( |
|
|
|
child: Text( |
|
|
|
"赠送", |
|
|
|
style: TextStyle(fontSize: 13.w, color: Colors.white), |
|
|
|
child: Center( |
|
|
|
child: Text( |
|
|
|
"赠送", |
|
|
|
style: TextStyle(fontSize: 13.w, color: Colors.white), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|