fix: make routineId nullable in WorkoutLogTable to prevent crash

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
This commit is contained in:
Mustafa Senoglu
2026-07-09 14:15:04 +03:00
parent 4a8a1d6d00
commit cc483f3dae
2 changed files with 4 additions and 4 deletions

View File

@@ -65,7 +65,7 @@ class WorkoutLogTable extends Table {
TextColumn get id => text().clientDefault(() => ps.uuid.v7())();
IntColumn get exerciseId => integer().named('exercise_id')();
IntColumn get routineId => integer().named('routine_id')();
IntColumn get routineId => integer().named('routine_id').nullable()();
TextColumn get sessionId => text().named('session_id').nullable()();
IntColumn get iteration => integer().nullable()();
IntColumn get slotEntryId => integer().named('slot_entry_id').nullable()();

View File

@@ -45,7 +45,7 @@ class Log {
late int exerciseId;
late Exercise exerciseObj;
late int routineId;
int? routineId;
String? sessionId;
int? iteration;
int? slotEntryId;
@@ -69,7 +69,7 @@ class Log {
required this.exerciseId,
this.iteration,
this.slotEntryId,
required this.routineId,
this.routineId,
this.sessionId,
this.repetitions,
this.repetitionsTarget,
@@ -166,7 +166,7 @@ class Log {
return WorkoutLogTableCompanion(
id: id != null ? drift.Value(id!) : const drift.Value.absent(),
exerciseId: drift.Value(exerciseId),
routineId: drift.Value(routineId),
routineId: routineId != null ? drift.Value(routineId) : const drift.Value.absent(),
sessionId: sessionId != null ? drift.Value(sessionId) : const drift.Value.absent(),
iteration: iteration != null ? drift.Value(iteration) : const drift.Value.absent(),
slotEntryId: slotEntryId != null ? drift.Value(slotEntryId) : const drift.Value.absent(),