1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:wger/helpers/measurements.dart' ;
2
3
import 'package:wger/l10n/generated/app_localizations.dart' ;
3
4
import 'package:wger/models/nutrition/nutritional_plan.dart' ;
4
5
import 'package:wger/widgets/measurements/charts.dart' ;
@@ -19,7 +20,16 @@ List<Widget> getOverviewWidgets(
19
20
Container (
20
21
padding: const EdgeInsets .all (15 ),
21
22
height: 220 ,
22
- child: MeasurementChartWidgetFl (raw, unit, avgs: avg),
23
+ child: raw.isEmpty
24
+ ? Center (
25
+ child: Text (
26
+ 'No data available' ,
27
+ style: Theme .of (context).textTheme.bodyLarge? .copyWith (
28
+ color: Theme .of (context).colorScheme.secondary.withValues (alpha: 0.7 ),
29
+ ),
30
+ ),
31
+ )
32
+ : MeasurementChartWidgetFl (raw, unit, avgs: avg),
23
33
),
24
34
if (avg.isNotEmpty) MeasurementOverallChangeWidget (avg.first, avg.last, unit),
25
35
const SizedBox (height: 8 ),
@@ -34,16 +44,11 @@ List<Widget> getOverviewWidgetsSeries(
34
44
String name,
35
45
List <MeasurementChartEntry > entriesAll,
36
46
List <MeasurementChartEntry > entries7dAvg,
37
- NutritionalPlan ? plan ,
47
+ List < NutritionalPlan > plans ,
38
48
String unit,
39
49
BuildContext context,
40
50
) {
41
51
final monthAgo = DateTime .now ().subtract (const Duration (days: 30 ));
42
- final showPlan = plan != null &&
43
- entriesAll.any ((e) =>
44
- e.date.isAfter (plan.startDate) &&
45
- (plan.endDate == null || e.date.isBefore (plan.endDate! )));
46
-
47
52
return [
48
53
...getOverviewWidgets (
49
54
AppLocalizations .of (context).chartAllTimeTitle (name),
@@ -52,39 +57,25 @@ List<Widget> getOverviewWidgetsSeries(
52
57
unit,
53
58
context,
54
59
),
55
- if (showPlan)
60
+ // Show overview widgets for each plan in plans
61
+ for (final plan in plans)
56
62
...getOverviewWidgets (
57
63
AppLocalizations .of (context).chartDuringPlanTitle (name, plan.description),
58
- entriesAll
59
- .where ((e) =>
60
- e.date.isAfter (plan.startDate) &&
61
- (plan.endDate == null || e.date.isBefore (plan.endDate! )))
62
- .toList (),
63
- entries7dAvg
64
- .where ((e) =>
65
- e.date.isAfter (plan.startDate) &&
66
- (plan.endDate == null || e.date.isBefore (plan.endDate! )))
67
- .toList (),
64
+ entriesAll.whereDate (plan.startDate, plan.endDate),
65
+ entries7dAvg.whereDate (plan.startDate, plan.endDate),
68
66
unit,
69
67
context,
70
68
),
71
69
// if all time is significantly longer than 30 days (let's say > 75 days)
72
- // and any plan was also > 75 days,
73
70
// then let's show a separate chart just focusing on the last 30 days,
74
71
// if there is data for it.
75
72
if (entriesAll.isNotEmpty &&
76
73
entriesAll.first.date.isBefore (entriesAll.last.date.subtract (const Duration (days: 75 ))) &&
77
- (plan == null ||
78
- (showPlan &&
79
- entriesAll
80
- .firstWhere ((e) => e.date.isAfter (plan.startDate))
81
- .date
82
- .isBefore (entriesAll.last.date.subtract (const Duration (days: 30 ))))) &&
83
74
entriesAll.any ((e) => e.date.isAfter (monthAgo)))
84
75
...getOverviewWidgets (
85
76
AppLocalizations .of (context).chart30DaysTitle (name),
86
- entriesAll.where ((e) => e.date. isAfter ( monthAgo)). toList ( ),
87
- entries7dAvg.where ((e) => e.date. isAfter ( monthAgo)). toList ( ),
77
+ entriesAll.whereDate ( monthAgo, null ),
78
+ entries7dAvg.whereDate ( monthAgo, null ),
88
79
unit,
89
80
context,
90
81
),
@@ -119,16 +110,16 @@ List<Widget> getOverviewWidgetsSeries(
119
110
final twoMonthsAgo = DateTime .now ().subtract (const Duration (days: 61 ));
120
111
final fourMonthsAgo = DateTime .now ().subtract (const Duration (days: 122 ));
121
112
122
- if (entriesAll.where ((e) => e.date. isAfter ( twoMonthsAgo) ).length > 4 ) {
113
+ if (entriesAll.whereDate ( twoMonthsAgo, null ).length > 4 ) {
123
114
return (
124
- entriesAll.where ((e) => e.date. isAfter ( twoMonthsAgo)). toList ( ),
125
- entries7dAvg.where ((e) => e.date. isAfter ( twoMonthsAgo)). toList ( ),
115
+ entriesAll.whereDate ( twoMonthsAgo, null ),
116
+ entries7dAvg.whereDate ( twoMonthsAgo, null ),
126
117
);
127
118
}
128
- if (entriesAll.where ((e) => e.date. isAfter ( fourMonthsAgo) ).length > 4 ) {
119
+ if (entriesAll.whereDate ( fourMonthsAgo, null ).length > 4 ) {
129
120
return (
130
- entriesAll.where ((e) => e.date. isAfter ( fourMonthsAgo)). toList ( ),
131
- entries7dAvg.where ((e) => e.date. isAfter ( fourMonthsAgo)). toList ( ),
121
+ entriesAll.whereDate ( fourMonthsAgo, null ),
122
+ entries7dAvg.whereDate ( fourMonthsAgo, null ),
132
123
);
133
124
}
134
125
return (entriesAll, entries7dAvg);
0 commit comments