import 'package:cached_network_image/cached_network_image.dart'; import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/controller/home/user_information_controller.dart'; import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:dating_touchme_app/generated/assets.dart'; import 'package:dating_touchme_app/model/home/marriage_data.dart'; import 'package:dating_touchme_app/pages/home/report_page.dart'; import 'package:dating_touchme_app/pages/home/timeline_item.dart'; import 'package:dating_touchme_app/pages/message/chat_page.dart'; import 'package:dating_touchme_app/pages/mine/edit_info_page.dart'; import 'package:easy_refresh/easy_refresh.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'; import 'package:get/get_core/src/get_main.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart'; class UserInformationPage extends StatelessWidget { final String miId; final String userId; const UserInformationPage({super.key, required this.miId, required this.userId}); @override Widget build(BuildContext context) { return GetX( init: UserInformationController(miId: miId, userId: userId), builder: (controller){ // 如果正在加载,显示加载中 if (controller.isLoading.value) { return Scaffold( appBar: AppBar( title: const Text('用户主页'), ), body: const Center( child: CircularProgressIndicator(), ), ); } // 如果有错误,显示错误信息 if (controller.errorMessage.value.isNotEmpty) { return Scaffold( appBar: AppBar( title: const Text('用户主页'), leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () => Get.back(), ), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( controller.errorMessage.value, style: const TextStyle(color: Colors.grey), ), const SizedBox(height: 16), ElevatedButton( onPressed: () { controller.getUserData(); }, child: const Text('重试'), ), ], ), ), ); } // 如果用户数据为空,显示提示 if (controller.userData.value.id == null || controller.userData.value.id!.isEmpty) { return Scaffold( appBar: AppBar( title: const Text('用户主页'), leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () => Get.back(), ), ), body: const Center( child: Text('用户信息不存在'), ), ); } return Scaffold( body: Stack( children: [ controller.userData.value.photoList!.isNotEmpty ? CachedNetworkImage( imageUrl: "${controller.userData.value.photoList![controller.nowSelect.value].photoUrl}?x-oss-process=image/format,webp", width: 375.w, height: 384.w, fit: BoxFit.cover, ) : CachedNetworkImage( imageUrl: "${controller.userData.value.profilePhoto}?x-oss-process=image/format,webp", width: 375.w, height: 384.w, fit: BoxFit.cover, ), Positioned( left: 120.w, top: miId != GlobalData().userData!.id ? 290.w : 310.w, width: 240.w, child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: [ ...controller.userData.value.photoList!.asMap().entries.map((entry){ return Container( margin: EdgeInsets.only(right: 7.w), child: InkWell( onTap: (){ controller.nowSelect.value = entry.key; }, child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(7.w)), child: Container( width: 40.w, height: 40.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(7.w)), border: controller.nowSelect.value == entry.key ? Border.all(width: 2.w, color: Colors.white) : null ), child: Center( child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(7.w)), child: CachedNetworkImage( imageUrl: "${entry.value.photoUrl}?x-oss-process=image/format,webp/resize,w_76", width: 38.w, height: 38.w, fit: BoxFit.cover, ), ), ), ), ), ), ); }), ], ), ), ), EasyRefresh( controller: controller.listRefreshController, header: const ClassicHeader( dragText: '下拉刷新', armedText: '释放刷新', readyText: '刷新中...', processingText: '刷新中...', processedText: '刷新完成', failedText: '刷新失败', noMoreText: '没有更多数据', showMessage: false ), footer: ClassicFooter( dragText: '上拉加载', armedText: '释放加载', readyText: '加载中...', processingText: '加载中...', processedText: '加载完成', failedText: '加载失败', noMoreText: '没有更多数据', showMessage: false ), // 下拉刷新 onRefresh: () async { print('推荐列表下拉刷新被触发'); controller.page.value = 1; controller.postList.clear(); await controller.getPostList(); controller.listRefreshController.finishRefresh(IndicatorResult.success); controller.listRefreshController.finishLoad(IndicatorResult.none); }, // 上拉加载更多 onLoad: () async { print('推荐列表上拉加载被触发, hasMore: '); controller.page.value += 1; await controller.getPostList(); }, child: DraggableScrollableSheet( initialChildSize: 0.57, // 初始露出高度(占屏幕比例) minChildSize: 0.57, // 最小(不想下滑回去就设成一样) maxChildSize: 1, builder: (context, scrollController) { return SingleChildScrollView( clipBehavior: Clip.none, controller: scrollController, child: Stack( clipBehavior: Clip.none, children: [ Container( width: 375.w, constraints: BoxConstraints( minHeight: 812.h, ), padding: EdgeInsets.only( top: 31.w, left: 15.w, right: 24.w ), decoration: BoxDecoration( borderRadius: BorderRadius.vertical( top: Radius.circular(23.w) ), color: Colors.white ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Text( controller.userData.value.nickName ?? "", style: TextStyle( fontSize: 22.w, color: const Color.fromRGBO(51, 51, 51, 1), fontWeight: FontWeight.w600 ), ), SizedBox(width: 13.w,), if(controller.userData.value?.genderCode == 1) Container( width: 33.w, height: 13.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(13.w)), color: const Color.fromRGBO(255, 237, 255, 1) ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesFemale, width: 8.w, height: 8.w, ), SizedBox(width: 2.w,), Text( "${ controller.calculateAge( (controller.userData.value.birthDate != null && controller.userData.value.birthDate!.isNotEmpty) ? (controller.userData.value.birthDate ?? "") : controller.userData.value.birthYear != null && controller.userData.value.birthYear!.isNotEmpty ? "${controller.userData.value.birthYear}-01-01" : "") }", style: TextStyle( fontSize: 11.w, color: const Color.fromRGBO(255, 66, 236, 1) ), ) ], ), ), SizedBox(width: 3.w,), Container( width: 33.w, height: 13.w, margin: EdgeInsets.only(right: 2.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(13.w)), color: const Color.fromRGBO(234, 255, 219, 1) ), child: Center( child: Text( "在线", style: TextStyle( fontSize: 11.w, color: const Color.fromRGBO(38, 199, 124, 1) ), ), ), ), SizedBox(width: 4.w,), if (controller.userData.value.identityCard != "" && controller.userData.value.identityCard != null) Container( width: 43.w, height: 13.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(13.w)), color: const Color.fromRGBO(246, 237, 255, 1) ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesRealName, width: 8.w, height: 7.w, ), SizedBox(width: 2.w,), Text( "实名", style: TextStyle( fontSize: 11.w, color: const Color.fromRGBO(160, 92, 255, 1) ), ) ], ), ), SizedBox(width: 4.w,), if(controller.userData.value?.genderCode == 0) Container( width: 33.w, height: 13.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(13.w)), color: const Color.fromRGBO(237, 245, 255, 1) ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesMale, width: 8.w, height: 8.w, ), SizedBox(width: 2.w,), Text( "${ controller.calculateAge( (controller.userData.value.birthDate != null && controller.userData.value.birthDate!.isNotEmpty) ? (controller.userData.value.birthDate ?? "") : controller.userData.value.birthYear != null && controller.userData.value.birthYear!.isNotEmpty ? "${controller.userData.value.birthYear}-01-01" : "") }", style: TextStyle( fontSize: 11.w, color: const Color.fromRGBO(120, 140, 255, 1) ), ) ], ), ), ], ), // 语音介绍功能暂时隐藏(为了通过苹果审核) // Container( // width: 63.w, // height: 27.w, // decoration: BoxDecoration( // borderRadius: BorderRadius.all(Radius.circular(27.w)), // color: const Color.fromRGBO(117, 98, 249, .1) // ), // child: Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Image.asset( // Assets.imagesPlayer, // width: 15.w, // height: 15.w, // ), // SizedBox(width: 4.w,), // Image.asset( // Assets.imagesVoice, // width: 15.w, // height: 13.w, // ), // SizedBox(width: 4.w,), // Text( // "6'", // style: TextStyle( // fontSize: 11.w, // color: const Color.fromRGBO(117, 98, 249, 1) // ), // ) // ], // ), // ) ], ), SizedBox(height: 8.w,), Text( (miId == GlobalData().userData!.id && GlobalData().userData!.auditDescribeInfo != null && GlobalData().userData!.auditDescribeInfo != "") ? (GlobalData().userData!.auditDescribeInfo ?? "") : (controller.userData.value.describeInfo ?? "好的生活方式,是和一群志同道合的人一起奔跑。"), style: TextStyle( fontSize: 14.w, color: const Color.fromRGBO(144, 144, 144, 1) ), ), // SizedBox(height: 11.w,), // Wrap( // spacing: 12.w, // runSpacing: 12.w, // children: [ // ...controller.tagList.map((e){ // return TagItem(label: e); // }), // ], // ), SizedBox(height: 16.w,), if ((controller.userData.value.provinceName?.isNotEmpty ?? false)) Text( "IP属地:${controller.userData.value.provinceName}", style: TextStyle( fontSize: 12.w, color: const Color.fromRGBO(144, 144, 144, 1) ), ), Text( "快乐星球ID:${userId}", style: TextStyle( fontSize: 12.w, color: const Color.fromRGBO(144, 144, 144, 1) ), ), Container( height: 1, color: const Color.fromRGBO(0, 0, 0, .3), margin: EdgeInsets.symmetric(vertical: 15.w), ), Obx( () { return Column( children: [ TDTabBar( tabs: [ TDTab(text: '我的动态'), TDTab(text: '人格类型'), ], physics: const NeverScrollableScrollPhysics(), controller: controller.tabController, showIndicator: true, isScrollable: true, onTap: (int i) async { controller.changeTab(i); }, ), SizedBox(height: 10.w,), if(controller.tab.value == 0) ...[ ...controller.postList.map((e){ return TimelineItem(item: e); }), if(controller.postList.isEmpty) Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( Assets.imagesNoMoreTimeline, width: 90.w, height: 112.w, ), SizedBox(height: 5.w,), Text( "暂无动态", style: TextStyle( fontSize: 14.w, color: const Color.fromRGBO(186, 186, 186, 1) ), ) ], ), ) ], if(controller.tab.value == 1) ...[ Stack( clipBehavior: Clip.none, children: [ Container(), Positioned( left: -15.w, child: Image.asset( Assets.imagesResultsBg, width: 375.w, ), ), Positioned( left: 0.w, top: 32.w, child: SizedBox( width: 95.w, child: Text( "你的人格类型鉴定结果", style: TextStyle( fontSize: 16.w, color: Colors.white ), ), ), ), Positioned( right: -9.w, top: 35.w, child: Text( "${controller.resultTitle.value != "" ? controller.resultTitle.value : "????"}", style: TextStyle( fontSize: 24.w, color: const Color.fromRGBO(117, 98, 249, 1), fontWeight: FontWeight.w700 ), ), ), Positioned( left: -4.w, top: 134.w, child: Stack( alignment: Alignment.center, children: [ Image.asset( Assets.imagesElementBorder, width: 91.w, height: 52.w, ), Text( "${controller.resultTitle.value != "" ? controller.resultData.value["优势"][0] : "???"}", style: TextStyle( fontSize: 14.w, color: Colors.white ), ) ], ), ), Positioned( left: -4.w, top: 259.w, child: Stack( alignment: Alignment.center, children: [ Image.asset( Assets.imagesElementBorder, width: 91.w, height: 52.w, ), Text( "${controller.resultTitle.value != "" ? controller.resultData.value["优势"][1] : "???"}", style: TextStyle( fontSize: 14.w, color: Colors.white ), ) ], ), ), Positioned( right: -13.w, top: 134.w, child: Stack( alignment: Alignment.center, children: [ Image.asset( Assets.imagesElementBorder, width: 91.w, height: 52.w, ), Text( "${controller.resultTitle.value != "" ? controller.resultData.value["优势"][2] : "???"}", style: TextStyle( fontSize: 14.w, color: Colors.white ), ) ], ), ), Positioned( right: -13.w, top: 251.w, child: Stack( alignment: Alignment.center, children: [ Image.asset( Assets.imagesElementBorder, width: 91.w, height: 52.w, ), Text( "${controller.resultTitle.value != "" ? controller.resultData.value["优势"][3] : "???"}", style: TextStyle( fontSize: 14.w, color: Colors.white ), ) ], ), ), ], ) ], ], ); } ), ], ), ), Positioned( left: 15.w, top: -60.w, child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(90.w)), child: Container( width: 90.w, height: 90.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(90.w)), border: Border.all(width: 3.w, color: Colors.white) ), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(84.w)), child: CachedNetworkImage( imageUrl: "${controller.userData.value.profilePhoto}?x-oss-process=image/format,webp", width: 84.w, height: 84.w, fit: BoxFit.cover, ), ), ), ), ) ], ), ); }, ), ), Positioned( left: 0, top: MediaQuery.of(context).padding.top + 23, child: Container( width: 375.w, padding: EdgeInsets.symmetric(horizontal: 19.w), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ InkWell( onTap: (){ Get.back(); }, child: Container( width: 31.w, height: 31.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(31.w)), color: const Color.fromRGBO(51, 51, 51, .5) ), child: Center( child: Icon( Icons.keyboard_arrow_left, size: 23.w, color: Colors.white, ), ), ), ), if(miId != GlobalData().userData!.id) PopupMenuButton( tooltip: "", padding: EdgeInsets.zero, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), color: Colors.white, elevation: 8, offset: Offset(0, 32.w), // 相对按钮下移一点 itemBuilder: (context) => [ const PopupMenuItem(value: 'report', child: Text('举报')), const PopupMenuItem(value: 'block', child: Text('拉黑')), ], onSelected: (v) { if (v == 'report') { print("举报"); Get.to(() => ReportPage(id: userId,)); } else if (v == 'block') { print("拉黑"); } }, child: Container( width: 31.w, height: 31.w, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(62.w)), color: const Color.fromRGBO(51, 51, 51, .5) ), child: Center( child: Icon( Icons.keyboard_control, size: 23.w, color: Colors.white, ), ), ), // 你的小圆按钮 ), if(miId == GlobalData().userData!.id) Container( height: 31.w, padding: EdgeInsets.symmetric(horizontal: 10.w), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(62.w)), color: const Color.fromRGBO(51, 51, 51, .5) ), child: Row( children: [ Image.asset( Assets.imagesEdit, width: 10.w, height: 10.w, color: Colors.white, ), SizedBox(width: 4.w,), Text( "修改资料", style: TextStyle( fontSize: 12.w, color: Colors.white, fontWeight: FontWeight.w500 ), ), ], ), ).onTap((){ Get.to(() => EditInfoPage())?.then((e){ controller.getUserData(); }); }) ], ), ), ), ], ), bottomNavigationBar: miId != GlobalData().userData!.id ? SafeArea( child: SizedBox( height: 48.h, child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ TDButton( text: '发消息', width: 350.w, size: TDButtonSize.medium, type: TDButtonType.fill, shape: TDButtonShape.round, textStyle: TextStyle(fontSize: 14, color: Colors.white), iconWidget: Image.asset( Assets.imagesChatBtn, width: 17.w, height: 15.h ), style: TDButtonStyle( textColor: Colors.white, backgroundColor: Color(0xFF333333), ), activeStyle: TDButtonStyle( textColor: Colors.white, backgroundColor: Color(0xC3333333), ), onTap: () async { try { final userInfo = controller.userData.value; print('📨 [UserInformationPage] 点击发消息'); print(' - 页面传入的miId: $miId'); print(' - 接口返回的userInfo.miId: ${userInfo.miId}'); print(' - 接口返回的userInfo.id: ${userInfo.id}'); print(' - 接口返回的userInfo.userId: ${userInfo.userId}'); print(' - 接口返回的userInfo.accountId: ${userInfo.accountId}'); // IM系统需要使用userId或accountId,而不是miId // 优先使用userId(这是IM系统的用户ID),如果没有则使用accountId,最后才使用miId String? targetUserId = userInfo.miUserId; if (targetUserId == null || targetUserId.isEmpty) { print('❌ [UserInformationPage] 无法获取用户ID,无法跳转'); SmartDialog.showToast('用户ID不存在,无法发送消息'); return; } print('✅ [UserInformationPage] 使用userId: $targetUserId (用于IM聊天)'); // 使用工厂方法将 UserInfoData 转换为 MarriageData final marriageData = MarriageData.fromUserInfoData(userInfo); print('✅ [UserInformationPage] 准备跳转到聊天页面,userId: $targetUserId'); await Get.to(() => ChatPage( userId: targetUserId, userData: marriageData, )); } catch (e) { print('❌ [UserInformationPage] 跳转聊天页面失败: $e'); SmartDialog.showToast('跳转失败,请重试'); } }, ), // const SizedBox(width: 10), // TDButton( // text: '关注', // width: 90, // size: TDButtonSize.medium, // type: TDButtonType.fill, // shape: TDButtonShape.round, // textStyle: TextStyle(fontSize: 14, color: Colors.white), // style: TDButtonStyle( // textColor: Colors.white, // backgroundColor: Color(0xFF7562F9), // ), // activeStyle: TDButtonStyle( // textColor: Colors.white, // backgroundColor: Color(0xC37562F9), // ), // onTap: (){ // // controller.tabIndex.value = 1; // }, // ) ], ), ) ) : null, ); }, ); } } class TagItem extends StatelessWidget { final String label; const TagItem({super.key, required this.label}); @override Widget build(BuildContext context) { return Container( padding: EdgeInsets.symmetric( vertical: 5.w, horizontal: 10.w ), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(13.w)), color: const Color.fromRGBO(245, 247, 255, 1) ), child: Text( label, style: TextStyle( fontSize: 13.w, color: const Color.fromRGBO(51, 51, 51, 1) ), ), ); } }