Skip to content

Commit 148fe8c

Browse files
committed
Fix null-check-operator error in the log page in the gym mode
1 parent 87a433b commit 148fe8c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/widgets/routines/gym_mode/log_page.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
275275
final logProvider = ref.read(workoutLogProvider);
276276
final log = ref.watch(gymLogProvider);
277277

278+
// The log is populated when the page becomes current: the PageView can lay
279+
// out and mount this page before that happens, so guard against null.
280+
if (log == null) {
281+
return const SizedBox.shrink();
282+
}
283+
278284
return Form(
279285
key: _form,
280286
child: Column(
@@ -290,9 +296,9 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
290296
Flexible(
291297
child: RepetitionInputWidget(
292298
key: const ValueKey('logs-reps-widget'),
293-
value: log?.repetitions,
299+
value: log.repetitions,
294300
valueChange: widget.configData.repetitionsRounding,
295-
unit: log?.repetitionsUnitObj,
301+
unit: log.repetitionsUnitObj,
296302
onChanged: (v) {
297303
if (v != null) {
298304
ref.read(gymLogProvider.notifier).setRepetitions(v);
@@ -308,9 +314,9 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
308314
Flexible(
309315
child: WeightInputWidget(
310316
key: const ValueKey('logs-weight-widget'),
311-
value: log?.weight,
317+
value: log.weight,
312318
valueChange: widget.configData.weightRounding,
313-
unit: log?.weightUnitObj,
319+
unit: log.weightUnitObj,
314320
onChanged: (v) {
315321
if (v != null) {
316322
ref.read(gymLogProvider.notifier).setWeight(v);
@@ -328,7 +334,7 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
328334
),
329335
RiRInputWidget(
330336
key: const ValueKey('rir-input-widget'),
331-
log!.rir,
337+
log.rir,
332338
onChanged: (value) {
333339
log.rir = value == '' ? null : num.parse(value);
334340
},

0 commit comments

Comments
 (0)