feat:重构模块
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/widget/chart.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class StatsPage extends StatefulWidget {
|
||||
@@ -24,7 +25,9 @@ class _StatsPage extends State<StatsPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSummaryStats(FoodProvider provider) {
|
||||
Widget _buildSummaryStats(BuildContext context, FoodProvider provider) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return GridView.count(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
@@ -34,42 +37,62 @@ class _StatsPage extends State<StatsPage> {
|
||||
mainAxisSpacing: 8,
|
||||
childAspectRatio: 2,
|
||||
children: [
|
||||
StatsCard(
|
||||
icon: Icons.restaurant_menu,
|
||||
title: '菜谱总数',
|
||||
value: provider.summaryStats.recipeCount.toString(),
|
||||
unit: '个',
|
||||
GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: StatsCard(
|
||||
icon: Icons.restaurant_menu,
|
||||
title: '菜谱总数',
|
||||
value: provider.summaryStats.recipeCount.toString(),
|
||||
unit: '个',
|
||||
),
|
||||
),
|
||||
StatsCard(
|
||||
icon: Icons.grid_view_rounded,
|
||||
title: '菜谱类别',
|
||||
value: provider.summaryStats.categoryCount.toString(),
|
||||
unit: '种',
|
||||
GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: StatsCard(
|
||||
icon: Icons.grid_view_rounded,
|
||||
title: '菜谱类别',
|
||||
value: provider.summaryStats.categoryCount.toString(),
|
||||
unit: '种',
|
||||
),
|
||||
),
|
||||
StatsCard(
|
||||
icon: Icons.flag,
|
||||
title: '做菜次数',
|
||||
value: provider.summaryStats.workCount.toString(),
|
||||
unit: '个',
|
||||
GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: StatsCard(
|
||||
icon: Icons.flag,
|
||||
title: '做菜次数',
|
||||
value: provider.summaryStats.workCount.toString(),
|
||||
unit: '个',
|
||||
),
|
||||
),
|
||||
StatsCard(
|
||||
icon: Icons.show_chart,
|
||||
title: '平均次数',
|
||||
value: provider.averageRecordCount.toStringAsFixed(2),
|
||||
unit: '次/月',
|
||||
GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: StatsCard(
|
||||
icon: Icons.show_chart,
|
||||
title: '平均次数',
|
||||
value: provider.averageRecordCount.toStringAsFixed(2),
|
||||
unit: '次/月',
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(FoodProvider provider) {
|
||||
Widget _buildContent(BuildContext context, FoodProvider provider) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildSummaryStats(provider),
|
||||
_buildSummaryStats(context, provider),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: chartHeight,
|
||||
child: CommonCard(
|
||||
child: GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: LineChart(
|
||||
title: '记录统计',
|
||||
xAxisName: '日期',
|
||||
@@ -82,7 +105,9 @@ class _StatsPage extends State<StatsPage> {
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: chartHeight,
|
||||
child: CommonCard(
|
||||
child: GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: PieChart(
|
||||
title: '菜谱统计',
|
||||
unit: '个',
|
||||
@@ -93,7 +118,9 @@ class _StatsPage extends State<StatsPage> {
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: chartHeight,
|
||||
child: CommonCard(
|
||||
child: GlassCard(
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: RankChart(title: '排行榜', data: provider.rankStats, unit: '次'),
|
||||
),
|
||||
),
|
||||
@@ -105,13 +132,28 @@ class _StatsPage extends State<StatsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<FoodProvider>();
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator()
|
||||
else
|
||||
SingleChildScrollView(child: _buildContent(provider)),
|
||||
],
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
title: Text('统计', style: Theme.of(context).textTheme.titleLarge),
|
||||
centerTitle: true,
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsetsGeometry.all(10),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator()
|
||||
else
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 90),
|
||||
child: _buildContent(context, provider),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user