Ensure muscles appearing in both primary and secondary lists only render the primary background, and deduplicate muscles by ID within each list. Fixes#145
Errors handled while the widget tree is building crashed or wedged the
app in three related ways:
- FlutterError.onError showed dialogs and snackbars synchronously.
Pushing a route mid-build trips the navigator's !_debugLocked
assertion, and because the one-dialog guard was set before showDialog
threw, its release never attached: every later error dialog was then
silently suppressed while nothing was on screen, leaving a blank,
unresponsive app until restart. Snackbars crashed outright via the
messenger's setState.
- The sync status and barcode dialogs did ref.read inside their route
builders, which run during build. With the provider chain dirty (any
token refresh dirties wgerBase -> auth), the read flushed it there and
Riverpod scheduled a scope refresh mid-build. The barcode builder also
created its search future inline, re-firing the search on every dialog
rebuild.
- Provider create bodies that widgets watch during build read providers
synchronously: the dashboard's routine hydration chain crashed on cold
start right after a token refresh, and TrophyStateNotifier.build()
has the same shape in the post-login window, where invalidation order
left networkStatusProvider dirty while its dependents rebuilt.
lib/core/build_safety.dart adds the two idioms as helpers: runAfterFrame
defers UI side effects past the build phase, yieldPastBuild yields
provider create bodies past their synchronous phase (a microtask, not a
timer, since widget tests assert !timersPending at teardown). The error
dialog guard is released when the context is gone or the push fails, the
snackbar helpers re-resolve the messenger inside the callback, the
dialog builders snapshot their providers in the tap handler, and
post-login invalidation runs leaf-first. Regression tests cover each
shape.
Not copying an exercise that isn't there keeps the crash away, but gym
mode then holds a log with no exercise, which would bite the next reader.
The past logs widget already knows the exercise from the set config, so
pass it down to setLog, which assigns it through the exercise setter so
that exerciseId stays consistent.
The notifier test worked around the old behaviour by setting exerciseObj
on every fixture, with a comment explaining that copyWith needs it. That
was the bug, written down, so it's gone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XzxNFoPMxsFPxHD3P2Ma3w
Log.exerciseObj was declared late and is only ever assigned when
hydrating the logs of a routine's sessions. Logs read from the database
are built through drift's row class and only carry exerciseId, so
copyWith threw a LateInitializationError when it unconditionally read
the field. Copying a past log in gym mode does exactly that.
Make the field nullable behind a getter that throws a descriptive error,
add exerciseObjOrNull for callers that legitimately handle logs straight
from the database, and only carry the exercise over when there is one.
Hydrating the exercise in watchLogsByExerciseDrift instead would mean
joining its translations, images, muscles and equipment for every log,
which most callers don't need.
The log page tests mocked the query with the test routine's logs, which
are hydrated, which is why this was never caught. They now return logs
without an exercise, like the real query does.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XzxNFoPMxsFPxHD3P2Ma3w
Server allows workout logs without a routine (free/ad-hoc logging),
but the app's Drift table declared routineId as non-nullable.
This caused a null check operator crash when PowerSync delivered
a row with routine_id = NULL.
Changes:
- WorkoutLogTable.routineId: integer() → integer().nullable()
- Log.routineId: late int → int?
- Log constructor: required this.routineId → this.routineId
- Log.toCompanion: handle null routineId with Value.absent()
Fixes#1250
- implement persistence for log scope and distinct settings
- refactor(logs): update pastExerciseLogsProvider to support custom scope and deduplication
- feat(ui): add log scope controls to StartPage and LogPage