Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/features/routines/models/set_config_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,23 @@ class SetConfigData {
@JsonKey(required: true, name: 'exercise')
late int exerciseId;

Exercise? _exercise;

@JsonKey(includeFromJson: false, includeToJson: false)
Exercise get exercise {
if (_exercise == null) {
throw StateError(
'SetConfigData for slot entry $slotEntryId has no hydrated exercise '
'(exercise ID $exerciseId)',
);
}
return _exercise!;
}

set exercise(Exercise value) => _exercise = value;

@JsonKey(includeFromJson: false, includeToJson: false)
late Exercise exercise;
Exercise? get exerciseOrNull => _exercise;

@JsonKey(required: true, name: 'slot_entry_id')
late int slotEntryId;
Expand Down Expand Up @@ -181,7 +196,7 @@ class SetConfigData {
restTime: restTime ?? this.restTime,
maxRestTime: maxRestTime ?? this.maxRestTime,
comment: comment ?? this.comment,
exercise: exercise ?? this.exercise,
exercise: exercise ?? _exercise,
weightUnit: weightUnit ?? this.weightUnit,
repetitionsUnit: repetitionsUnit ?? this.repetitionsUnit,
);
Expand Down
7 changes: 7 additions & 0 deletions lib/features/routines/providers/gym_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ class GymStateNotifier extends _$GymStateNotifier {
}

for (final config in slotData.setConfigs) {
if (config.exerciseOrNull == null) {
_logger.warning(
'Exercise ${config.exerciseId} not hydrated for slot entry '
'${config.slotEntryId}, skipping page.',
);
continue;
}
// Log page
slotEntries.add(
SlotPageEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ class ExerciseOverview extends ConsumerWidget {
);
return Container();
}
final exercise = page.setConfigData!.exercise;
final exercise = page.setConfigData!.exerciseOrNull;

if (exercise == null) {
_logger.info('Exercise for slot page $slotUuid not hydrated yet, showing empty container.');
return Container();
}

return Column(
children: [
Expand Down
12 changes: 9 additions & 3 deletions lib/features/routines/widgets/gym_mode/log_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class LogPage extends ConsumerWidget {
return Container();
}
final setConfigData = slotEntryPage.setConfigData!;
final exercise = setConfigData.exerciseOrNull;

if (exercise == null) {
_logger.info('Exercise for slot page $slotUuid not hydrated yet, showing empty container.');
return Container();
}

// Past logs come straight from the local DB (not the gym-mode routine
// snapshot) so a set logged during this workout shows up right away.
Expand All @@ -93,7 +99,7 @@ class LogPage extends ConsumerWidget {
return Column(
children: [
NavigationHeader(
setConfigData.exercise.getTranslation(languageCode).name,
exercise.getTranslation(languageCode).name,
_controller,
),

Expand Down Expand Up @@ -135,15 +141,15 @@ class LogPage extends ConsumerWidget {
),
),
),
if (setConfigData.exercise.showPlateCalculator) const LogsPlatesWidget(),
if (exercise.showPlateCalculator) const LogsPlatesWidget(),
if (slotEntryPage.setConfigData!.comment.isNotEmpty)
Text(slotEntryPage.setConfigData!.comment, textAlign: TextAlign.center),
const SizedBox(height: 10),

// Overriding the log scope from here is handled in a follow-up, the
// settings currently only live in the gym mode options.
// _LogScopeControls(gymState: gymState),
Expanded(child: _buildPastLogs(pastLogs, setConfigData.exercise)),
Expanded(child: _buildPastLogs(pastLogs, exercise)),

Padding(
padding: const EdgeInsets.all(10),
Expand Down
4 changes: 3 additions & 1 deletion lib/features/routines/widgets/gym_mode/start_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ class StartPage extends ConsumerWidget {
),
),
),

...dayDataDisplay.slots
.expand((slot) => slot.setConfigs)
.where((entry) => entry.exerciseOrNull != null)
.fold<Map<Exercise, List<String>>>({}, (acc, entry) {
acc.putIfAbsent(entry.exercise, () => []).add(entry.textReprWithType);
acc.putIfAbsent(entry.exerciseOrNull!, () => []).add(entry.textReprWithType);
return acc;
})
.entries
Expand Down