Browse Source

fix(live): 修复直播间礼物弹窗头部显示逻辑

- 调整 RoomController 获取位置,避免重复查找
- 当 RoomController 为空时,返回默认头部组件
- 优化 rtcChannelDetail 响应式变量访问方式
- 修复男性观众信息赋值错误问题
- 修复女性观众信息赋值错误问题
- 添加 userData 空值判断,防止空指针异常
ios
Jolie 4 months ago
parent
commit
2c0169e25b
2 changed files with 45 additions and 30 deletions
  1. 46
      lib/controller/discover/room_controller.dart
  2. 29
      lib/widget/live/live_gift_popup.dart

46
lib/controller/discover/room_controller.dart

@ -466,19 +466,22 @@ class RoomController extends GetxController with WidgetsBindingObserver {
if (currentDetail == null) {
return;
}
final userData = response.data.data;
if (userData == null) {
return;
}
if (message['role'] == 'male_audience') {
final userData = response.data.data;
// if (userData != null) {
final maleInfo = RtcSeatUserInfo(
miId: rtcChannelDetail.value!.anchorInfo!.miId,
userId: rtcChannelDetail.value!.anchorInfo!.userId,
nickName: rtcChannelDetail.value!.anchorInfo!.nickName,
profilePhoto: rtcChannelDetail.value!.anchorInfo!.profilePhoto,
genderCode: rtcChannelDetail.value!.anchorInfo!.genderCode,
seatNumber: rtcChannelDetail.value!.anchorInfo!.seatNumber,
isFriend: rtcChannelDetail.value!.anchorInfo!.isFriend,
isMicrophoneOn: rtcChannelDetail.value!.anchorInfo!.isMicrophoneOn,
isVideoOn: rtcChannelDetail.value!.anchorInfo!.isVideoOn,
miId: userData.miId,
userId: userData.userId,
nickName: userData.nickName,
profilePhoto: userData.profilePhoto,
genderCode: userData.genderCode,
seatNumber: userData.seatNumber,
isFriend: userData.isFriend,
isMicrophoneOn: userData.isMicrophoneOn,
isVideoOn: userData.isVideoOn,
uid: message['uid'] is int
? message['uid'] as int
: int.tryParse(message['uid']?.toString() ?? ''),
@ -490,20 +493,17 @@ class RoomController extends GetxController with WidgetsBindingObserver {
femaleInfo: currentDetail.femaleInfo,
);
rtcChannelDetail.value = newDetail;
// }
} else if (message['role'] == 'female_audience') {
final userData = response.data.data;
// if (userData != null) {
final femaleInfo = RtcSeatUserInfo(
miId: rtcChannelDetail.value!.anchorInfo!.miId,
userId: rtcChannelDetail.value!.anchorInfo!.userId,
nickName: rtcChannelDetail.value!.anchorInfo!.nickName,
profilePhoto: rtcChannelDetail.value!.anchorInfo!.profilePhoto,
genderCode: rtcChannelDetail.value!.anchorInfo!.genderCode,
seatNumber: rtcChannelDetail.value!.anchorInfo!.seatNumber,
isFriend: rtcChannelDetail.value!.anchorInfo!.isFriend,
isMicrophoneOn: rtcChannelDetail.value!.anchorInfo!.isMicrophoneOn,
isVideoOn: rtcChannelDetail.value!.anchorInfo!.isVideoOn,
miId: userData.miId,
userId: userData.userId,
nickName: userData.nickName,
profilePhoto: userData.profilePhoto,
genderCode: userData.genderCode,
seatNumber: userData.seatNumber,
isFriend: userData.isFriend,
isMicrophoneOn: userData.isMicrophoneOn,
isVideoOn: userData.isVideoOn,
uid: message['uid'] is int
? message['uid'] as int
: int.tryParse(message['uid']?.toString() ?? ''),

29
lib/widget/live/live_gift_popup.dart

@ -135,14 +135,29 @@ class _LiveGiftPopupState extends State<LiveGiftPopup> {
}
Widget _buildHeader() {
return Obx(() {
// RoomController
final roomController = Get.isRegistered<RoomController>()
? Get.find<RoomController>()
: null;
// RoomController Obx
final roomController = Get.isRegistered<RoomController>()
? Get.find<RoomController>()
: null;
// rtcChannelDetail
final rtcChannelDetail = roomController?.rtcChannelDetail.value;
if (roomController == null) {
return Container(
height: 53.w,
padding: EdgeInsets.symmetric(horizontal: 10.w),
child: Row(
children: [
Text(
"送给: ",
style: TextStyle(fontSize: 13.w, color: Colors.white),
),
],
),
);
}
return Obx(() {
// 访 Obx
final rtcChannelDetail = roomController.rtcChannelDetail.value;
// ID
final currentUserId = GlobalData().userId ?? GlobalData().userData?.id;

Loading…
Cancel
Save