@@ -26,6 +26,7 @@ import 'package:wger/providers/user.dart';
26
26
import 'package:wger/screens/form_screen.dart' ;
27
27
import 'package:wger/screens/measurement_categories_screen.dart' ;
28
28
import 'package:wger/widgets/measurements/charts.dart' ;
29
+ import 'package:wger/widgets/measurements/helpers.dart' ;
29
30
import 'package:wger/widgets/weight/forms.dart' ;
30
31
31
32
class WeightOverview extends StatelessWidget {
@@ -40,78 +41,18 @@ class WeightOverview extends StatelessWidget {
40
41
weightProvider.items.map ((e) => MeasurementChartEntry (e.weight, e.date)).toList ();
41
42
final entries7dAvg = moving7dAverage (entriesAll);
42
43
43
- List <Widget > getOverviewWidgets (String title, bool isMetric, List <MeasurementChartEntry > raw,
44
- List <MeasurementChartEntry > avg, BuildContext context) {
45
- return [
46
- Text (
47
- title,
48
- textAlign: TextAlign .center,
49
- style: Theme .of (context).textTheme.titleLarge,
50
- ),
51
- Container (
52
- padding: const EdgeInsets .all (15 ),
53
- height: 220 ,
54
- child: MeasurementChartWidgetFl (
55
- raw,
56
- weightUnit (isMetric, context),
57
- avgs: avg,
58
- ),
59
- ),
60
- MeasurementOverallChangeWidget (
61
- avg.first,
62
- avg.last,
63
- weightUnit (isMetric, context),
64
- ),
65
- const SizedBox (height: 8 ),
66
- ];
67
- }
44
+ final unit = weightUnit (profile! .isMetric, context);
68
45
69
46
return Column (
70
47
children: [
71
- ...getOverviewWidgets (
72
- 'Weight all-time' ,
73
- profile! .isMetric,
48
+ ...getOverviewWidgetsSeries (
49
+ 'Weight' ,
74
50
entriesAll,
75
51
entries7dAvg,
52
+ plan,
53
+ unit,
76
54
context,
77
55
),
78
- if (plan != null )
79
- ...getOverviewWidgets (
80
- 'Weight during nutritional plan ${plan .description }' ,
81
- profile.isMetric,
82
- entriesAll.where ((e) => e.date.isAfter (plan.creationDate)).toList (),
83
- entries7dAvg.where ((e) => e.date.isAfter (plan.creationDate)).toList (),
84
- context,
85
- ),
86
- // if all time is significantly longer than 30 days (let's say > 75 days)
87
- // and if there is is a plan and it also was > 75 days,
88
- // then let's show a separate chart just focusing on the last 30 days
89
- if (entriesAll.first.date
90
- .isBefore (entriesAll.last.date.subtract (const Duration (days: 75 ))) &&
91
- (plan == null ||
92
- entriesAll
93
- .firstWhere ((e) => e.date.isAfter (plan.creationDate))
94
- .date
95
- .isBefore (entriesAll.last.date.subtract (const Duration (days: 30 )))))
96
- ...getOverviewWidgets (
97
- 'Weight last 30 days' ,
98
- profile.isMetric,
99
- entriesAll
100
- .where ((e) => e.date.isAfter (DateTime .now ().subtract (const Duration (days: 30 ))))
101
- .toList (),
102
- entries7dAvg
103
- .where ((e) => e.date.isAfter (DateTime .now ().subtract (const Duration (days: 30 ))))
104
- .toList (),
105
- context,
106
- ),
107
-
108
- Row (
109
- mainAxisAlignment: MainAxisAlignment .center,
110
- children: [
111
- Indicator (color: Theme .of (context).colorScheme.primary, text: 'raw' , isSquare: true ),
112
- Indicator (color: Theme .of (context).colorScheme.tertiary, text: 'avg' , isSquare: true ),
113
- ],
114
- ),
115
56
TextButton (
116
57
onPressed: () => Navigator .pushNamed (
117
58
context,
0 commit comments