factor:布局颜色重构

This commit is contained in:
2025-11-21 14:11:35 +08:00
parent 8f0f641d37
commit e38e26e685
18 changed files with 572 additions and 179 deletions

View File

@@ -53,7 +53,11 @@ class BlogCard extends StatelessWidget {
alignment: WrapAlignment.center,
children: [
if (blog.isGreat)
_buildBlogLabelItem('精品', Icons.workspace_premium, Colors.deepOrange),
_buildBlogLabelItem(
'精品',
Icons.workspace_premium,
Colors.deepOrange,
),
if (blog.topValue > 1)
_buildBlogLabelItem('置顶', Icons.push_pin, Colors.red),
_buildBlogLabelItem(blog.category, Icons.folder, Colors.blue),
@@ -101,12 +105,14 @@ class BlogCard extends StatelessWidget {
);
}
Widget _buildBlogSummary() {
Widget _buildBlogSummary(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return SizedBox(
width: double.infinity,
child: Text(
blog.summary,
style: TextStyle(color: Colors.grey.shade700, height: 1.6),
style: TextStyle(color: colors.secondary, height: 1.6),
overflow: TextOverflow.ellipsis,
),
);
@@ -126,7 +132,7 @@ class BlogCard extends StatelessWidget {
SizedBox(height: 16),
Container(height: 1, width: 80, color: colors.primary),
SizedBox(height: 16),
_buildBlogSummary(),
_buildBlogSummary(context),
],
),
);
@@ -181,14 +187,16 @@ Widget buildCategoryCard(BuildContext context, BlogCategory category) {
),
),
trailing: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
width: 30,
height: 30,
decoration: BoxDecoration(
color: colors.primary.withAlpha(50),
borderRadius: BorderRadius.circular(16),
color: Theme.of(context).colorScheme.primary.withAlpha(50),
shape: BoxShape.circle,
),
child: Text(
category.count.toString(),
style: TextStyle(color: colors.primary, fontWeight: FontWeight.bold),
child: Icon(
Icons.arrow_forward,
size: 16,
color: Theme.of(context).colorScheme.primary,
),
),
onTap: () => navigateToBlogList(context, category),
@@ -220,11 +228,17 @@ Widget buildBlogListItem(BuildContext context, Blog blog, int index) {
padding: EdgeInsets.all(0),
child: Row(
children: [
Text('$index.', style: TextStyle(fontWeight: FontWeight.w500)),
Text(
'$index.',
style: TextStyle(
color: colors.onSurface,
fontWeight: FontWeight.w500,
),
),
SizedBox(width: 10),
Text(
formatDateString(blog.createTime),
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
style: TextStyle(fontSize: 14, color: colors.onSurface),
),
SizedBox(width: 10),
Expanded(

View File

@@ -283,3 +283,67 @@ Widget pieChart({
],
);
}
Color _getRankColor(BuildContext context, int index) {
switch (index) {
case 0: // 金牌
return const Color(0xFFFFD700); // 标准金色
case 1: // 银牌
return const Color(0xFFC0C0C0); // 标准银色
case 2: // 铜牌
return const Color(0xFFCD7F32); // 标准铜色
default:
return Theme.of(context).colorScheme.onSurface; // 普通颜色
}
}
Widget rankChart({
required BuildContext context,
required String unit,
required List<ChartData> data,
}) {
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
final item = data[index];
final rank = index + 1;
return SizedBox(
height: 35,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
width: 25,
alignment: Alignment.center,
child: Text(
'$rank.',
style: TextStyle(
fontWeight: FontWeight.bold,
color: _getRankColor(context, index),
),
),
),
Text(
item.name,
style: TextStyle(
fontWeight: index < 3 ? FontWeight.bold : FontWeight.normal,
color: _getRankColor(context, index),
),
),
],
),
Text(
'${item.value.toStringAsFixed(0)} $unit',
style: TextStyle(
fontWeight: index < 3 ? FontWeight.bold : FontWeight.normal,
color: _getRankColor(context, index),
),
),
],
),
);
},
);
}

View File

@@ -8,6 +8,7 @@ Widget buildMarkdown({
}) => MarkdownWidget(data: data, tocController: tocController);
Widget buildTocPanel({
required BuildContext context,
required TocController tocController,
required bool showToc,
}) => Visibility(
@@ -18,7 +19,7 @@ Widget buildTocPanel({
width: 250,
height: 400,
decoration: BoxDecoration(
color: Colors.white,
color: Theme.of(context).colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
@@ -34,7 +35,7 @@ Widget buildTocPanel({
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[100],
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),

View File

@@ -27,14 +27,13 @@ Widget buildSearchField({
}
Widget buildSearchResultItem(BuildContext context, BlogSearch blog) {
final colors = Theme.of(context).colorScheme;
return BuildCard(
child: ListTile(
title: Text(
blog.title,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
style: TextStyle(fontWeight: FontWeight.bold, color: colors.primary),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -42,7 +41,7 @@ Widget buildSearchResultItem(BuildContext context, BlogSearch blog) {
SizedBox(height: 4),
Text(
blog.content,
style: TextStyle(color: Colors.grey[600], fontSize: 14),
style: TextStyle(color: colors.secondary, fontSize: 14),
),
],
),

View File

@@ -104,7 +104,7 @@ class _YearSelectorState extends State<YearSelector>
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Theme.of(context).primaryColor,
color: Theme.of(context).colorScheme.primary,
),
),
),