From 6c3bcc84b6ec06e1b06666a863015888c436762a Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Tue, 16 Dec 2025 00:08:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E6=9B=B4=E6=96=B0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=A1=B5=E9=9D=A2=E5=A9=9A=E5=A7=BB=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 根据性别代码动态显示男性或女性图标 - 优化图片画廊布局,固定显示4张图片 - 添加空图片占位符以保持布局一致性 - 在婚姻数据模型中新增性别代码字段 - 更新婚姻数据构造函数和JSON解析逻辑 - 从用户信息映射中添加性别代码转换 --- lib/model/home/marriage_data.dart | 4 ++++ lib/pages/message/chat_page.dart | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/model/home/marriage_data.dart b/lib/model/home/marriage_data.dart index 6a8acf9..edbf7fc 100644 --- a/lib/model/home/marriage_data.dart +++ b/lib/model/home/marriage_data.dart @@ -18,6 +18,7 @@ class MarriageData { final String districtName; final String describeInfo; final String createTime; + final int genderCode; final List photoList; // 为了兼容UI展示,添加一些计算属性 @@ -45,6 +46,7 @@ class MarriageData { required this.describeInfo, required this.createTime, required this.photoList, + required this.genderCode, }); factory MarriageData.fromJson(Map json) { @@ -65,6 +67,7 @@ class MarriageData { districtName: json['districtName'] ?? '', describeInfo: json['describeInfo'] ?? '', createTime: json['createTime'] ?? '', + genderCode: json['genderCode'] ?? 0, photoList: (json['photoList'] as List?)?.map((e) => PhotoItem.fromJson(e as Map)).toList() ?? [], ); } @@ -88,6 +91,7 @@ class MarriageData { districtName: userInfo.districtName ?? '', describeInfo: userInfo.describeInfo ?? '', createTime: userInfo.createTime ?? '', + genderCode: userInfo.genderCode?.toInt() ?? 0, photoList: (userInfo.photoList ?? []).map((photo) => PhotoItem( photoUrl: photo.photoUrl ?? '', auditStatus: photo.auditStatus, diff --git a/lib/pages/message/chat_page.dart b/lib/pages/message/chat_page.dart index 088c524..d8dfb75 100644 --- a/lib/pages/message/chat_page.dart +++ b/lib/pages/message/chat_page.dart @@ -323,7 +323,6 @@ class _ChatPageState extends State { if (marriageData == null) { return SizedBox.shrink(); } - return IntrinsicHeight( child: GestureDetector( onTap: () { @@ -452,7 +451,7 @@ class _ChatPageState extends State { children: [ // 性别图标(根据实际数据调整,这里暂时默认显示女性图标) Image.asset( - Assets.imagesFemale, + marriageData.genderCode == 0 ? Assets.imagesMale : Assets.imagesFemale, width: 14.w, height: 14.w, ), @@ -510,11 +509,24 @@ class _ChatPageState extends State { ), if (marriageData.photoList.isNotEmpty) ...[ SizedBox(height: 8.h), // 图片上方间距 - // 图片画廊(正方形) + // 图片画廊(正方形)- 固定4张的布局 Row( - children: marriageData.photoList.take(4).toList().asMap().entries.map((entry) { - final index = entry.key; - final photo = entry.value; + children: List.generate(4, (index) { + // 如果索引超出照片列表长度,返回空容器 + if (index >= marriageData.photoList.length) { + return Expanded( + child: AspectRatio( + aspectRatio: 1, // 设置为正方形 + child: Container( + margin: EdgeInsets.only( + right: index < 3 ? 8.w : 0, + ), + ), + ), + ); + } + + final photo = marriageData.photoList[index]; final photoUrl = photo.photoUrl.trim().replaceAll('`', ''); // 移除URL中的反引号 return Expanded( child: AspectRatio( @@ -537,7 +549,7 @@ class _ChatPageState extends State { ), ), ); - }).toList(), + }), ), SizedBox(height: 4.h), // 图片下方间距 ],