feat:增加统计模块年份选择功能
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flisp_app/widgets/flisp_widget.dart';
|
||||
import 'package:flisp_app/widgets/stats.dart';
|
||||
import 'package:flisp_app/widgets/todo_widget.dart';
|
||||
import 'package:flisp_app/widgets/year_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StatsPage extends StatefulWidget {
|
||||
@@ -18,7 +19,8 @@ class StatsPage extends StatefulWidget {
|
||||
|
||||
class StatsPageState extends State<StatsPage> {
|
||||
final double chartHeight = 400;
|
||||
final double statsHeight = 160;
|
||||
final double statsHeight = 120;
|
||||
int currentYear = DateTime.now().year;
|
||||
final FlispService flispService = FlispService();
|
||||
final TodoService todoService = TodoService();
|
||||
|
||||
@@ -33,11 +35,15 @@ class StatsPageState extends State<StatsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
allFlisps = flispService.getAllFlisps();
|
||||
refreshStats();
|
||||
}
|
||||
|
||||
void refreshStats() {
|
||||
allFlisps = flispService.getAllFlispsByYear(currentYear);
|
||||
getFlispMonthlyStats(allFlisps);
|
||||
getFlispCategoryStats(allFlisps);
|
||||
|
||||
allTodos = todoService.getAllTodos();
|
||||
allTodos = todoService.getAllTodosByYear(currentYear);
|
||||
getTodoMonthlyStats(allTodos);
|
||||
getTodoMonthlyCompleteStats(allTodos);
|
||||
getTodoCategoryStats(allTodos);
|
||||
@@ -109,10 +115,15 @@ class StatsPageState extends State<StatsPage> {
|
||||
Widget _buildFlispStats(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
buildChartTitle(context, '闪灵统计', Icons.analytics),
|
||||
const SizedBox(height: 3),
|
||||
buildChartDivider(context),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.analytics, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(width: 3),
|
||||
const Text('闪灵统计'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(child: buildFlispStatsCard(allFlisps)),
|
||||
],
|
||||
);
|
||||
@@ -159,10 +170,15 @@ class StatsPageState extends State<StatsPage> {
|
||||
Widget _buildTodoStats(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
buildChartTitle(context, '待办统计', Icons.analytics),
|
||||
const SizedBox(height: 3),
|
||||
buildChartDivider(context),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.analytics, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(width: 3),
|
||||
const Text('待办统计'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(child: buildTodoStatsCard(allTodos)),
|
||||
],
|
||||
);
|
||||
@@ -212,14 +228,25 @@ class StatsPageState extends State<StatsPage> {
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
YearSelector(
|
||||
initialYear: DateTime.now().year,
|
||||
minYear: 2000,
|
||||
maxYear: 2100,
|
||||
onYearChanged: (year) => {
|
||||
setState(() {
|
||||
currentYear = year;
|
||||
refreshStats();
|
||||
})
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
height: statsHeight,
|
||||
child: BuildCard(child: _buildFlispStats(context)),
|
||||
child: _buildFlispStats(context),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
SizedBox(
|
||||
height: statsHeight,
|
||||
child: BuildCard(child: _buildTodoStats(context)),
|
||||
child: _buildTodoStats(context),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
SizedBox(
|
||||
|
||||
Reference in New Issue
Block a user