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/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/message/chat_page.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){ return controller.userData.value.id != null ? 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, ), SingleChildScrollView( child: Container( padding: EdgeInsets.only(top: 361.w), child: Container( height: 812.h - 361.w, width: 375.w, 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.myUserData.value?.genderCode == 0) 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.userData.value.age}", 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.myUserData.value?.genderCode == 1) 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.userData.value.age}", 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( "父母催婚找个结婚的", 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) ), ), ], ), ), ), ), 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, ), ), ), ), 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()); } 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, ), ), ), // 你的小圆按钮 ), ], ), ), ), Positioned( left: 15.w, top: 310.w, width: 345.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: CachedNetworkImage( imageUrl: "${entry.value.photoUrl}?x-oss-process=image/format,webp/resize,w_76", width: 38.w, height: 38.w, fit: BoxFit.cover, ), ), ), ), ), ); }), ], ), ), ), ], ), bottomNavigationBar: miId != GlobalData().userData!.id ? SafeArea( child: SizedBox( height: 48.h, child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ TDButton( text: '发消息', width: 240.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.userId?.isNotEmpty == true ? userInfo.userId : (userInfo.accountId?.isNotEmpty == true ? userInfo.accountId : (userInfo.miId?.isNotEmpty == true ? userInfo.miId : (userInfo.id?.isNotEmpty == true ? userInfo.id : (miId.isNotEmpty ? miId : null))))); 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, ) : SizedBox(); }, ); } } 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) ), ), ); } }