@@ -35,6 +35,8 @@ List<Widget> getOverviewWidgetsSeries(
35
35
BuildContext context,
36
36
) {
37
37
final monthAgo = DateTime .now ().subtract (const Duration (days: 30 ));
38
+ final showPlan = plan != null && entriesAll.any ((e) => e.date.isAfter (plan.creationDate));
39
+
38
40
return [
39
41
...getOverviewWidgets (
40
42
AppLocalizations .of (context).chartAllTimeTitle (name),
@@ -43,7 +45,7 @@ List<Widget> getOverviewWidgetsSeries(
43
45
unit,
44
46
context,
45
47
),
46
- if (plan != null )
48
+ if (showPlan )
47
49
...getOverviewWidgets (
48
50
AppLocalizations .of (context).chartDuringPlanTitle (name, plan.description),
49
51
entriesAll.where ((e) => e.date.isAfter (plan.creationDate)).toList (),
@@ -52,14 +54,18 @@ List<Widget> getOverviewWidgetsSeries(
52
54
context,
53
55
),
54
56
// if all time is significantly longer than 30 days (let's say > 75 days)
55
- // and if there is is a plan and it also was > 75 days,
56
- // then let's show a separate chart just focusing on the last 30 days
57
- if (entriesAll.first.date.isBefore (entriesAll.last.date.subtract (const Duration (days: 75 ))) &&
57
+ // and any plan was also > 75 days,
58
+ // then let's show a separate chart just focusing on the last 30 days,
59
+ // if there is data for it.
60
+ if (entriesAll.isNotEmpty &&
61
+ entriesAll.first.date.isBefore (entriesAll.last.date.subtract (const Duration (days: 75 ))) &&
58
62
(plan == null ||
59
- entriesAll
60
- .firstWhere ((e) => e.date.isAfter (plan.creationDate))
61
- .date
62
- .isBefore (entriesAll.last.date.subtract (const Duration (days: 30 )))))
63
+ (showPlan &&
64
+ entriesAll
65
+ .firstWhere ((e) => e.date.isAfter (plan.creationDate))
66
+ .date
67
+ .isBefore (entriesAll.last.date.subtract (const Duration (days: 30 ))))) &&
68
+ entriesAll.any ((e) => e.date.isAfter (monthAgo)))
63
69
...getOverviewWidgets (
64
70
AppLocalizations .of (context).chart30DaysTitle (name),
65
71
entriesAll.where ((e) => e.date.isAfter (monthAgo)).toList (),
0 commit comments