Properly load the ingredient images

This commit is contained in:
Roland Geider
2026-04-29 20:53:50 +02:00
parent 3fbdaac4b3
commit 5bf2dd22ee
4 changed files with 27 additions and 6 deletions

View File

@@ -4433,6 +4433,10 @@ class $WorkoutLogTableTable extends WorkoutLogTable with TableInfo<$WorkoutLogTa
DriftSqlType.int,
data['${effectivePrefix}routine_id'],
)!,
sessionId: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}session_id'],
),
repetitions: attachedDatabase.typeMapping.read(
DriftSqlType.double,
data['${effectivePrefix}repetitions'],
@@ -6733,7 +6737,7 @@ class $IngredientImageTableTable extends IngredientImageTable
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'nutrition_ingredientimage';
static const String $name = 'nutrition_image';
@override
VerificationContext validateIntegrity(
Insertable<IngredientImage> instance, {

View File

@@ -95,7 +95,7 @@ const PowersyncIngredientTable = ps.Table(
@UseRowClass(IngredientImage)
class IngredientImageTable extends Table {
@override
String get tableName => 'nutrition_ingredientimage';
String get tableName => 'nutrition_image';
IntColumn get id => integer()();
TextColumn get uuid => text()();
@@ -113,7 +113,7 @@ class IngredientImageTable extends Table {
}
const PowersyncIngredientImageTable = ps.Table(
'nutrition_ingredientimage',
'nutrition_image',
[
ps.Column.text('uuid'),
ps.Column.integer('ingredient_id'),

View File

@@ -20,6 +20,7 @@
* Repository for measurement entries (local Drift operations).
*/
import 'package:drift/drift.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:wger/models/nutrition/ingredient.dart';
@@ -37,10 +38,26 @@ class IngredientRepository {
IngredientRepository(this._db);
/// Watches a single ingredient by [id], with its `image` field hydrated.
/// Emits `null` if no ingredient with that id exists, and re-emits whenever
/// either the ingredient row or its image change.
Stream<Ingredient?> watchById(int id) {
_logger.finer('Watching ingredient $id');
final query = (_db.select(_db.ingredientTable)..where((t) => t.id.equals(id)));
return query.watchSingleOrNull();
final joined = (_db.select(_db.ingredientTable)..where((t) => t.id.equals(id))).join([
leftOuterJoin(
_db.ingredientImageTable,
_db.ingredientImageTable.ingredientId.equalsExp(_db.ingredientTable.id),
),
]);
return joined.watchSingleOrNull().map((row) {
if (row == null) {
return null;
}
final ingredient = row.readTable(_db.ingredientTable);
ingredient.image = row.readTableOrNull(_db.ingredientImageTable);
return ingredient;
});
}
/// Read a single ingredient by [id] once from the DB

View File

@@ -111,7 +111,7 @@ final class RoutinesRiverpodProvider
RoutinesRiverpod create() => RoutinesRiverpod();
}
String _$routinesRiverpodHash() => r'e2ccfaa499f24dcd774cf6b208853b24da041318';
String _$routinesRiverpodHash() => r'7d24f51ef42eb8599e038df510ae21fd194730fb';
abstract class _$RoutinesRiverpod extends $StreamNotifier<RoutinesState> {
Stream<RoutinesState> build();