Skip to content

Commit d56c3b2

Browse files
committed
Handle corner cases with null values
While this should not happen, it seems there are situations when some people do run into the "Null check operator used on a null value" error here. Closes #878
1 parent 0a8dd49 commit d56c3b2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/widgets/dashboard/calendar.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
8787

8888
void loadEvents() async {
8989
final numberFormat = NumberFormat.decimalPattern(Localizations.localeOf(context).toString());
90+
final i18n = AppLocalizations.of(context);
9091

9192
// Process weight entries
9293
final weightProvider = context.read<BodyWeightProvider>();
@@ -98,7 +99,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
9899
}
99100

100101
// Add events to lists
101-
_events[date]!.add(Event(EventType.weight, '${numberFormat.format(entry.weight)} kg'));
102+
_events[date]?.add(Event(EventType.weight, '${numberFormat.format(entry.weight)} kg'));
102103
}
103104

104105
// Process measurements
@@ -111,7 +112,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
111112
_events[date] = [];
112113
}
113114

114-
_events[date]!.add(Event(
115+
_events[date]?.add(Event(
115116
EventType.measurement,
116117
'${category.name}: ${numberFormat.format(entry.value)} ${category.unit}',
117118
));
@@ -130,9 +131,9 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
130131
time = '(${timeToString(session.timeStart)} - ${timeToString(session.timeEnd)})';
131132

132133
// Add events to lists
133-
_events[date]!.add(Event(
134+
_events[date]?.add(Event(
134135
EventType.session,
135-
'${AppLocalizations.of(context).impression}: ${session.impressionAsString} $time',
136+
'${i18n.impression}: ${session.impressionAsString} $time',
136137
));
137138
}
138139
});
@@ -148,15 +149,15 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
148149
}
149150

150151
// Add events to lists
151-
_events[date]!.add(Event(
152+
_events[date]?.add(Event(
152153
EventType.caloriesDiary,
153-
AppLocalizations.of(context).kcalValue(entry.value.energy.toStringAsFixed(0)),
154+
i18n.kcalValue(entry.value.energy.toStringAsFixed(0)),
154155
));
155156
}
156157
}
157158

158159
// Add initial selected day to events list
159-
_selectedEvents.value = _getEventsForDay(_selectedDay!);
160+
_selectedEvents.value = _selectedDay != null ? _getEventsForDay(_selectedDay!) : [];
160161
}
161162

162163
@override

0 commit comments

Comments
 (0)