You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
8.5 KiB
234 lines
8.5 KiB
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/overlay_controller.dart';
|
|
import 'package:dating_touchme_app/generated/assets.dart';
|
|
import 'package:dating_touchme_app/model/discover/rtc_channel_model.dart';
|
|
import 'package:dating_touchme_app/pages/discover/live_room_page.dart';
|
|
import 'package:dating_touchme_app/rtc/rtc_manager.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
/// 直播项组件
|
|
class LiveItemWidget extends StatefulWidget {
|
|
final dynamic item;
|
|
final String? channelId;
|
|
final RtcChannelModel? channel;
|
|
const LiveItemWidget({
|
|
super.key,
|
|
this.item,
|
|
this.channelId,
|
|
this.channel,
|
|
});
|
|
|
|
@override
|
|
State<LiveItemWidget> createState() => _LiveItemWidgetState();
|
|
}
|
|
|
|
class _LiveItemWidgetState extends State<LiveItemWidget> {
|
|
late final RoomController roomController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if (Get.isRegistered<RoomController>()) {
|
|
roomController = Get.find<RoomController>();
|
|
} else {
|
|
roomController = Get.put(RoomController());
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: () async {
|
|
// 获取目标 channelId
|
|
String? targetChannelId;
|
|
if (widget.channelId != null && widget.channelId!.isNotEmpty) {
|
|
targetChannelId = widget.channelId!;
|
|
} else if (widget.item is Map && widget.item['channelId'] != null) {
|
|
targetChannelId = widget.item['channelId'].toString();
|
|
}
|
|
|
|
if (targetChannelId == null || targetChannelId.isEmpty) {
|
|
return;
|
|
}
|
|
|
|
// 获取当前直播间的 channelId
|
|
final currentChannelId = RTCManager.instance.currentChannelId;
|
|
|
|
// 如果 channelId 与当前直播间一致,直接进入直播间(逻辑与点击小窗口一致)
|
|
if (currentChannelId != null &&
|
|
currentChannelId.isNotEmpty &&
|
|
currentChannelId == targetChannelId) {
|
|
// 隐藏小窗口(如果显示的话)
|
|
if (Get.isRegistered<OverlayController>()) {
|
|
final overlayController = Get.find<OverlayController>();
|
|
overlayController.hide();
|
|
}
|
|
// 直接跳转到直播间
|
|
Get.to(() => const LiveRoomPage(id: 0));
|
|
} else {
|
|
// 如果不一致,先退出当前直播间,再加入新的直播间
|
|
if (currentChannelId != null && currentChannelId.isNotEmpty) {
|
|
await roomController.leaveChannel();
|
|
}
|
|
await roomController.joinChannel(targetChannelId);
|
|
}
|
|
},
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(10.w)),
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
width: 171.w,
|
|
height: 171.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(10.w)),
|
|
),
|
|
child: CachedNetworkImage(
|
|
imageUrl: "${ widget.channel!.channelPic}?x-oss-process=image/format,webp/resize,w_240",
|
|
width: 171.w,
|
|
height: 171.w,
|
|
fit: BoxFit.cover,
|
|
placeholder: (context, url) => Container(
|
|
color: Colors.white38,
|
|
child: Center(
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 1.w,
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
),
|
|
errorWidget: (context, url, error) =>
|
|
Image.asset(
|
|
Assets.imagesUserAvatar,
|
|
width: 171.w,
|
|
height: 171.w,
|
|
fit: BoxFit.cover,
|
|
),
|
|
)
|
|
),
|
|
// Positioned(
|
|
// top: 0,
|
|
// left: 0,
|
|
// child: Stack(
|
|
// children: [
|
|
// Image.asset(
|
|
// Assets.imagesSubscript,
|
|
// width: 56.w,
|
|
// height: 16.w,
|
|
// ),
|
|
// SizedBox(
|
|
// height: 16.w,
|
|
// child: Row(
|
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
// children: [
|
|
// SizedBox(width: 5.w),
|
|
// Image.asset(
|
|
// Assets.imagesLocationIcon,
|
|
// width: 6.w,
|
|
// height: 7.w,
|
|
// ),
|
|
// SizedBox(width: 3.w),
|
|
// Text(
|
|
// "49.9km",
|
|
// style: TextStyle(
|
|
// fontSize: 8.w,
|
|
// color: Colors.white,
|
|
// fontWeight: FontWeight.w500,
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
if (widget.item != null && widget.item is Map && widget.item["isNew"] == true)
|
|
Positioned(
|
|
top: 9.w,
|
|
right: 8.w,
|
|
child: Container(
|
|
width: 39.w,
|
|
height: 13.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(13.w)),
|
|
color: const Color.fromRGBO(0, 0, 0, .3),
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: 5.w,
|
|
height: 5.w,
|
|
margin: EdgeInsets.only(right: 3.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(5.w)),
|
|
color: const Color.fromRGBO(255, 209, 43, 1),
|
|
),
|
|
),
|
|
Text(
|
|
"等待",
|
|
style: TextStyle(
|
|
fontSize: 8.w,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
left: 9.w,
|
|
bottom: 6.w,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
widget.channel?.age != 0 && widget.channel?.age != null ? "${widget.channel?.channelName} | ${widget.channel?.age}岁" : widget.channel?.channelName ?? '',
|
|
style: TextStyle(
|
|
fontSize: 11.w,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
SizedBox(width: 5.w),
|
|
if (widget.item != null && widget.item is Map && widget.item["isNew"] == true)
|
|
Container(
|
|
width: 32.w,
|
|
height: 10.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(10.w),
|
|
),
|
|
color: const Color.fromRGBO(255, 206, 28, .8),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"新人",
|
|
style: TextStyle(
|
|
fontSize: 8.w,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|