feat:增加博客统计模块

This commit is contained in:
2025-11-15 16:56:47 +08:00
parent 2cfb2ce592
commit d512a77f5f
22 changed files with 1196 additions and 524 deletions

View File

@@ -1,5 +1,6 @@
import 'package:blog_app/models/blog.dart';
import 'package:blog_app/pages/blog_detail_page.dart';
import 'package:blog_app/pages/category_list_page.dart';
import 'package:blog_app/utils/date_utils.dart';
import 'package:blog_app/widget/common.dart';
import 'package:flutter/material.dart';
@@ -138,6 +139,134 @@ class BlogCard extends StatelessWidget {
}
}
Widget buildCategoryTitle(BuildContext context, int count) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(8),
),
child: Text(
'$count 个分类',
style: const TextStyle(
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
),
],
);
}
Widget buildCategoryCard(BuildContext context, BlogCategory category) {
final colors = Theme.of(context).colorScheme;
return buildCard(
context: context,
child: ListTile(
leading: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: colors.primary.withAlpha(50),
shape: BoxShape.circle,
),
child: Icon(Icons.folder, color: colors.primary, size: 28),
),
title: Text(
category.name,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
subtitle: Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Text(
'${category.count} 篇博客',
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
),
),
trailing: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: colors.primary.withAlpha(50),
borderRadius: BorderRadius.circular(16),
),
child: Text(
category.count.toString(),
style: TextStyle(color: colors.primary, fontWeight: FontWeight.bold),
),
),
onTap: () => navigateToBlogList(context, category),
),
);
}
Widget buildListTitle(int count) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'博客列表',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
Text(
'$count',
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
),
],
);
}
Widget buildBlogListItem(BuildContext context, Blog blog, int index) {
final colors = Theme.of(context).colorScheme;
return buildCard(
context: context,
child: Padding(
padding: EdgeInsets.all(10),
child: Row(
children: [
SizedBox(
width: 25,
child: Text(
index.toString(),
style: TextStyle(
fontWeight: FontWeight.w500,
color: colors.primary,
),
),
),
// 发布时间
SizedBox(
width: 150,
child: Text(
blog.createTime,
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
),
),
// 标题
Expanded(
child: Text(
blog.title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: colors.primary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
);
}
void navigatorToBlogDetail(BuildContext context, int blogId) {
Navigator.push(
context,
@@ -145,6 +274,15 @@ void navigatorToBlogDetail(BuildContext context, int blogId) {
);
}
void navigateToBlogList(BuildContext context, BlogCategory category) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CategoryListPage(category: category.name),
),
);
}
Widget buildEmpty() {
return Center(
child: Column(