import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:aslan/app_localizations.dart'; import 'package:aslan/chatvibe_ui/components/text/at_text.dart'; import 'package:aslan/chatvibe_core/constants/at_global_config.dart'; import 'package:aslan/chatvibe_domain/models/res/login_res.dart'; import 'package:aslan/chatvibe_managers/user_profile_manager.dart'; import 'package:marquee/marquee.dart'; import 'package:provider/provider.dart'; import 'package:aslan/chatvibe_ui/components/at_compontent.dart'; import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart'; import 'package:aslan/chatvibe_data/sources/local/user_manager.dart'; import 'package:aslan/chatvibe_data/sources/repositories/room_repository_imp.dart'; import 'package:aslan/chatvibe_domain/models/res/user_count_guard_res.dart'; import 'package:aslan/chatvibe_features/index/main_route.dart'; ///CP关系 class RelationShipPage extends StatefulWidget { String tageId = ""; bool isFromMe = false; RelationShipPage(this.isFromMe, this.tageId); @override _RelationShipPageState createState() => _RelationShipPageState(); } class _RelationShipPageState extends State { List? userCountGuardResList; @override void initState() { super.initState(); ChatRoomRepository().userCountGuard(widget.tageId).then((result) { userCountGuardResList = result; setState(() {}); }); } @override Widget build(BuildContext context) { return SingleChildScrollView( child: Consumer( builder: (context, ref, child) { return Column( mainAxisSize: MainAxisSize.min, children: [ Row( children: [ SizedBox(width: 12.w), text( ATAppLocalizations.of(context)!.couple2, fontSize: 14.sp, fontWeight: FontWeight.bold, textColor: Colors.black, ), Spacer(), widget.tageId == UserManager().getCurrentUser()?.userProfile?.id ? GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { ATNavigatorUtils.push(context, MainRoute.cpList); }, child: Row( children: [ text( ATAppLocalizations.of(context)!.cpList, fontSize: 12.sp, fontWeight: FontWeight.bold, textColor: Colors.black, ), Icon( Icons.chevron_right, color: Colors.black, size: 18.w, ), ], ), ) : Container(), SizedBox(width: 12.w), ], ), SizedBox(height: 10.w), _buildCpList(ref), // SizedBox(height: 10.w), // Row( // children: [ // SizedBox(width: 12.w), // text( // ATAppLocalizations.of(context)!.superFans, // fontSize: 14.sp, // fontWeight: FontWeight.bold, // textColor: Colors.white, // ), // ], // ), // SizedBox(height: 10.w), // Row( // children: [ // Expanded( // child: Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // userCountGuardResList != null && // userCountGuardResList!.isNotEmpty // ? GestureDetector( // child: Stack( // alignment: Alignment.center, // children: [ // Image.asset( // "atu_images/room/at_icon_user_count_guard1_user.png", // width: 100.w, // height: 100.w, // ), // Positioned( // bottom: 9.w, // child: head( // url: // userCountGuardResList![0] // .userProfile! // .userAvatar ?? // "", // width: 70.w, // ), // ), // ], // ), // onTap: () { // ATNavigatorUtils.push( // context, // replace: !widget.isFromMe, // "${MainRoute.person}?isMe=${UserManager().getCurrentUser()?.userProfile?.id == userCountGuardResList![0].userProfile?.id}&tageId=${userCountGuardResList![0].userProfile?.id}", // ); // }, // ) // : Image.asset( // "atu_images/room/at_icon_user_count_guard1.png", // width: 100.w, // height: 100.w, // ), // ], // ), // ), // Expanded( // child: Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // userCountGuardResList != null && // userCountGuardResList!.length > 1 // ? GestureDetector( // onTap: () { // ATNavigatorUtils.push( // context, // replace: !widget.isFromMe, // "${MainRoute.person}?isMe=${UserManager().getCurrentUser()?.userProfile?.id == userCountGuardResList![1].userProfile?.id}&tageId=${userCountGuardResList![1].userProfile?.id}", // ); // }, // child: Stack( // alignment: Alignment.center, // children: [ // Image.asset( // "atu_images/room/at_icon_user_count_guard2_user.png", // width: 100.w, // height: 100.w, // ), // Positioned( // bottom: 9.w, // child: head( // url: // userCountGuardResList![1] // .userProfile! // .userAvatar ?? // "", // width: 70.w, // ), // ), // ], // ), // ) // : Image.asset( // "atu_images/room/at_icon_user_count_guard2.png", // width: 100.w, // height: 100.w, // ), // ], // ), // ), // Expanded( // child: Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // userCountGuardResList != null && // userCountGuardResList!.length > 2 // ? GestureDetector( // onTap: () { // ATNavigatorUtils.push( // context, // replace: !widget.isFromMe, // "${MainRoute.person}?isMe=${UserManager().getCurrentUser()?.userProfile?.id == userCountGuardResList![2].userProfile?.id}&tageId=${userCountGuardResList![2].userProfile?.id}", // ); // }, // child: Stack( // alignment: Alignment.center, // children: [ // Image.asset( // "atu_images/room/at_icon_user_count_guard3_user.png", // width: 100.w, // height: 100.w, // ), // Positioned( // bottom: 9.w, // child: head( // url: // userCountGuardResList![2] // .userProfile! // .userAvatar ?? // "", // width: 70.w, // ), // ), // ], // ), // ) // : Image.asset( // "atu_images/room/at_icon_user_count_guard3.png", // width: 100.w, // height: 100.w, // ), // ], // ), // ), // ], // ), ], ); }, ), ); } Widget _buildCpList(ChatVibeUserProfileManager ref) { List cpList = []; if (widget.tageId == UserManager().getCurrentUser()?.userProfile?.id) { //自己 if (widget.isFromMe) { cpList = UserManager().getCurrentUser()?.userProfile?.cpList ?? []; } else { cpList = ref.userProfile?.cpList ?? []; } } else { cpList = ref.userProfile?.cpList ?? []; } if (widget.tageId == UserManager().getCurrentUser()?.userProfile?.id) { return cpList.isNotEmpty ? SizedBox( height: 188.w, child: CarouselSlider( options: CarouselOptions( height: 188.w, autoPlay: (cpList.length ?? 0) > 1, // 启用自动播放 enlargeCenterPage: false, // 居中放大当前页面 aspectRatio: 1 / 1, // 宽高比 enableInfiniteScroll: true, // 启用无限循环 autoPlayAnimationDuration: Duration(milliseconds: 800), // 自动播放动画时长 viewportFraction: 1, // 视口分数 onPageChanged: (index, reason) { setState(() {}); }, ), items: cpList.map((item) { return GestureDetector( child: _buildCpItem(item), onTap: () {}, ); }).toList(), ), ) : GestureDetector( child: _buildEmptyCpItem(true), onTap: () { ATNavigatorUtils.push(context, MainRoute.cpList); }, ); } else { return cpList.isNotEmpty ? SizedBox( height: 188.w, child: CarouselSlider( options: CarouselOptions( height: 188.w, autoPlay: cpList.length > 1, // 启用自动播放 enlargeCenterPage: false, // 居中放大当前页面 aspectRatio: 1 / 1, // 宽高比 enableInfiniteScroll: true, // 启用无限循环 autoPlayAnimationDuration: Duration(milliseconds: 800), // 自动播放动画时长 viewportFraction: 1, // 视口分数 onPageChanged: (index, reason) { setState(() {}); }, ), items: cpList.map((item) { return GestureDetector( child: _buildCpItem(item), onTap: () {}, ); }).toList(), ), ) : _buildEmptyCpItem(false); } } Widget _buildCpItem(CPRes item) { return Stack( alignment: AlignmentDirectional.center, children: [ Container( width: ScreenUtil().screenWidth, margin: EdgeInsets.symmetric(horizontal: 10.w), child: Stack( children: [ Image.asset( "atu_images/person/at_icon_no_cp_item_bg2_lv_${(item.profileCardLevel ?? 0) <= 3 ? (item.profileCardLevel ?? 1) : 3}.png", width: ScreenUtil().screenWidth, fit: BoxFit.fill, ), Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox(height: 30.w), Stack( alignment: AlignmentGeometry.bottomCenter, children: [ Transform.scale( scale: 1.2, child: netImage( url: item.selfRing?.sourceUrl ?? "", width: 65.w, ), ), Transform.translate( offset: Offset(0, 15.w), child: Container( width: 70.w, height: 32.w, alignment: AlignmentDirectional.center, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( "atu_images/person/at_icon_user_cp_level_value_bg.png", ), fit: BoxFit.fill, ), ), child: Directionality( textDirection: TextDirection.ltr, child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( margin: EdgeInsets.only(top: 5.w, left: 15.w), child: text( "LV.${item.cpLevel ?? 1}", fontWeight: FontWeight.w600, fontSize: 12.sp, textColor: Colors.white, ), ), ], ), ), ), ), ], ), SizedBox(height: 18.w), Container( alignment: AlignmentDirectional.bottomCenter, child: text( ATAppLocalizations.of( context, )!.timeSpentTogether(item.days ?? ""), fontWeight: FontWeight.w600, fontSize: 12.sp, textColor: Color(0xFFFF79A1), ), ), Container( alignment: AlignmentDirectional.bottomCenter, child: text( ATAppLocalizations.of( context, )!.firstDay(item.firstDay ?? ""), fontWeight: FontWeight.w600, fontSize: 11.sp, textColor: Colors.white, ), ), ], ), ], ), ), PositionedDirectional( top: 50.w, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Column( children: [ GestureDetector( child: SizedBox( height: 50.w, child: Stack( alignment: AlignmentDirectional.center, children: [ netImage( url: item.meUserAvatar ?? "", width: 48.w, shape: BoxShape.circle, defaultImg: "atu_images/general/at_icon_avar_defalt.png", ), Image.asset( "atu_images/person/at_icon_cp_head_ring.png", ), ], ), ), onTap: () { ATNavigatorUtils.push( context, replace: !widget.isFromMe, "${MainRoute.person}?isMe=${UserManager().getCurrentUser()?.userProfile?.id == item.meUserId}&tageId=${item.meUserId}", ); }, ), Container( alignment: Alignment.center, width: 80.w, height: 15.w, child: (item.meUserNickname?.length ?? 0) > 8 ? Marquee( text: item.meUserNickname ?? "", style: TextStyle( fontSize: 10.sp, color: Colors.white, fontWeight: FontWeight.w600, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 20.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration(seconds: 1), accelerationCurve: Curves.linear, decelerationDuration: Duration(milliseconds: 500), decelerationCurve: Curves.easeOut, ) : Text( item.meUserNickname ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 10.sp, color: Colors.white, fontWeight: FontWeight.w600, decoration: TextDecoration.none, ), ), ), ], ), SizedBox(width: 120.w), Column( children: [ GestureDetector( child: SizedBox( height: 50.w, child: Stack( alignment: AlignmentDirectional.center, children: [ netImage( url: item.cpUserAvatar ?? "", width: 48.w, shape: BoxShape.circle, defaultImg: "atu_images/general/at_icon_avar_defalt.png", ), Image.asset( "atu_images/person/at_icon_cp_head_ring.png", ), ], ), ), onTap: () { ATNavigatorUtils.push( context, replace: !widget.isFromMe, "${MainRoute.person}?isMe=${UserManager().getCurrentUser()?.userProfile?.id == item.cpUserId}&tageId=${item.cpUserId}", ); }, ), Container( alignment: Alignment.center, width: 80.w, height: 15.w, child: (item.cpUserNickname?.length ?? 0) > 8 ? Marquee( text: item.cpUserNickname ?? "", style: TextStyle( fontSize: 10.sp, color: Colors.white, fontWeight: FontWeight.w600, decoration: TextDecoration.none, ), scrollAxis: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.start, blankSpace: 20.0, velocity: 40.0, pauseAfterRound: Duration(seconds: 1), accelerationDuration: Duration(seconds: 1), accelerationCurve: Curves.linear, decelerationDuration: Duration(milliseconds: 500), decelerationCurve: Curves.easeOut, ) : Text( item.cpUserNickname ?? "", maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 10.sp, color: Colors.white, fontWeight: FontWeight.w600, decoration: TextDecoration.none, ), ), ), ], ), ], ), ), ], ); } String _cpVaFormat(num cpValue) { int value = cpValue.toInt(); if (value > 99999) { return "${(value / 1000).toStringAsFixed(0)}k"; } return "$value"; } _buildEmptyCpItem(bool canAdd) { return Container( width: ScreenUtil().screenWidth, margin: EdgeInsets.symmetric(horizontal: 6.w), height: 200.w, decoration: BoxDecoration( image: DecorationImage( image: AssetImage( canAdd ? "atu_images/person/at_icon_no_cp_item_bg.png" : "atu_images/person/at_icon_no_cp_item_bg4.png", ), fit: BoxFit.fill, ), ), child: Container( margin: EdgeInsets.only(bottom: 48.w, left: 12.w), alignment: AlignmentDirectional.bottomCenter, child: text( ATAppLocalizations.of(context)!.noMatchedCP, fontWeight: FontWeight.w600, fontSize: 10.sp, textColor: Colors.white, ), ), ); } }