import 'package:dating_touchme_app/controller/discover/room_controller.dart'; import 'package:dating_touchme_app/controller/overlay_controller.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/widget/live/disconnect_mic_dialog.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'; /// 直播间顶部用户信息与操作区域 class LiveRoomUserHeader extends StatelessWidget { const LiveRoomUserHeader({ super.key, required this.userName, required this.popularityText, this.avatarAsset = Assets.imagesUserAvatar, this.fireIconAsset = Assets.imagesFireIcon, this.closeIconAsset = Assets.imagesCloseArrow, this.onFollowTap, this.onCloseTap, }); final String userName; final String popularityText; final String avatarAsset; final String fireIconAsset; final String closeIconAsset; final VoidCallback? onFollowTap; final VoidCallback? onCloseTap; @override Widget build(BuildContext context) { // 获取 RoomController 判断当前用户角色 final roomController = Get.find(); final overlayController = Get.find(); final isHost = roomController.currentRole == CurrentRole.broadcaster; return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( height: 40.w, padding: EdgeInsets.symmetric(horizontal: 3.w), margin: EdgeInsets.only(left: 10.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(40.w)), color: const Color.fromRGBO(0, 0, 0, .25), ), child: Row( children: [ // 支持网络图片和本地资源 ClipOval( child: Image.network( avatarAsset, width: 34.w, height: 34.w, fit: BoxFit.cover, errorBuilder: (context, error, stackTrace) { return Image.asset( Assets.imagesUserAvatar, width: 34.w, height: 34.w, ); }, ), ), SizedBox(width: 7.w), Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( userName, style: TextStyle(fontSize: 13.w, color: Colors.white), ), ], ), ], ), ), Row( children: [ // 只有主持人才显示直播设置按钮 if (isHost) GestureDetector( onTap: () { SmartDialog.showAttach( targetContext: context, builder: (context) { // 判断是否有嘉宾在连麦 final hasGuests = roomController.rtcChannelDetail.value?.maleInfo != null || roomController.rtcChannelDetail.value?.femaleInfo != null; return Container( width: 100.w, margin: EdgeInsets.only(left: 160.w), decoration: BoxDecoration( color: Colors.black.withAlpha(80), borderRadius: BorderRadius.all(Radius.circular(10.w)), ), child: Column( children: [ SizedBox(height: 15.w), // 只有当有嘉宾在连麦时才显示"解除连麦"选项 if (hasGuests) GestureDetector( onTap: () { // 关闭设置弹窗 SmartDialog.dismiss(); // 弹出解除连麦对话框 SmartDialog.show( builder: (context) { return DisconnectMicDialog(); }, ); }, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesMicOff, width: 15.w, ), SizedBox(width: 5.w), Text( '解除连麦', style: TextStyle( color: Colors.white, fontSize: 13.sp, ), ), ], ), ), if (hasGuests) SizedBox(height: 15.w), GestureDetector( onTap: () async { SmartDialog.dismiss(); Get.back(); overlayController.hide(); await roomController.leaveChannel(); // 隐藏 overlay }, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesExitRoom, width: 15.w, ), SizedBox(width: 5.w), Text( '结束直播', style: TextStyle( color: Colors.white, fontSize: 13.sp, ), ), ], ), ), SizedBox(height: 15.w), ], ), ); }, ); }, child: Container( height: 30.w, padding: EdgeInsets.symmetric(horizontal: 5.w), margin: EdgeInsets.only(right: 15.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(30.w)), color: const Color.fromRGBO(0, 0, 0, .3), border: Border.all( color: const Color.fromRGBO(255, 255, 255, .3), width: 1.w, ), ), child: Row( children: [ Icon( Icons.settings_rounded, color: Colors.white, size: 18.w, ), Text( '直播设置', style: TextStyle(color: Colors.white, fontSize: 13.sp), ), Icon( Icons.keyboard_arrow_down_sharp, color: Colors.white, size: 18.w, ), ], ), ), ), GestureDetector( onTap: onCloseTap, child: Container( width: 30.w, height: 30.w, margin: EdgeInsets.only(right: 15.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(30.w)), color: const Color.fromRGBO(0, 0, 0, .3), ), child: Center( child: Image.asset(closeIconAsset, width: 14.w, height: 14.w), ), ), ), ], ), ], ); } }