86 lines
2.3 KiB
Dart
86 lines
2.3 KiB
Dart
import 'package:blog_app/apis/blog.dart';
|
|
import 'package:blog_app/models/blog.dart';
|
|
import 'package:blog_app/widget/blog.dart';
|
|
import 'package:blog_app/widget/year_selector.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:timelines_plus/timelines_plus.dart';
|
|
|
|
class TimelinePage extends StatefulWidget {
|
|
const TimelinePage({super.key});
|
|
|
|
@override
|
|
State<TimelinePage> createState() => _TimelinePageState();
|
|
}
|
|
|
|
class _TimelinePageState extends State<TimelinePage> {
|
|
late List<Blog> blogs = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadBlogList();
|
|
}
|
|
|
|
Future<void> _loadBlogList() async {
|
|
try {
|
|
final result = await queryBlogByConditionApi(
|
|
null,
|
|
null,
|
|
DateTime.now().year,
|
|
);
|
|
setState(() {
|
|
blogs = result;
|
|
});
|
|
} catch (e) {
|
|
throw Exception('获取博客列表失败: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> refreshRecord(int year) async {
|
|
final result = await queryBlogByConditionApi(null, null, year);
|
|
setState(() {
|
|
blogs = result;
|
|
});
|
|
}
|
|
|
|
Widget _buildBlogList() {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return Timeline.tileBuilder(
|
|
theme: TimelineThemeData(nodePosition: 0, indicatorPosition: 0),
|
|
padding: EdgeInsets.all(6),
|
|
builder: TimelineTileBuilder.connected(
|
|
itemCount: blogs.length,
|
|
connectorBuilder:
|
|
(context, index, type) =>
|
|
Connector.solidLine(thickness: 2, color: colors.primary),
|
|
indicatorBuilder: (context, index) {
|
|
return Indicator.dot(size: 12.0, color: colors.primary);
|
|
},
|
|
contentsBuilder: (context, index) {
|
|
return buildBlogListItem(context, blogs[index], index + 1);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
YearSelector(
|
|
initialYear: DateTime.now().year,
|
|
minYear: 2000,
|
|
maxYear: 2100,
|
|
onYearChanged: (year) => refreshRecord(year),
|
|
),
|
|
const SizedBox(height: 8),
|
|
buildListTitle(blogs.length),
|
|
const SizedBox(height: 8),
|
|
Expanded(child: blogs.isEmpty ? buildEmpty() : _buildBlogList()),
|
|
],
|
|
);
|
|
}
|
|
}
|