import 'package:cached_network_image/cached_network_image.dart'; import 'package:dating_touchme_app/controller/discover/room_controller.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/model/discover/rtc_channel_model.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 createState() => _LiveItemWidgetState(); } class _LiveItemWidgetState extends State { late final RoomController roomController; @override void initState() { super.initState(); if (Get.isRegistered()) { roomController = Get.find(); } else { roomController = Get.put(RoomController()); } } @override Widget build(BuildContext context) { return InkWell( onTap: () async { if (widget.channelId != null && widget.channelId!.isNotEmpty) { await roomController.joinChannel(widget.channelId!); } else if (widget.item is Map && widget.item['channelId'] != null) { await roomController.joinChannel(widget.item['channelId'].toString()); } }, 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: [ SizedBox( width: 64.w, child: Text( widget.channel != null && widget.channel!.channelName.isNotEmpty ? widget.channel!.channelName : "一直一直在等你一直一直在等你......", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 8.w, color: Colors.white, fontWeight: FontWeight.w500, ), ), ), SizedBox(height: 2.w), Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "福州 | 28岁", 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, ), ), ), ), ], ), ], ), ), ], ), ), ); } }