145 lines
3.9 KiB
Dart
145 lines
3.9 KiB
Dart
import 'package:blog_app/models/blog.dart';
|
|
import 'package:blog_app/utils/date_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class BlogLabel {
|
|
final String text;
|
|
final IconData icon;
|
|
final Color color;
|
|
|
|
BlogLabel(this.text, this.icon, this.color);
|
|
}
|
|
|
|
class BlogCard extends StatelessWidget {
|
|
final Blog blog;
|
|
|
|
const BlogCard({super.key, required this.blog});
|
|
|
|
Widget _buildBlogLabelItem(String text, IconData icon, Color color) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: color.withAlpha(30),
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: color.withAlpha(20), width: 1),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 12, color: color),
|
|
SizedBox(width: 4),
|
|
Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
color: color,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBlogLabel() {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
child: Wrap(
|
|
spacing: 6,
|
|
runSpacing: 6,
|
|
alignment: WrapAlignment.center,
|
|
children: [
|
|
if (blog.isGreat)
|
|
_buildBlogLabelItem('精品', Icons.workspace_premium, Colors.amber),
|
|
if (blog.topValue > 1)
|
|
_buildBlogLabelItem('置顶', Icons.push_pin, Colors.red),
|
|
_buildBlogLabelItem(blog.category, Icons.folder, Colors.blue),
|
|
_buildBlogLabelItem(
|
|
formatDateString(blog.createTime),
|
|
Icons.calendar_today,
|
|
Colors.green,
|
|
),
|
|
_buildBlogLabelItem(
|
|
formatDateString(blog.updateTime),
|
|
Icons.calendar_month,
|
|
Colors.orange,
|
|
),
|
|
_buildBlogLabelItem(
|
|
'${blog.visitCount} 次',
|
|
Icons.remove_red_eye,
|
|
Colors.purple,
|
|
),
|
|
_buildBlogLabelItem(
|
|
'${blog.wordCount} 字',
|
|
Icons.text_fields,
|
|
Colors.indigo,
|
|
),
|
|
_buildBlogLabelItem(
|
|
'${blog.readDuration} 分钟',
|
|
Icons.access_time,
|
|
Colors.brown,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBlogTitle(BuildContext context) {
|
|
return Text(
|
|
blog.title,
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
}
|
|
|
|
Widget _buildBlogSummary() {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
child: Text(
|
|
blog.summary,
|
|
style: TextStyle(color: Colors.grey.shade700, height: 1.6),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return Card(
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
child: Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
color: colors.surface,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: colors.outline.withAlpha(50), width: 1),
|
|
),
|
|
child: Padding(
|
|
padding: EdgeInsets.all(20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
_buildBlogTitle(context),
|
|
SizedBox(height: 16),
|
|
_buildBlogLabel(),
|
|
SizedBox(height: 16),
|
|
Container(height: 1, width: 80, color: Theme.of(context).colorScheme.primary),
|
|
SizedBox(height: 16),
|
|
_buildBlogSummary(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|