Skip to content

Commit 5f148e7

Browse files
Dieterberolandgeider
authored andcommitted
no point showing charts that are empty - this also fixes some crashes
1 parent c5b1695 commit 5f148e7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/widgets/measurements/helpers.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ List<Widget> getOverviewWidgetsSeries(
3535
BuildContext context,
3636
) {
3737
final monthAgo = DateTime.now().subtract(const Duration(days: 30));
38+
final showPlan = plan != null && entriesAll.any((e) => e.date.isAfter(plan.creationDate));
39+
3840
return [
3941
...getOverviewWidgets(
4042
AppLocalizations.of(context).chartAllTimeTitle(name),
@@ -43,7 +45,7 @@ List<Widget> getOverviewWidgetsSeries(
4345
unit,
4446
context,
4547
),
46-
if (plan != null)
48+
if (showPlan)
4749
...getOverviewWidgets(
4850
AppLocalizations.of(context).chartDuringPlanTitle(name, plan.description),
4951
entriesAll.where((e) => e.date.isAfter(plan.creationDate)).toList(),
@@ -52,14 +54,18 @@ List<Widget> getOverviewWidgetsSeries(
5254
context,
5355
),
5456
// 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))) &&
5862
(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)))
6369
...getOverviewWidgets(
6470
AppLocalizations.of(context).chart30DaysTitle(name),
6571
entriesAll.where((e) => e.date.isAfter(monthAgo)).toList(),

0 commit comments

Comments
 (0)