diff --git a/lib/controller/discover/room_controller.dart b/lib/controller/discover/room_controller.dart index f10499a..ce0cb06 100644 --- a/lib/controller/discover/room_controller.dart +++ b/lib/controller/discover/room_controller.dart @@ -59,6 +59,7 @@ class RoomController extends GetxController with WidgetsBindingObserver { /// 玫瑰数量 final RxInt roseCount = 0.obs; + var isDialogShowing = false.obs; /// 消息服务实例 final LiveChatMessageService _messageService = @@ -94,6 +95,10 @@ class RoomController extends GetxController with WidgetsBindingObserver { chatMessages.clear(); } + void setDialogDismiss(bool flag){ + isDialogShowing.value = flag; + } + /// 注册消息监听 void _registerMessageListener() { _messageService.registerMessageListener( @@ -460,8 +465,12 @@ class RoomController extends GetxController with WidgetsBindingObserver { Get.log('❌ 送礼失败: ${response.data.data}'); // 使用 addPostFrameCallback 确保在下一帧显示弹框,避免与 toast 冲突 WidgetsBinding.instance.addPostFrameCallback((_) { + setDialogDismiss(true); SmartDialog.show( alignment: Alignment.bottomCenter, + onDismiss: (){ + setDialogDismiss(false); + }, maskColor: Colors.black.withOpacity(0.5), builder: (_) => const LiveRechargePopup(), ); diff --git a/lib/pages/discover/live_room_page.dart b/lib/pages/discover/live_room_page.dart index 5716bb8..e8e7bc9 100644 --- a/lib/pages/discover/live_room_page.dart +++ b/lib/pages/discover/live_room_page.dart @@ -184,9 +184,14 @@ class _LiveRoomPageState extends State { FocusScope.of(context).unfocus(); // 刷新玫瑰数量 await _roomController.getVirtualAccount(); + _roomController.setDialogDismiss(true); SmartDialog.show( + backType: SmartBackType.block, alignment: Alignment.bottomCenter, maskColor: TDTheme.of(context).fontGyColor2, + onDismiss: () { + _roomController.setDialogDismiss(false); + }, builder: (_) => Obx(() { // 优先使用 API 返回的 giftProducts,如果为空则使用后备列表 final giftProducts = _roomController.giftProducts; @@ -205,9 +210,13 @@ class _LiveRoomPageState extends State { void _showRechargePopup() { // 隐藏键盘 FocusScope.of(context).unfocus(); + _roomController.setDialogDismiss(true); SmartDialog.show( alignment: Alignment.bottomCenter, maskColor: TDTheme.of(context).fontGyColor2, + onDismiss: (){ + _roomController.setDialogDismiss(false); + }, builder: (_) => const LiveRechargePopup(), ); } @@ -234,151 +243,164 @@ class _LiveRoomPageState extends State { }); } }); + return Obx(() { + return PopScope( + canPop: !_roomController.isDialogShowing.value, + onPopInvokedWithResult: (bool didPop, Object? result) async { + // SmartDialog.dismiss(); + // print('256>22>>' + didPop.toString()); + // if (didPop) return; - return PopScope( - onPopInvokedWithResult: (bool didPop, Object? result) async { - SmartDialog.dismiss(); - // 退出房间时清空RTM消息 - if (Get.isRegistered()) { - final roomController = Get.find(); - roomController.chatMessages.clear(); - } - // 如果还没有执行 pop,手动调用 Get.back() - if (!didPop) { - Get.back(); - } - // 等待页面关闭后再显示小窗口,确保小窗口能正确显示 - Future.delayed(const Duration(milliseconds: 200), () { - _overlayController.show(); - }); - }, - child: Scaffold( - resizeToAvoidBottomInset: false, - body: Stack( - children: [ - Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Color.fromRGBO(248, 242, 255, 1), - Color.fromRGBO(247, 247, 247, 1), - ], + // 如果有对话框显示,关闭对话框 + if (_roomController.isDialogShowing.value) { + SmartDialog.dismiss(); + return; // 阻止页面返回 + } + // 退出房间时清空RTM消息 + if (Get.isRegistered()) { + final roomController = Get.find(); + roomController.chatMessages.clear(); + } + // 如果还没有执行 pop,手动调用 Get.back() + if (!didPop) { + Get.back(); + } + // 等待页面关闭后再显示小窗口,确保小窗口能正确显示 + Future.delayed(const Duration(milliseconds: 200), () { + _overlayController.show(); + }); + }, + child: Scaffold( + resizeToAvoidBottomInset: false, + body: Stack( + children: [ + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Color.fromRGBO(248, 242, 255, 1), + Color.fromRGBO(247, 247, 247, 1), + ], + ), ), ), - ), - Container( - decoration: const BoxDecoration( - gradient: LinearGradient( - begin: Alignment.bottomCenter, - end: Alignment.topCenter, - colors: [ - Color.fromRGBO(19, 16, 47, 1), - Color.fromRGBO(19, 16, 47, 1), - ], + Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.bottomCenter, + end: Alignment.topCenter, + colors: [ + Color.fromRGBO(19, 16, 47, 1), + Color.fromRGBO(19, 16, 47, 1), + ], + ), ), ), - ), - Container( - padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), - child: Column( - children: [ - SizedBox(height: 10.w), - Obx(() { - final detail = _roomController.rtcChannelDetail.value; - final anchorInfo = detail?.anchorInfo; + Container( + padding: EdgeInsets.only( + top: MediaQuery.of(context).padding.top, + ), + child: Column( + children: [ + SizedBox(height: 10.w), + Obx(() { + final detail = _roomController.rtcChannelDetail.value; + final anchorInfo = detail?.anchorInfo; - final userName = anchorInfo?.nickName ?? '用户'; - final avatarAsset = anchorInfo?.profilePhoto ?? Assets.imagesUserAvatar; - const popularityText = '0'; // TODO: 使用真实数据 + final userName = anchorInfo?.nickName ?? '用户'; + final avatarAsset = + anchorInfo?.profilePhoto ?? Assets.imagesUserAvatar; + const popularityText = '0'; // TODO: 使用真实数据 - return LiveRoomUserHeader( - userName: userName, - popularityText: popularityText, - avatarAsset: avatarAsset, - onCloseTap: () { - SmartDialog.dismiss(); - // 退出房间时清空RTM消息 - if (Get.isRegistered()) { - final roomController = Get.find(); - roomController.chatMessages.clear(); - } - Get.back(); - // 等待页面关闭后再显示小窗口,确保小窗口能正确显示 - Future.delayed(const Duration(milliseconds: 200), () { - _overlayController.show(); - }); - }, - ); - }), - SizedBox(height: 7.w), - LiveRoomAnchorShowcase(), - SizedBox(height: 5.w), - const LiveRoomActiveSpeaker(), - SizedBox(height: 9.w), - Expanded(child: const LiveRoomNoticeChatPanel()), - // 根据键盘状态显示/隐藏 LiveRoomActionBar - if (MediaQuery.of(context).viewInsets.bottom == 0) - SafeArea( - top: false, - child: Padding( - padding: EdgeInsets.only( - bottom: 10.w, - left: 0, - right: 0, - ), - child: LiveRoomActionBar( - messageController: _messageController, - onMessageChanged: (value) { - message = value; - }, - onSendTap: _sendMessage, - onGiftTap: _showGiftPopup, - onChargeTap: _showRechargePopup, - onInputTap: _openInputDialog, + return LiveRoomUserHeader( + userName: userName, + popularityText: popularityText, + avatarAsset: avatarAsset, + onCloseTap: () { + SmartDialog.dismiss(); + // 退出房间时清空RTM消息 + if (Get.isRegistered()) { + final roomController = Get.find(); + roomController.chatMessages.clear(); + } + Get.back(); + // 等待页面关闭后再显示小窗口,确保小窗口能正确显示 + Future.delayed(const Duration(milliseconds: 200), () { + _overlayController.show(); + }); + }, + ); + }), + SizedBox(height: 7.w), + LiveRoomAnchorShowcase(), + SizedBox(height: 5.w), + const LiveRoomActiveSpeaker(), + SizedBox(height: 9.w), + Expanded(child: const LiveRoomNoticeChatPanel()), + // 根据键盘状态显示/隐藏 LiveRoomActionBar + if (MediaQuery.of(context).viewInsets.bottom == 0) + SafeArea( + top: false, + child: Padding( + padding: EdgeInsets.only( + bottom: 10.w, + left: 0, + right: 0, + ), + child: LiveRoomActionBar( + messageController: _messageController, + onMessageChanged: (value) { + message = value; + }, + onSendTap: _sendMessage, + onGiftTap: _showGiftPopup, + onChargeTap: _showRechargePopup, + onInputTap: _openInputDialog, + ), ), ), - ), - ], - ), - ), - // SVGA 动画播放组件 - const SvgaPlayerWidget(), - // 输入对话框 - if (_showInputDialog) ...[ - // 遮罩层,点击时隐藏对话框和键盘(放在对话框下方,对话框会在上面拦截点击) - Positioned.fill( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - // 隐藏键盘 - FocusScope.of(context).unfocus(); - // 隐藏对话框 - _hideInputDialog(); - }, - child: Container(color: Colors.transparent), + ], ), ), - // 输入对话框(放在遮罩层上面,会自动拦截点击事件) - AnimatedPositioned( - duration: const Duration(milliseconds: 200), - curve: Curves.easeOut, - left: 0, - right: 0, - bottom: MediaQuery.of(context).viewInsets.bottom, - child: _InputDialogWidget( - controller: _inputDialogController, - focusNode: _inputDialogFocusNode, - onSend: _sendInputDialogMessage, - onClose: _hideInputDialog, + // SVGA 动画播放组件 + const SvgaPlayerWidget(), + // 输入对话框 + if (_showInputDialog) ...[ + // 遮罩层,点击时隐藏对话框和键盘(放在对话框下方,对话框会在上面拦截点击) + Positioned.fill( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + // 隐藏键盘 + FocusScope.of(context).unfocus(); + // 隐藏对话框 + _hideInputDialog(); + }, + child: Container(color: Colors.transparent), + ), ), - ), + // 输入对话框(放在遮罩层上面,会自动拦截点击事件) + AnimatedPositioned( + duration: const Duration(milliseconds: 200), + curve: Curves.easeOut, + left: 0, + right: 0, + bottom: MediaQuery.of(context).viewInsets.bottom, + child: _InputDialogWidget( + controller: _inputDialogController, + focusNode: _inputDialogFocusNode, + onSend: _sendInputDialogMessage, + onClose: _hideInputDialog, + ), + ), + ], ], - ], + ), ), - ), - ); + ); + }); } } diff --git a/lib/widget/live/live_room_anchor_showcase.dart b/lib/widget/live/live_room_anchor_showcase.dart index 8a768fe..8dd765c 100644 --- a/lib/widget/live/live_room_anchor_showcase.dart +++ b/lib/widget/live/live_room_anchor_showcase.dart @@ -376,9 +376,13 @@ class _LiveRoomAnchorShowcaseState extends State { } void _showGuestListDialog(BuildContext context, bool isMaleSeat) { + _roomController.setDialogDismiss(true); SmartDialog.show( alignment: Alignment.bottomCenter, maskColor: Colors.black.withOpacity(0.5), + onDismiss: () { + _roomController.setDialogDismiss(false); + }, builder: (context) { return LiveRoomGuestListDialog( initialTab: isMaleSeat ? 1 : 0, // 0: 女嘉宾, 1: 男嘉宾 @@ -406,10 +410,13 @@ class _LiveRoomAnchorShowcaseState extends State { // 创建必要的 ValueNotifier final activeGift = ValueNotifier(null); final giftNum = ValueNotifier(1); - + _roomController.setDialogDismiss(true); SmartDialog.show( alignment: Alignment.bottomCenter, maskColor: Colors.black.withOpacity(0.5), + onDismiss: (){ + _roomController.setDialogDismiss(false); + }, builder: (context) { return Obx(() { // 获取礼物列表 diff --git a/lib/widget/live/live_room_notice_chat_panel.dart b/lib/widget/live/live_room_notice_chat_panel.dart index 8cc4d72..f5d7584 100644 --- a/lib/widget/live/live_room_notice_chat_panel.dart +++ b/lib/widget/live/live_room_notice_chat_panel.dart @@ -180,9 +180,13 @@ class _LiveRoomNoticeChatPanelState extends State { final cardNum = linkMicCard?.num ?? 0; // 如果显示"上麦20玫瑰"且玫瑰数量小于20,弹出充值弹框 if (cardNum == 0 && controller.roseCount.value < 20) { + controller.setDialogDismiss(true); SmartDialog.show( alignment: Alignment.bottomCenter, maskColor: Colors.black.withOpacity(0.5), + onDismiss: (){ + controller.setDialogDismiss(false); + }, builder: (_) => const LiveRechargePopup(), ); return; diff --git a/lib/widget/live/live_room_user_header.dart b/lib/widget/live/live_room_user_header.dart index bc325db..11dbc72 100644 --- a/lib/widget/live/live_room_user_header.dart +++ b/lib/widget/live/live_room_user_header.dart @@ -84,8 +84,12 @@ class LiveRoomUserHeader extends StatelessWidget { if (isHost) GestureDetector( onTap: () { + roomController.setDialogDismiss(true); SmartDialog.showAttach( targetContext: context, + onDismiss: (){ + roomController.setDialogDismiss(false); + }, builder: (context) { // 判断是否有嘉宾在连麦 final hasGuests =