mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-02 18:19:25 +01:00
Properly load the ingredient images
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user