You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.3 KiB
193 lines
5.3 KiB
import 'package:flutter/material.dart';
|
|
import 'package:dating_touchme_app/generated/assets.dart';
|
|
import 'package:dating_touchme_app/model/home/marriage_data.dart';
|
|
|
|
class ContentCard extends StatelessWidget {
|
|
final MarriageData item;
|
|
|
|
const ContentCard({
|
|
Key? key,
|
|
required this.item,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
margin: EdgeInsets.only(bottom: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
elevation: 2,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 用户信息头部
|
|
_buildUserHeader(),
|
|
|
|
// 个人描述
|
|
if (item.description.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
child: Text(
|
|
item.description,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: Colors.black87
|
|
),
|
|
strutStyle: const StrutStyle(height: 1.5),
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
)
|
|
),
|
|
|
|
// 照片列表
|
|
if (item.photoList.isNotEmpty)
|
|
_buildImageGrid(),
|
|
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildUserHeader() {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
// 用户头像
|
|
CircleAvatar(
|
|
radius: 30,
|
|
backgroundImage: NetworkImage(_cleanImageUrl(item.avatar)),
|
|
backgroundColor: Colors.grey[200],
|
|
),
|
|
|
|
// 用户信息
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
item.nickName,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black
|
|
),
|
|
),
|
|
SizedBox(width: 6),
|
|
Text(
|
|
'${item.age}岁',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: Colors.grey[600]
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
item.city,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Colors.grey[500]
|
|
),
|
|
strutStyle: const StrutStyle(height: 1.2),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// 打招呼按钮
|
|
GestureDetector(
|
|
onTap: () {
|
|
// 打招呼功能
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFFFF6B6B),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Image.asset(
|
|
Assets.imagesHiIcon,
|
|
width: 16,
|
|
height: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildImageGrid() {
|
|
int imageCount = item.photoList.length;
|
|
|
|
if (imageCount == 0) return SizedBox();
|
|
|
|
// 单张图片
|
|
if (imageCount == 1) {
|
|
return Container(
|
|
width: double.infinity,
|
|
height: 200,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(12),
|
|
bottomRight: Radius.circular(12),
|
|
),
|
|
),
|
|
child: Image.network(
|
|
_cleanImageUrl(item.photoList[0].photoUrl),
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Image.asset(
|
|
Assets.imagesExampleContent,
|
|
fit: BoxFit.cover,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
// 多张图片网格布局
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
mainAxisSpacing: 2,
|
|
crossAxisSpacing: 2,
|
|
),
|
|
itemCount: imageCount,
|
|
itemBuilder: (context, index) {
|
|
return Container(
|
|
height: 100,
|
|
child: Image.network(
|
|
_cleanImageUrl(item.photoList[index].photoUrl),
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Image.asset(
|
|
Assets.imagesExampleContent,
|
|
fit: BoxFit.cover,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// 清理图片URL中的空格和多余字符
|
|
String _cleanImageUrl(String url) {
|
|
return url.trim();
|
|
}
|
|
}
|