From 4e959d777a690f0234fd2f69c8e39d657cb38f4e Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sun, 16 Mar 2025 19:59:00 +0100 Subject: [PATCH] The repetition and weight units can be null and don't need to be loaded in this case --- lib/providers/routines.dart | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/providers/routines.dart b/lib/providers/routines.dart index bb8a5d5f..62a93e51 100644 --- a/lib/providers/routines.dart +++ b/lib/providers/routines.dart @@ -289,12 +289,16 @@ class RoutinesProvider with ChangeNotifier { for (final slotEntry in slot.entries) { slotEntry.exerciseObj = (await _exerciseProvider.fetchAndSetExercise(slotEntry.exerciseId))!; - slotEntry.repetitionUnitObj = _repetitionUnits.firstWhere( - (e) => e.id == slotEntry.repetitionUnitId, - ); - slotEntry.weightUnitObj = _weightUnits.firstWhere( - (e) => e.id == slotEntry.weightUnitId, - ); + if (slotEntry.repetitionUnitId != null) { + slotEntry.repetitionUnitObj = _repetitionUnits.firstWhere( + (e) => e.id == slotEntry.repetitionUnitId, + ); + } + if (slotEntry.weightUnitId != null) { + slotEntry.weightUnitObj = _weightUnits.firstWhere( + (e) => e.id == slotEntry.weightUnitId, + ); + } } } } @@ -306,8 +310,12 @@ class RoutinesProvider with ChangeNotifier { routine.sessions = List.from(sessionDataEntries); for (final session in routine.sessions) { for (final log in session.logs) { - log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId); - log.repetitionUnit = _repetitionUnits.firstWhere((e) => e.id == log.repetitionsUnitId); + if (log.weightUnitId != null) { + log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId); + } + if (log.repetitionsUnitId != null) { + log.repetitionUnit = _repetitionUnits.firstWhere((e) => e.id == log.repetitionsUnitId); + } log.exerciseBase = (await _exerciseProvider.fetchAndSetExercise(log.exerciseId))!; } }