diff --git a/lib/controller/discover/room_controller.dart b/lib/controller/discover/room_controller.dart index c9fcfd6..ac2c495 100644 --- a/lib/controller/discover/room_controller.dart +++ b/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() ?? ''), diff --git a/lib/widget/live/live_gift_popup.dart b/lib/widget/live/live_gift_popup.dart index 2e4daab..d53a361 100644 --- a/lib/widget/live/live_gift_popup.dart +++ b/lib/widget/live/live_gift_popup.dart @@ -135,14 +135,29 @@ class _LiveGiftPopupState extends State { } Widget _buildHeader() { - return Obx(() { - // 获取 RoomController - final roomController = Get.isRegistered() - ? Get.find() - : null; + // 获取 RoomController(在 Obx 外部获取,避免重复查找) + final roomController = Get.isRegistered() + ? Get.find() + : 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;