diff --git a/stronglift_replacement/workout_app/lib/screens/workout_screen_session.dart b/stronglift_replacement/workout_app/lib/screens/workout_screen_session.dart index 2079fe2..148f6f7 100644 --- a/stronglift_replacement/workout_app/lib/screens/workout_screen_session.dart +++ b/stronglift_replacement/workout_app/lib/screens/workout_screen_session.dart @@ -8,21 +8,24 @@ part of 'workout_screen.dart'; /// Save/restore of the crash-recovery session blob and break bookkeeping. extension _WorkoutScreenSession on _WorkoutScreenState { - /// Loads every exercise's state and the gap deloads to show. + /// Loads every exercise's state, then the gap deloads to show. Future _loadExerciseStates() async { - final states = await StorageService.instance.getAllExerciseStates(); - final gapDeloads = await StorageService.instance.activeGapDeloads(); + final storage = StorageService.instance; + final states = await storage.getAllExerciseStates(); // After, not beside, the read above: the push below carries both. await _cues.load(); - if (mounted) { - _applyBreakState(() { - _exerciseStates = {for (final s in states) s.name: s}; - _gapDeloads = gapDeloads; - }); - // The first snapshot can go out before this load lands, and it would - // count a paused exercise's sets until the next tap. A no-op if the - // service has not started yet: start() builds its own, current one. - unawaited(_breaks.push(_buildSnapshot())); + if (!mounted) return; + _applyBreakState(() { + _exerciseStates = {for (final s in states) s.name: s}; + }); + // The first snapshot can go out before this load lands, and it would + // count a paused exercise's sets until the next tap. A no-op if the + // service has not started yet: start() builds its own, current one. + unawaited(_breaks.push(_buildSnapshot())); + // Last, and only for the tiles: the struck-through pre-deload targets. + final gapDeloads = await storage.activeGapDeloads(); + if (mounted && gapDeloads.isNotEmpty) { + _applyBreakState(() => _gapDeloads = gapDeloads); } } diff --git a/stronglift_replacement/workout_app/lib/services/storage_service_gap_deload.dart b/stronglift_replacement/workout_app/lib/services/storage_service_gap_deload.dart index d137d86..1926b0e 100644 --- a/stronglift_replacement/workout_app/lib/services/storage_service_gap_deload.dart +++ b/stronglift_replacement/workout_app/lib/services/storage_service_gap_deload.dart @@ -120,10 +120,15 @@ extension StorageServiceGapDeload on StorageService { /// The newest gap or backfill deload per exercise that no session has /// followed yet: what the tile shows struck through. Future> activeGapDeloads() async { + final events = [ + for (final e in await getProgressionEvents()) + if (e.kind == kGapDeloadKind || e.kind == kBackfillDeloadKind) e, + ]; + // The usual case: no gap deload ever, so no history scan. + if (events.isEmpty) return const {}; final marks = await sessionMarks(); final shown = {}; - for (final e in await getProgressionEvents()) { - if (e.kind != kGapDeloadKind && e.kind != kBackfillDeloadKind) continue; + for (final e in events) { if (shown.containsKey(e.exercise)) continue; // newest first final history = marks[e.exercise]; if (history != null &&