diff --git a/lib/database/powersync/database.dart b/lib/database/powersync/database.dart index 0d7270d17..2ec7fe825 100644 --- a/lib/database/powersync/database.dart +++ b/lib/database/powersync/database.dart @@ -40,6 +40,8 @@ import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/ingredient_image.dart'; import 'package:wger/models/nutrition/ingredient_weight_unit.dart'; import 'package:wger/models/nutrition/log.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/models/workouts/log.dart'; import 'package:wger/models/workouts/repetition_unit.dart'; @@ -97,6 +99,8 @@ part 'database.g.dart'; IngredientTable, IngredientImageTable, IngredientWeightUnitTable, + MealTable, + MealItemTable, LogItemTable, // Gallery diff --git a/lib/database/powersync/database.g.dart b/lib/database/powersync/database.g.dart index 042bb4650..b77e0a8ce 100644 --- a/lib/database/powersync/database.g.dart +++ b/lib/database/powersync/database.g.dart @@ -7348,6 +7348,539 @@ class IngredientWeightUnitTableCompanion extends UpdateCompanion { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $MealTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _planIdMeta = const VerificationMeta('planId'); + @override + late final GeneratedColumn planId = GeneratedColumn( + 'plan_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES nutrition_nutritionplan (id)', + ), + ); + static const VerificationMeta _orderMeta = const VerificationMeta('order'); + @override + late final GeneratedColumn order = GeneratedColumn( + 'order', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + @override + late final GeneratedColumnWithTypeConverter time = GeneratedColumn( + 'time', + aliasedName, + true, + type: DriftSqlType.string, + requiredDuringInsert: false, + ).withConverter($MealTableTable.$convertertimen); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); + @override + late final GeneratedColumn name = GeneratedColumn( + 'name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: false, + defaultValue: const Constant(''), + ); + @override + List get $columns => [id, planId, order, time, name]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'nutrition_meal'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('plan_id')) { + context.handle( + _planIdMeta, + planId.isAcceptableOrUnknown(data['plan_id']!, _planIdMeta), + ); + } else if (isInserting) { + context.missing(_planIdMeta); + } + if (data.containsKey('order')) { + context.handle( + _orderMeta, + order.isAcceptableOrUnknown(data['order']!, _orderMeta), + ); + } else if (isInserting) { + context.missing(_orderMeta); + } + if (data.containsKey('name')) { + context.handle( + _nameMeta, + name.isAcceptableOrUnknown(data['name']!, _nameMeta), + ); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Meal map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Meal.fromDrift( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + planId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}plan_id'], + )!, + order: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}order'], + )!, + time: $MealTableTable.$convertertimen.fromSql( + attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}time'], + ), + ), + name: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name'], + )!, + ); + } + + @override + $MealTableTable createAlias(String alias) { + return $MealTableTable(attachedDatabase, alias); + } + + static TypeConverter $convertertime = const TimeOfDayConverter(); + static TypeConverter $convertertimen = NullAwareTypeConverter.wrap( + $convertertime, + ); +} + +class MealTableCompanion extends UpdateCompanion { + final Value id; + final Value planId; + final Value order; + final Value time; + final Value name; + final Value rowid; + const MealTableCompanion({ + this.id = const Value.absent(), + this.planId = const Value.absent(), + this.order = const Value.absent(), + this.time = const Value.absent(), + this.name = const Value.absent(), + this.rowid = const Value.absent(), + }); + MealTableCompanion.insert({ + required int id, + required int planId, + required int order, + this.time = const Value.absent(), + this.name = const Value.absent(), + this.rowid = const Value.absent(), + }) : id = Value(id), + planId = Value(planId), + order = Value(order); + static Insertable custom({ + Expression? id, + Expression? planId, + Expression? order, + Expression? time, + Expression? name, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (planId != null) 'plan_id': planId, + if (order != null) 'order': order, + if (time != null) 'time': time, + if (name != null) 'name': name, + if (rowid != null) 'rowid': rowid, + }); + } + + MealTableCompanion copyWith({ + Value? id, + Value? planId, + Value? order, + Value? time, + Value? name, + Value? rowid, + }) { + return MealTableCompanion( + id: id ?? this.id, + planId: planId ?? this.planId, + order: order ?? this.order, + time: time ?? this.time, + name: name ?? this.name, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (planId.present) { + map['plan_id'] = Variable(planId.value); + } + if (order.present) { + map['order'] = Variable(order.value); + } + if (time.present) { + map['time'] = Variable( + $MealTableTable.$convertertimen.toSql(time.value), + ); + } + if (name.present) { + map['name'] = Variable(name.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('MealTableCompanion(') + ..write('id: $id, ') + ..write('planId: $planId, ') + ..write('order: $order, ') + ..write('time: $time, ') + ..write('name: $name, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $MealItemTableTable extends MealItemTable with TableInfo<$MealItemTableTable, MealItem> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $MealItemTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _mealIdMeta = const VerificationMeta('mealId'); + @override + late final GeneratedColumn mealId = GeneratedColumn( + 'meal_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES nutrition_meal (id)', + ), + ); + static const VerificationMeta _ingredientIdMeta = const VerificationMeta( + 'ingredientId', + ); + @override + late final GeneratedColumn ingredientId = GeneratedColumn( + 'ingredient_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES nutrition_ingredient (id)', + ), + ); + static const VerificationMeta _weightUnitIdMeta = const VerificationMeta( + 'weightUnitId', + ); + @override + late final GeneratedColumn weightUnitId = GeneratedColumn( + 'weight_unit_id', + aliasedName, + true, + type: DriftSqlType.int, + requiredDuringInsert: false, + ); + static const VerificationMeta _orderMeta = const VerificationMeta('order'); + @override + late final GeneratedColumn order = GeneratedColumn( + 'order', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _amountMeta = const VerificationMeta('amount'); + @override + late final GeneratedColumn amount = GeneratedColumn( + 'amount', + aliasedName, + false, + type: DriftSqlType.double, + requiredDuringInsert: true, + ); + @override + List get $columns => [ + id, + mealId, + ingredientId, + weightUnitId, + order, + amount, + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'nutrition_mealitem'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('meal_id')) { + context.handle( + _mealIdMeta, + mealId.isAcceptableOrUnknown(data['meal_id']!, _mealIdMeta), + ); + } else if (isInserting) { + context.missing(_mealIdMeta); + } + if (data.containsKey('ingredient_id')) { + context.handle( + _ingredientIdMeta, + ingredientId.isAcceptableOrUnknown( + data['ingredient_id']!, + _ingredientIdMeta, + ), + ); + } else if (isInserting) { + context.missing(_ingredientIdMeta); + } + if (data.containsKey('weight_unit_id')) { + context.handle( + _weightUnitIdMeta, + weightUnitId.isAcceptableOrUnknown( + data['weight_unit_id']!, + _weightUnitIdMeta, + ), + ); + } + if (data.containsKey('order')) { + context.handle( + _orderMeta, + order.isAcceptableOrUnknown(data['order']!, _orderMeta), + ); + } else if (isInserting) { + context.missing(_orderMeta); + } + if (data.containsKey('amount')) { + context.handle( + _amountMeta, + amount.isAcceptableOrUnknown(data['amount']!, _amountMeta), + ); + } else if (isInserting) { + context.missing(_amountMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + MealItem map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return MealItem.fromDrift( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + mealId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}meal_id'], + )!, + ingredientId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}ingredient_id'], + )!, + weightUnitId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}weight_unit_id'], + ), + order: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}order'], + )!, + amount: attachedDatabase.typeMapping.read( + DriftSqlType.double, + data['${effectivePrefix}amount'], + )!, + ); + } + + @override + $MealItemTableTable createAlias(String alias) { + return $MealItemTableTable(attachedDatabase, alias); + } +} + +class MealItemTableCompanion extends UpdateCompanion { + final Value id; + final Value mealId; + final Value ingredientId; + final Value weightUnitId; + final Value order; + final Value amount; + final Value rowid; + const MealItemTableCompanion({ + this.id = const Value.absent(), + this.mealId = const Value.absent(), + this.ingredientId = const Value.absent(), + this.weightUnitId = const Value.absent(), + this.order = const Value.absent(), + this.amount = const Value.absent(), + this.rowid = const Value.absent(), + }); + MealItemTableCompanion.insert({ + required int id, + required int mealId, + required int ingredientId, + this.weightUnitId = const Value.absent(), + required int order, + required double amount, + this.rowid = const Value.absent(), + }) : id = Value(id), + mealId = Value(mealId), + ingredientId = Value(ingredientId), + order = Value(order), + amount = Value(amount); + static Insertable custom({ + Expression? id, + Expression? mealId, + Expression? ingredientId, + Expression? weightUnitId, + Expression? order, + Expression? amount, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (mealId != null) 'meal_id': mealId, + if (ingredientId != null) 'ingredient_id': ingredientId, + if (weightUnitId != null) 'weight_unit_id': weightUnitId, + if (order != null) 'order': order, + if (amount != null) 'amount': amount, + if (rowid != null) 'rowid': rowid, + }); + } + + MealItemTableCompanion copyWith({ + Value? id, + Value? mealId, + Value? ingredientId, + Value? weightUnitId, + Value? order, + Value? amount, + Value? rowid, + }) { + return MealItemTableCompanion( + id: id ?? this.id, + mealId: mealId ?? this.mealId, + ingredientId: ingredientId ?? this.ingredientId, + weightUnitId: weightUnitId ?? this.weightUnitId, + order: order ?? this.order, + amount: amount ?? this.amount, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (mealId.present) { + map['meal_id'] = Variable(mealId.value); + } + if (ingredientId.present) { + map['ingredient_id'] = Variable(ingredientId.value); + } + if (weightUnitId.present) { + map['weight_unit_id'] = Variable(weightUnitId.value); + } + if (order.present) { + map['order'] = Variable(order.value); + } + if (amount.present) { + map['amount'] = Variable(amount.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('MealItemTableCompanion(') + ..write('id: $id, ') + ..write('mealId: $mealId, ') + ..write('ingredientId: $ingredientId, ') + ..write('weightUnitId: $weightUnitId, ') + ..write('order: $order, ') + ..write('amount: $amount, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + class $LogItemTableTable extends LogItemTable with TableInfo<$LogItemTableTable, LogItem> { @override final GeneratedDatabase attachedDatabase; @@ -7960,6 +8493,8 @@ abstract class _$DriftPowersyncDatabase extends GeneratedDatabase { late final $IngredientImageTableTable ingredientImageTable = $IngredientImageTableTable(this); late final $IngredientWeightUnitTableTable ingredientWeightUnitTable = $IngredientWeightUnitTableTable(this); + late final $MealTableTable mealTable = $MealTableTable(this); + late final $MealItemTableTable mealItemTable = $MealItemTableTable(this); late final $LogItemTableTable logItemTable = $LogItemTableTable(this); late final $GalleryImageTableTable galleryImageTable = $GalleryImageTableTable(this); @override @@ -7991,6 +8526,8 @@ abstract class _$DriftPowersyncDatabase extends GeneratedDatabase { ingredientTable, ingredientImageTable, ingredientWeightUnitTable, + mealTable, + mealItemTable, logItemTable, galleryImageTable, ]; @@ -14748,6 +15285,28 @@ final class $$NutritionalPlanTableTableReferences super.$_typedResult, ); + static MultiTypedResultKey<$MealTableTable, List> _mealTableRefsTable( + _$DriftPowersyncDatabase db, + ) => MultiTypedResultKey.fromTable( + db.mealTable, + aliasName: $_aliasNameGenerator( + db.nutritionalPlanTable.id, + db.mealTable.planId, + ), + ); + + $$MealTableTableProcessedTableManager get mealTableRefs { + final manager = $$MealTableTableTableManager( + $_db, + $_db.mealTable, + ).filter((f) => f.planId.id.sqlEquals($_itemColumn('id')!)); + + final cache = $_typedResult.readTableOrNull(_mealTableRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache), + ); + } + static MultiTypedResultKey<$LogItemTableTable, List> _logItemTableRefsTable( _$DriftPowersyncDatabase db, ) => MultiTypedResultKey.fromTable( @@ -14840,6 +15399,30 @@ class $$NutritionalPlanTableTableFilterComposer builder: (column) => ColumnFilters(column), ); + Expression mealTableRefs( + Expression Function($$MealTableTableFilterComposer f) f, + ) { + final $$MealTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealTable, + getReferencedColumn: (t) => t.planId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealTableTableFilterComposer( + $db: $db, + $table: $db.mealTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } + Expression logItemTableRefs( Expression Function($$LogItemTableTableFilterComposer f) f, ) { @@ -14993,6 +15576,30 @@ class $$NutritionalPlanTableTableAnnotationComposer builder: (column) => column, ); + Expression mealTableRefs( + Expression Function($$MealTableTableAnnotationComposer a) f, + ) { + final $$MealTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealTable, + getReferencedColumn: (t) => t.planId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealTableTableAnnotationComposer( + $db: $db, + $table: $db.mealTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } + Expression logItemTableRefs( Expression Function($$LogItemTableTableAnnotationComposer a) f, ) { @@ -15031,7 +15638,7 @@ class $$NutritionalPlanTableTableTableManager $$NutritionalPlanTableTableUpdateCompanionBuilder, (NutritionalPlan, $$NutritionalPlanTableTableReferences), NutritionalPlan, - PrefetchHooks Function({bool logItemTableRefs}) + PrefetchHooks Function({bool mealTableRefs, bool logItemTableRefs}) > { $$NutritionalPlanTableTableTableManager( _$DriftPowersyncDatabase db, @@ -15118,13 +15725,33 @@ class $$NutritionalPlanTableTableTableManager ), ) .toList(), - prefetchHooksCallback: ({logItemTableRefs = false}) { + prefetchHooksCallback: ({mealTableRefs = false, logItemTableRefs = false}) { return PrefetchHooks( db: db, - explicitlyWatchedTables: [if (logItemTableRefs) db.logItemTable], + explicitlyWatchedTables: [ + if (mealTableRefs) db.mealTable, + if (logItemTableRefs) db.logItemTable, + ], addJoins: null, getPrefetchedDataCallback: (items) async { return [ + if (mealTableRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: $$NutritionalPlanTableTableReferences._mealTableRefsTable( + db, + ), + managerFromTypedResult: (p0) => $$NutritionalPlanTableTableReferences( + db, + table, + p0, + ).mealTableRefs, + referencedItemsForCurrentItem: (item, referencedItems) => + referencedItems.where( + (e) => e.planId == item.id, + ), + typedResults: items, + ), if (logItemTableRefs) await $_getPrefetchedData( currentTable: table, @@ -15137,7 +15764,9 @@ class $$NutritionalPlanTableTableTableManager p0, ).logItemTableRefs, referencedItemsForCurrentItem: (item, referencedItems) => - referencedItems.where((e) => e.planId == item.id), + referencedItems.where( + (e) => e.planId == item.id, + ), typedResults: items, ), ]; @@ -15160,7 +15789,7 @@ typedef $$NutritionalPlanTableTableProcessedTableManager = $$NutritionalPlanTableTableUpdateCompanionBuilder, (NutritionalPlan, $$NutritionalPlanTableTableReferences), NutritionalPlan, - PrefetchHooks Function({bool logItemTableRefs}) + PrefetchHooks Function({bool mealTableRefs, bool logItemTableRefs}) >; typedef $$IngredientTableTableCreateCompanionBuilder = IngredientTableCompanion Function({ @@ -15267,6 +15896,28 @@ final class $$IngredientTableTableReferences ); } + static MultiTypedResultKey<$MealItemTableTable, List> _mealItemTableRefsTable( + _$DriftPowersyncDatabase db, + ) => MultiTypedResultKey.fromTable( + db.mealItemTable, + aliasName: $_aliasNameGenerator( + db.ingredientTable.id, + db.mealItemTable.ingredientId, + ), + ); + + $$MealItemTableTableProcessedTableManager get mealItemTableRefs { + final manager = $$MealItemTableTableTableManager( + $_db, + $_db.mealItemTable, + ).filter((f) => f.ingredientId.id.sqlEquals($_itemColumn('id')!)); + + final cache = $_typedResult.readTableOrNull(_mealItemTableRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache), + ); + } + static MultiTypedResultKey<$LogItemTableTable, List> _logItemTableRefsTable( _$DriftPowersyncDatabase db, ) => MultiTypedResultKey.fromTable( @@ -15453,6 +16104,30 @@ class $$IngredientTableTableFilterComposer return f(composer); } + Expression mealItemTableRefs( + Expression Function($$MealItemTableTableFilterComposer f) f, + ) { + final $$MealItemTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealItemTable, + getReferencedColumn: (t) => t.ingredientId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealItemTableTableFilterComposer( + $db: $db, + $table: $db.mealItemTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } + Expression logItemTableRefs( Expression Function($$LogItemTableTableFilterComposer f) f, ) { @@ -15728,6 +16403,30 @@ class $$IngredientTableTableAnnotationComposer return f(composer); } + Expression mealItemTableRefs( + Expression Function($$MealItemTableTableAnnotationComposer a) f, + ) { + final $$MealItemTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealItemTable, + getReferencedColumn: (t) => t.ingredientId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealItemTableTableAnnotationComposer( + $db: $db, + $table: $db.mealItemTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } + Expression logItemTableRefs( Expression Function($$LogItemTableTableAnnotationComposer a) f, ) { @@ -15769,6 +16468,7 @@ class $$IngredientTableTableTableManager PrefetchHooks Function({ bool ingredientImageTableRefs, bool ingredientWeightUnitTableRefs, + bool mealItemTableRefs, bool logItemTableRefs, }) > { @@ -15893,6 +16593,7 @@ class $$IngredientTableTableTableManager ({ ingredientImageTableRefs = false, ingredientWeightUnitTableRefs = false, + mealItemTableRefs = false, logItemTableRefs = false, }) { return PrefetchHooks( @@ -15900,6 +16601,7 @@ class $$IngredientTableTableTableManager explicitlyWatchedTables: [ if (ingredientImageTableRefs) db.ingredientImageTable, if (ingredientWeightUnitTableRefs) db.ingredientWeightUnitTable, + if (mealItemTableRefs) db.mealItemTable, if (logItemTableRefs) db.logItemTable, ], addJoins: null, @@ -15945,6 +16647,23 @@ class $$IngredientTableTableTableManager ), typedResults: items, ), + if (mealItemTableRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: $$IngredientTableTableReferences._mealItemTableRefsTable( + db, + ), + managerFromTypedResult: (p0) => $$IngredientTableTableReferences( + db, + table, + p0, + ).mealItemTableRefs, + referencedItemsForCurrentItem: (item, referencedItems) => + referencedItems.where( + (e) => e.ingredientId == item.id, + ), + typedResults: items, + ), if (logItemTableRefs) await $_getPrefetchedData( currentTable: table, @@ -15985,6 +16704,7 @@ typedef $$IngredientTableTableProcessedTableManager = PrefetchHooks Function({ bool ingredientImageTableRefs, bool ingredientWeightUnitTableRefs, + bool mealItemTableRefs, bool logItemTableRefs, }) >; @@ -16769,6 +17489,828 @@ typedef $$IngredientWeightUnitTableTableProcessedTableManager = IngredientWeightUnit, PrefetchHooks Function({bool ingredientId}) >; +typedef $$MealTableTableCreateCompanionBuilder = + MealTableCompanion Function({ + required int id, + required int planId, + required int order, + Value time, + Value name, + Value rowid, + }); +typedef $$MealTableTableUpdateCompanionBuilder = + MealTableCompanion Function({ + Value id, + Value planId, + Value order, + Value time, + Value name, + Value rowid, + }); + +final class $$MealTableTableReferences + extends BaseReferences<_$DriftPowersyncDatabase, $MealTableTable, Meal> { + $$MealTableTableReferences(super.$_db, super.$_table, super.$_typedResult); + + static $NutritionalPlanTableTable _planIdTable(_$DriftPowersyncDatabase db) => + db.nutritionalPlanTable.createAlias( + $_aliasNameGenerator(db.mealTable.planId, db.nutritionalPlanTable.id), + ); + + $$NutritionalPlanTableTableProcessedTableManager get planId { + final $_column = $_itemColumn('plan_id')!; + + final manager = $$NutritionalPlanTableTableTableManager( + $_db, + $_db.nutritionalPlanTable, + ).filter((f) => f.id.sqlEquals($_column)); + final item = $_typedResult.readTableOrNull(_planIdTable($_db)); + if (item == null) return manager; + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item]), + ); + } + + static MultiTypedResultKey<$MealItemTableTable, List> _mealItemTableRefsTable( + _$DriftPowersyncDatabase db, + ) => MultiTypedResultKey.fromTable( + db.mealItemTable, + aliasName: $_aliasNameGenerator( + db.mealTable.id, + db.mealItemTable.mealId, + ), + ); + + $$MealItemTableTableProcessedTableManager get mealItemTableRefs { + final manager = $$MealItemTableTableTableManager( + $_db, + $_db.mealItemTable, + ).filter((f) => f.mealId.id.sqlEquals($_itemColumn('id')!)); + + final cache = $_typedResult.readTableOrNull(_mealItemTableRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache), + ); + } +} + +class $$MealTableTableFilterComposer extends Composer<_$DriftPowersyncDatabase, $MealTableTable> { + $$MealTableTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, + builder: (column) => ColumnFilters(column), + ); + + ColumnFilters get order => $composableBuilder( + column: $table.order, + builder: (column) => ColumnFilters(column), + ); + + ColumnWithTypeConverterFilters get time => $composableBuilder( + column: $table.time, + builder: (column) => ColumnWithTypeConverterFilters(column), + ); + + ColumnFilters get name => $composableBuilder( + column: $table.name, + builder: (column) => ColumnFilters(column), + ); + + $$NutritionalPlanTableTableFilterComposer get planId { + final $$NutritionalPlanTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.planId, + referencedTable: $db.nutritionalPlanTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$NutritionalPlanTableTableFilterComposer( + $db: $db, + $table: $db.nutritionalPlanTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } + + Expression mealItemTableRefs( + Expression Function($$MealItemTableTableFilterComposer f) f, + ) { + final $$MealItemTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealItemTable, + getReferencedColumn: (t) => t.mealId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealItemTableTableFilterComposer( + $db: $db, + $table: $db.mealItemTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } +} + +class $$MealTableTableOrderingComposer extends Composer<_$DriftPowersyncDatabase, $MealTableTable> { + $$MealTableTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get order => $composableBuilder( + column: $table.order, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get time => $composableBuilder( + column: $table.time, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get name => $composableBuilder( + column: $table.name, + builder: (column) => ColumnOrderings(column), + ); + + $$NutritionalPlanTableTableOrderingComposer get planId { + final $$NutritionalPlanTableTableOrderingComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.planId, + referencedTable: $db.nutritionalPlanTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$NutritionalPlanTableTableOrderingComposer( + $db: $db, + $table: $db.nutritionalPlanTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } +} + +class $$MealTableTableAnnotationComposer + extends Composer<_$DriftPowersyncDatabase, $MealTableTable> { + $$MealTableTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); + + GeneratedColumn get order => + $composableBuilder(column: $table.order, builder: (column) => column); + + GeneratedColumnWithTypeConverter get time => + $composableBuilder(column: $table.time, builder: (column) => column); + + GeneratedColumn get name => + $composableBuilder(column: $table.name, builder: (column) => column); + + $$NutritionalPlanTableTableAnnotationComposer get planId { + final $$NutritionalPlanTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.planId, + referencedTable: $db.nutritionalPlanTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$NutritionalPlanTableTableAnnotationComposer( + $db: $db, + $table: $db.nutritionalPlanTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } + + Expression mealItemTableRefs( + Expression Function($$MealItemTableTableAnnotationComposer a) f, + ) { + final $$MealItemTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.mealItemTable, + getReferencedColumn: (t) => t.mealId, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealItemTableTableAnnotationComposer( + $db: $db, + $table: $db.mealItemTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return f(composer); + } +} + +class $$MealTableTableTableManager + extends + RootTableManager< + _$DriftPowersyncDatabase, + $MealTableTable, + Meal, + $$MealTableTableFilterComposer, + $$MealTableTableOrderingComposer, + $$MealTableTableAnnotationComposer, + $$MealTableTableCreateCompanionBuilder, + $$MealTableTableUpdateCompanionBuilder, + (Meal, $$MealTableTableReferences), + Meal, + PrefetchHooks Function({bool planId, bool mealItemTableRefs}) + > { + $$MealTableTableTableManager( + _$DriftPowersyncDatabase db, + $MealTableTable table, + ) : super( + TableManagerState( + db: db, + table: table, + createFilteringComposer: () => $$MealTableTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => $$MealTableTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$MealTableTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: + ({ + Value id = const Value.absent(), + Value planId = const Value.absent(), + Value order = const Value.absent(), + Value time = const Value.absent(), + Value name = const Value.absent(), + Value rowid = const Value.absent(), + }) => MealTableCompanion( + id: id, + planId: planId, + order: order, + time: time, + name: name, + rowid: rowid, + ), + createCompanionCallback: + ({ + required int id, + required int planId, + required int order, + Value time = const Value.absent(), + Value name = const Value.absent(), + Value rowid = const Value.absent(), + }) => MealTableCompanion.insert( + id: id, + planId: planId, + order: order, + time: time, + name: name, + rowid: rowid, + ), + withReferenceMapper: (p0) => p0 + .map( + (e) => ( + e.readTable(table), + $$MealTableTableReferences(db, table, e), + ), + ) + .toList(), + prefetchHooksCallback: ({planId = false, mealItemTableRefs = false}) { + return PrefetchHooks( + db: db, + explicitlyWatchedTables: [ + if (mealItemTableRefs) db.mealItemTable, + ], + addJoins: + < + T extends TableManagerState< + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic + > + >(state) { + if (planId) { + state = + state.withJoin( + currentTable: table, + currentColumn: table.planId, + referencedTable: $$MealTableTableReferences._planIdTable(db), + referencedColumn: $$MealTableTableReferences._planIdTable(db).id, + ) + as T; + } + + return state; + }, + getPrefetchedDataCallback: (items) async { + return [ + if (mealItemTableRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: $$MealTableTableReferences._mealItemTableRefsTable(db), + managerFromTypedResult: (p0) => $$MealTableTableReferences( + db, + table, + p0, + ).mealItemTableRefs, + referencedItemsForCurrentItem: (item, referencedItems) => + referencedItems.where((e) => e.mealId == item.id), + typedResults: items, + ), + ]; + }, + ); + }, + ), + ); +} + +typedef $$MealTableTableProcessedTableManager = + ProcessedTableManager< + _$DriftPowersyncDatabase, + $MealTableTable, + Meal, + $$MealTableTableFilterComposer, + $$MealTableTableOrderingComposer, + $$MealTableTableAnnotationComposer, + $$MealTableTableCreateCompanionBuilder, + $$MealTableTableUpdateCompanionBuilder, + (Meal, $$MealTableTableReferences), + Meal, + PrefetchHooks Function({bool planId, bool mealItemTableRefs}) + >; +typedef $$MealItemTableTableCreateCompanionBuilder = + MealItemTableCompanion Function({ + required int id, + required int mealId, + required int ingredientId, + Value weightUnitId, + required int order, + required double amount, + Value rowid, + }); +typedef $$MealItemTableTableUpdateCompanionBuilder = + MealItemTableCompanion Function({ + Value id, + Value mealId, + Value ingredientId, + Value weightUnitId, + Value order, + Value amount, + Value rowid, + }); + +final class $$MealItemTableTableReferences + extends BaseReferences<_$DriftPowersyncDatabase, $MealItemTableTable, MealItem> { + $$MealItemTableTableReferences( + super.$_db, + super.$_table, + super.$_typedResult, + ); + + static $MealTableTable _mealIdTable(_$DriftPowersyncDatabase db) => db.mealTable.createAlias( + $_aliasNameGenerator(db.mealItemTable.mealId, db.mealTable.id), + ); + + $$MealTableTableProcessedTableManager get mealId { + final $_column = $_itemColumn('meal_id')!; + + final manager = $$MealTableTableTableManager( + $_db, + $_db.mealTable, + ).filter((f) => f.id.sqlEquals($_column)); + final item = $_typedResult.readTableOrNull(_mealIdTable($_db)); + if (item == null) return manager; + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item]), + ); + } + + static $IngredientTableTable _ingredientIdTable( + _$DriftPowersyncDatabase db, + ) => db.ingredientTable.createAlias( + $_aliasNameGenerator(db.mealItemTable.ingredientId, db.ingredientTable.id), + ); + + $$IngredientTableTableProcessedTableManager get ingredientId { + final $_column = $_itemColumn('ingredient_id')!; + + final manager = $$IngredientTableTableTableManager( + $_db, + $_db.ingredientTable, + ).filter((f) => f.id.sqlEquals($_column)); + final item = $_typedResult.readTableOrNull(_ingredientIdTable($_db)); + if (item == null) return manager; + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item]), + ); + } +} + +class $$MealItemTableTableFilterComposer + extends Composer<_$DriftPowersyncDatabase, $MealItemTableTable> { + $$MealItemTableTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, + builder: (column) => ColumnFilters(column), + ); + + ColumnFilters get weightUnitId => $composableBuilder( + column: $table.weightUnitId, + builder: (column) => ColumnFilters(column), + ); + + ColumnFilters get order => $composableBuilder( + column: $table.order, + builder: (column) => ColumnFilters(column), + ); + + ColumnFilters get amount => $composableBuilder( + column: $table.amount, + builder: (column) => ColumnFilters(column), + ); + + $$MealTableTableFilterComposer get mealId { + final $$MealTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.mealId, + referencedTable: $db.mealTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealTableTableFilterComposer( + $db: $db, + $table: $db.mealTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } + + $$IngredientTableTableFilterComposer get ingredientId { + final $$IngredientTableTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.ingredientId, + referencedTable: $db.ingredientTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$IngredientTableTableFilterComposer( + $db: $db, + $table: $db.ingredientTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } +} + +class $$MealItemTableTableOrderingComposer + extends Composer<_$DriftPowersyncDatabase, $MealItemTableTable> { + $$MealItemTableTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get weightUnitId => $composableBuilder( + column: $table.weightUnitId, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get order => $composableBuilder( + column: $table.order, + builder: (column) => ColumnOrderings(column), + ); + + ColumnOrderings get amount => $composableBuilder( + column: $table.amount, + builder: (column) => ColumnOrderings(column), + ); + + $$MealTableTableOrderingComposer get mealId { + final $$MealTableTableOrderingComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.mealId, + referencedTable: $db.mealTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealTableTableOrderingComposer( + $db: $db, + $table: $db.mealTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } + + $$IngredientTableTableOrderingComposer get ingredientId { + final $$IngredientTableTableOrderingComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.ingredientId, + referencedTable: $db.ingredientTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$IngredientTableTableOrderingComposer( + $db: $db, + $table: $db.ingredientTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } +} + +class $$MealItemTableTableAnnotationComposer + extends Composer<_$DriftPowersyncDatabase, $MealItemTableTable> { + $$MealItemTableTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); + + GeneratedColumn get weightUnitId => $composableBuilder( + column: $table.weightUnitId, + builder: (column) => column, + ); + + GeneratedColumn get order => + $composableBuilder(column: $table.order, builder: (column) => column); + + GeneratedColumn get amount => + $composableBuilder(column: $table.amount, builder: (column) => column); + + $$MealTableTableAnnotationComposer get mealId { + final $$MealTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.mealId, + referencedTable: $db.mealTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$MealTableTableAnnotationComposer( + $db: $db, + $table: $db.mealTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } + + $$IngredientTableTableAnnotationComposer get ingredientId { + final $$IngredientTableTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.ingredientId, + referencedTable: $db.ingredientTable, + getReferencedColumn: (t) => t.id, + builder: + ( + joinBuilder, { + $addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer, + }) => $$IngredientTableTableAnnotationComposer( + $db: $db, + $table: $db.ingredientTable, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, + ), + ); + return composer; + } +} + +class $$MealItemTableTableTableManager + extends + RootTableManager< + _$DriftPowersyncDatabase, + $MealItemTableTable, + MealItem, + $$MealItemTableTableFilterComposer, + $$MealItemTableTableOrderingComposer, + $$MealItemTableTableAnnotationComposer, + $$MealItemTableTableCreateCompanionBuilder, + $$MealItemTableTableUpdateCompanionBuilder, + (MealItem, $$MealItemTableTableReferences), + MealItem, + PrefetchHooks Function({bool mealId, bool ingredientId}) + > { + $$MealItemTableTableTableManager( + _$DriftPowersyncDatabase db, + $MealItemTableTable table, + ) : super( + TableManagerState( + db: db, + table: table, + createFilteringComposer: () => $$MealItemTableTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => + $$MealItemTableTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$MealItemTableTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: + ({ + Value id = const Value.absent(), + Value mealId = const Value.absent(), + Value ingredientId = const Value.absent(), + Value weightUnitId = const Value.absent(), + Value order = const Value.absent(), + Value amount = const Value.absent(), + Value rowid = const Value.absent(), + }) => MealItemTableCompanion( + id: id, + mealId: mealId, + ingredientId: ingredientId, + weightUnitId: weightUnitId, + order: order, + amount: amount, + rowid: rowid, + ), + createCompanionCallback: + ({ + required int id, + required int mealId, + required int ingredientId, + Value weightUnitId = const Value.absent(), + required int order, + required double amount, + Value rowid = const Value.absent(), + }) => MealItemTableCompanion.insert( + id: id, + mealId: mealId, + ingredientId: ingredientId, + weightUnitId: weightUnitId, + order: order, + amount: amount, + rowid: rowid, + ), + withReferenceMapper: (p0) => p0 + .map( + (e) => ( + e.readTable(table), + $$MealItemTableTableReferences(db, table, e), + ), + ) + .toList(), + prefetchHooksCallback: ({mealId = false, ingredientId = false}) { + return PrefetchHooks( + db: db, + explicitlyWatchedTables: [], + addJoins: + < + T extends TableManagerState< + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic + > + >(state) { + if (mealId) { + state = + state.withJoin( + currentTable: table, + currentColumn: table.mealId, + referencedTable: $$MealItemTableTableReferences._mealIdTable(db), + referencedColumn: $$MealItemTableTableReferences + ._mealIdTable(db) + .id, + ) + as T; + } + if (ingredientId) { + state = + state.withJoin( + currentTable: table, + currentColumn: table.ingredientId, + referencedTable: $$MealItemTableTableReferences._ingredientIdTable( + db, + ), + referencedColumn: $$MealItemTableTableReferences + ._ingredientIdTable(db) + .id, + ) + as T; + } + + return state; + }, + getPrefetchedDataCallback: (items) async { + return []; + }, + ); + }, + ), + ); +} + +typedef $$MealItemTableTableProcessedTableManager = + ProcessedTableManager< + _$DriftPowersyncDatabase, + $MealItemTableTable, + MealItem, + $$MealItemTableTableFilterComposer, + $$MealItemTableTableOrderingComposer, + $$MealItemTableTableAnnotationComposer, + $$MealItemTableTableCreateCompanionBuilder, + $$MealItemTableTableUpdateCompanionBuilder, + (MealItem, $$MealItemTableTableReferences), + MealItem, + PrefetchHooks Function({bool mealId, bool ingredientId}) + >; typedef $$LogItemTableTableCreateCompanionBuilder = LogItemTableCompanion Function({ Value id, @@ -17486,6 +19028,9 @@ class $DriftPowersyncDatabaseManager { _db, _db.ingredientWeightUnitTable, ); + $$MealTableTableTableManager get mealTable => $$MealTableTableTableManager(_db, _db.mealTable); + $$MealItemTableTableTableManager get mealItemTable => + $$MealItemTableTableTableManager(_db, _db.mealItemTable); $$LogItemTableTableTableManager get logItemTable => $$LogItemTableTableTableManager(_db, _db.logItemTable); $$GalleryImageTableTableTableManager get galleryImageTable => diff --git a/lib/database/powersync/tables/nutrition.dart b/lib/database/powersync/tables/nutrition.dart index bcf195ce5..80d559aa0 100644 --- a/lib/database/powersync/tables/nutrition.dart +++ b/lib/database/powersync/tables/nutrition.dart @@ -17,9 +17,13 @@ */ import 'package:drift/drift.dart'; +import 'package:flutter/material.dart' show TimeOfDay; import 'package:powersync/powersync.dart' as ps; +import 'package:wger/database/converters/time_of_day_converter.dart'; import 'package:wger/database/powersync/tables/ingredient.dart'; import 'package:wger/models/nutrition/log.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; @UseRowClass(NutritionalPlan) @@ -94,3 +98,67 @@ const PowersyncLogItemTable = ps.Table( ps.Index('ingredient_idx', [ps.IndexedColumn('ingredient_id')]), ], ); + +/// A meal inside a nutritional plan (`nutrition_meal`). +/// +/// Creation goes via REST (server assigns the integer PK and the `order` +/// field), edits and deletes flow through PowerSync. The `time` is +/// stored as a `HH:MM:SS` string and translated to/from [TimeOfDay] via +/// [TimeOfDayConverter]. +@UseRowClass(Meal, constructor: 'fromDrift') +class MealTable extends Table { + @override + String get tableName => 'nutrition_meal'; + + IntColumn get id => integer()(); + IntColumn get planId => integer().named('plan_id').references(NutritionalPlanTable, #id)(); + IntColumn get order => integer()(); + TextColumn get time => text().map(const TimeOfDayConverter()).nullable()(); + TextColumn get name => text().withDefault(const Constant(''))(); +} + +const PowersyncMealTable = ps.Table( + 'nutrition_meal', + [ + ps.Column.integer('plan_id'), + ps.Column.integer('order'), + ps.Column.text('time'), + ps.Column.text('name'), + ], + indexes: [ + ps.Index('plan_idx', [ps.IndexedColumn('plan_id')]), + ], +); + +/// A single ingredient + amount inside a meal (`nutrition_mealitem`). +/// +/// Creation via REST, edits and deletes via PowerSync. `amount` is +/// a `DecimalField(decimal_places=2, max_digits=6)` server-side, stored here +/// as REAL — the rounding happens implicitly when DRF coerces back. +@UseRowClass(MealItem, constructor: 'fromDrift') +class MealItemTable extends Table { + @override + String get tableName => 'nutrition_mealitem'; + + IntColumn get id => integer()(); + IntColumn get mealId => integer().named('meal_id').references(MealTable, #id)(); + IntColumn get ingredientId => integer().named('ingredient_id').references(IngredientTable, #id)(); + IntColumn get weightUnitId => integer().named('weight_unit_id').nullable()(); + IntColumn get order => integer()(); + RealColumn get amount => real()(); +} + +const PowersyncMealItemTable = ps.Table( + 'nutrition_mealitem', + [ + ps.Column.integer('meal_id'), + ps.Column.integer('ingredient_id'), + ps.Column.integer('weight_unit_id'), + ps.Column.integer('order'), + ps.Column.real('amount'), + ], + indexes: [ + ps.Index('meal_idx', [ps.IndexedColumn('meal_id')]), + ps.Index('ingredient_idx', [ps.IndexedColumn('ingredient_id')]), + ], +); diff --git a/lib/models/nutrition/meal.dart b/lib/models/nutrition/meal.dart index efafb5bd1..cd3653b59 100644 --- a/lib/models/nutrition/meal.dart +++ b/lib/models/nutrition/meal.dart @@ -16,8 +16,10 @@ * along with this program. If not, see . */ +import 'package:drift/drift.dart' as drift; import 'package:flutter/material.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:wger/database/powersync/database.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/helpers/date.dart'; import 'package:wger/helpers/json.dart'; @@ -41,6 +43,11 @@ class Meal { @JsonKey(name: 'name') late String name; + /// Server-assigned ordering inside the plan. Not user-editable; we sync it + /// down so PowerSync can replicate the row, but never push changes back. + @JsonKey(includeToJson: false, defaultValue: 1) + int order = 1; + @JsonKey(includeFromJson: false, includeToJson: false, defaultValue: []) List mealItems = []; @@ -67,6 +74,25 @@ class Meal { this.name = name ?? ''; } + /// Constructor used by Drift's generated row factory. + /// + /// The column names declared on `MealTable` map onto the named parameters + /// here; `mealItems`/`diaryEntries` aren't synced and are filled in later + /// by the repository hydration step. + Meal.fromDrift({ + this.id, + required int planId, + required int order, + this.time, + required String name, + }) { + this.planId = planId; + this.order = order; + this.name = name; + mealItems = []; + diaryEntries = []; + } + /// Calculate total nutritional value // This is already done on the server. It might be better to read it from there. NutritionalValues get plannedNutritionalValues { @@ -89,6 +115,22 @@ class Meal { Map toJson() => _$MealToJson(this); + /// Drift companion for updates against `nutrition_meal`. + /// + /// `order` is intentionally absent — it's server-managed and read-only. + MealTableCompanion toCompanion() { + final mealId = id; + if (mealId == null) { + throw StateError('Cannot persist meal without id (creation goes via REST)'); + } + return MealTableCompanion( + id: drift.Value(mealId), + planId: drift.Value(planId), + time: time == null ? const drift.Value.absent() : drift.Value(time!), + name: drift.Value(name), + ); + } + Meal copyWith({ int? id, int? planId, diff --git a/lib/models/nutrition/meal.g.dart b/lib/models/nutrition/meal.g.dart index 0edad8cd6..d4b3f1c4f 100644 --- a/lib/models/nutrition/meal.g.dart +++ b/lib/models/nutrition/meal.g.dart @@ -6,11 +6,14 @@ part of 'meal.dart'; // JsonSerializableGenerator // ************************************************************************** -Meal _$MealFromJson(Map json) => Meal( - id: (json['id'] as num?)?.toInt(), - time: stringToTimeNull(json['time'] as String?), - name: json['name'] as String?, -)..planId = (json['plan'] as num).toInt(); +Meal _$MealFromJson(Map json) => + Meal( + id: (json['id'] as num?)?.toInt(), + time: stringToTimeNull(json['time'] as String?), + name: json['name'] as String?, + ) + ..planId = (json['plan'] as num).toInt() + ..order = (json['order'] as num?)?.toInt() ?? 1; Map _$MealToJson(Meal instance) => { 'id': instance.id, diff --git a/lib/models/nutrition/meal_item.dart b/lib/models/nutrition/meal_item.dart index 9b17797ce..56eb03f75 100644 --- a/lib/models/nutrition/meal_item.dart +++ b/lib/models/nutrition/meal_item.dart @@ -16,7 +16,9 @@ * along with this program. If not, see . */ +import 'package:drift/drift.dart' as drift; import 'package:json_annotation/json_annotation.dart'; +import 'package:wger/database/powersync/database.dart'; import 'package:wger/helpers/json.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/ingredient_weight_unit.dart'; @@ -47,6 +49,10 @@ class MealItem { @JsonKey(required: true, fromJson: stringToNum, toJson: numToString) late num amount; + /// Server-assigned ordering inside the meal. Not user-editable. + @JsonKey(includeToJson: false, defaultValue: 1) + int order = 1; + MealItem({ this.id, int? mealId, @@ -66,11 +72,46 @@ class MealItem { MealItem.empty(); + /// Constructor used by Drift's generated row factory. + /// + /// The hydrated [ingredient]/[weightUnitObj] are filled in by the repository + /// after a JOIN; instances built here have only the FK ids set. + MealItem.fromDrift({ + this.id, + required int mealId, + required int ingredientId, + this.weightUnitId, + required int order, + required double amount, + }) { + this.mealId = mealId; + this.ingredientId = ingredientId; + this.amount = amount; + this.order = order; + } + // Boilerplate factory MealItem.fromJson(Map json) => _$MealItemFromJson(json); Map toJson() => _$MealItemToJson(this); + /// Drift companion for updates against `nutrition_mealitem`. + /// + /// `order` is intentionally absent — it's server-managed and read-only. + MealItemTableCompanion toCompanion() { + final itemId = id; + if (itemId == null) { + throw StateError('Cannot persist meal item without id (creation goes via REST)'); + } + return MealItemTableCompanion( + id: drift.Value(itemId), + mealId: drift.Value(mealId), + ingredientId: drift.Value(ingredientId), + weightUnitId: weightUnitId == null ? const drift.Value.absent() : drift.Value(weightUnitId!), + amount: drift.Value(amount.toDouble()), + ); + } + /// Calculations NutritionalValues get nutritionalValues { final weight = weightUnitObj == null ? amount : amount * weightUnitObj!.grams; diff --git a/lib/models/nutrition/meal_item.g.dart b/lib/models/nutrition/meal_item.g.dart index 91b201ed8..2e5155b24 100644 --- a/lib/models/nutrition/meal_item.g.dart +++ b/lib/models/nutrition/meal_item.g.dart @@ -14,7 +14,7 @@ MealItem _$MealItemFromJson(Map json) { ingredientId: (json['ingredient'] as num).toInt(), weightUnitId: (json['weight_unit'] as num?)?.toInt(), amount: stringToNum(json['amount'] as String?), - ); + )..order = (json['order'] as num?)?.toInt() ?? 1; } Map _$MealItemToJson(MealItem instance) => { diff --git a/lib/powersync/schema.dart b/lib/powersync/schema.dart index ce852d323..595da5b52 100644 --- a/lib/powersync/schema.dart +++ b/lib/powersync/schema.dart @@ -49,6 +49,8 @@ Schema schema = const Schema([ PowersyncIngredientImageTable, PowersyncIngredientWeightUnitTable, PowersyncNutritionalPlanTable, + PowersyncMealTable, + PowersyncMealItemTable, PowersyncLogItemTable, // Body weight diff --git a/lib/providers/nutrition_notifier.dart b/lib/providers/nutrition_notifier.dart index 519398878..1c8f756c4 100644 --- a/lib/providers/nutrition_notifier.dart +++ b/lib/providers/nutrition_notifier.dart @@ -20,7 +20,6 @@ import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:stream_transform/stream_transform.dart'; -import 'package:wger/core/exceptions/http_exception.dart'; import 'package:wger/core/exceptions/no_such_entry_exception.dart'; import 'package:wger/models/nutrition/log.dart'; import 'package:wger/models/nutrition/meal.dart'; @@ -241,6 +240,9 @@ class NutritionNotifier extends _$NutritionNotifier { // --- Meals --- + /// Creation still goes through REST. The freshly-saved meal is injected into + /// in-memory state so the UI sees it immediately, before PowerSync has + /// replicated the row down into the local Drift database. Future addMeal(Meal meal, int planId) async { final repo = ref.read(nutritionRepositoryProvider); final plan = findById(planId); @@ -252,32 +254,27 @@ class NutritionNotifier extends _$NutritionNotifier { return saved; } - Future editMeal(Meal meal) async { + /// Goes through PowerSync (Drift update → CRUD queue → backend). + Future editMeal(Meal meal) async { final repo = ref.read(nutritionRepositoryProvider); - final data = await repo.updateMeal(meal.id!, meal.toJson()); - final updated = Meal.fromJson(data); + await repo.editMealLocalDrift(meal); _notifyAfterInPlaceMutation(); - return updated; } + /// Goes through PowerSync (Drift delete → CRUD queue → backend), where + /// Django's FK CASCADE removes any dependent meal items. Future deleteMeal(Meal meal) async { final repo = ref.read(nutritionRepositoryProvider); final plan = findById(meal.planId); - final mealIndex = plan.meals.indexWhere((e) => e.id == meal.id); - final existing = plan.meals[mealIndex]; - plan.meals.removeAt(mealIndex); + plan.meals.removeWhere((e) => e.id == meal.id); _notifyAfterInPlaceMutation(); - - final response = await repo.deleteMeal(meal.id!); - if (response.statusCode >= 400) { - plan.meals.insert(mealIndex, existing); - _notifyAfterInPlaceMutation(); - throw WgerHttpException(response); - } + await repo.deleteMealLocalDrift(meal.id!); } // --- Meal items --- + /// Creation still goes through REST. The saved item is injected into the + /// meal's in-memory list so the UI sees it immediately. Future addMealItem(MealItem mealItem, Meal meal) async { final repo = ref.read(nutritionRepositoryProvider); final data = await repo.createMealItem(mealItem.toJson()); @@ -288,20 +285,20 @@ class NutritionNotifier extends _$NutritionNotifier { return saved; } + /// Goes through PowerSync (Drift update → CRUD queue → backend). + Future editMealItem(MealItem mealItem) async { + final repo = ref.read(nutritionRepositoryProvider); + await repo.editMealItemLocalDrift(mealItem); + _notifyAfterInPlaceMutation(); + } + + /// Goes through PowerSync (Drift delete → CRUD queue → backend). Future deleteMealItem(MealItem mealItem) async { final repo = ref.read(nutritionRepositoryProvider); final meal = findMealById(mealItem.mealId)!; - final mealItemIndex = meal.mealItems.indexWhere((e) => e.id == mealItem.id); - final existing = meal.mealItems[mealItemIndex]; - meal.mealItems.removeAt(mealItemIndex); + meal.mealItems.removeWhere((e) => e.id == mealItem.id); _notifyAfterInPlaceMutation(); - - final response = await repo.deleteMealItem(mealItem.id!); - if (response.statusCode >= 400) { - meal.mealItems.insert(mealItemIndex, existing); - _notifyAfterInPlaceMutation(); - throw WgerHttpException(response); - } + await repo.deleteMealItemLocalDrift(mealItem.id!); } // --- Logs (nutrition diary) --- diff --git a/lib/providers/nutrition_notifier.g.dart b/lib/providers/nutrition_notifier.g.dart index e46165d2f..9858f7f76 100644 --- a/lib/providers/nutrition_notifier.g.dart +++ b/lib/providers/nutrition_notifier.g.dart @@ -33,7 +33,7 @@ final class NutritionNotifierProvider NutritionNotifier create() => NutritionNotifier(); } -String _$nutritionNotifierHash() => r'ac4b649e3622f55c01486efa4538038f68dba113'; +String _$nutritionNotifierHash() => r'c38f221bd9b074fb5b59f2a6d3421f460a8c37dc'; abstract class _$NutritionNotifier extends $StreamNotifier { Stream build(); diff --git a/lib/providers/nutrition_repository.dart b/lib/providers/nutrition_repository.dart index fc6fdb047..600154567 100644 --- a/lib/providers/nutrition_repository.dart +++ b/lib/providers/nutrition_repository.dart @@ -19,12 +19,13 @@ import 'package:collection/collection.dart'; import 'package:drift/drift.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; import 'package:logging/logging.dart'; import 'package:wger/database/powersync/database.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/ingredient_weight_unit.dart'; import 'package:wger/models/nutrition/log.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/base_provider.dart'; import 'package:wger/providers/wger_base.dart'; @@ -37,11 +38,13 @@ final nutritionRepositoryProvider = Provider((ref) { /// Data access for nutrition-related entities. /// -/// HTTP only for what hasn't migrated to PowerSync yet (plan creation, meals -/// and meal items). Reads/edits/deletes for the top-level [NutritionalPlan] -/// and the diary [LogItem] table go through the local PowerSync-backed Drift -/// database — see [watchAllDrift], [editLocalDrift], [deleteLocalDrift], -/// [watchAllLogsHydrated], [addLogLocalDrift], [deleteLogLocalDrift]. +/// Creation paths still use HTTP (plans, meals, meal items — the server picks +/// the integer PK and the `order`). Edits and deletes for [NutritionalPlan], +/// [Meal], [MealItem] and the diary [LogItem] table all flow through the +/// local PowerSync-backed Drift database; see [editLocalDrift] / +/// [deleteLocalDrift] (plans), [editMealLocalDrift] / [deleteMealLocalDrift], +/// [editMealItemLocalDrift] / [deleteMealItemLocalDrift], and the log +/// methods. /// /// Ingredient searches (local + REST) live on [IngredientRepository]. class NutritionRepository { @@ -108,26 +111,54 @@ class NutritionRepository { // --- Meals --- + /// Creation still goes through REST: the server assigns the integer PK and + /// the `order` field, then PowerSync replicates the row down so subsequent + /// edits and deletes can target the local Drift row. Future> createMeal(Map data) async { return _base.post(data, _base.makeUrl(mealPath)); } - Future> updateMeal(int id, Map data) async { - return _base.patch(data, _base.makeUrl(mealPath, id: id)); + /// Updates a meal via the local Drift table. PowerSync's CRUD queue picks + /// the change up and PATCHes it to the backend. + Future editMealLocalDrift(Meal meal) async { + final id = meal.id; + if (id == null) { + throw StateError('Cannot edit a meal without id'); + } + _logger.finer('Updating local meal $id'); + await (_db.update(_db.mealTable)..where((t) => t.id.equals(id))).write(meal.toCompanion()); } - Future deleteMeal(int id) async { - return _base.deleteRequest(mealPath, id); + /// Deletes a meal via the local Drift table. The backend cascades through + /// to the dependent meal items. + Future deleteMealLocalDrift(int id) async { + _logger.finer('Deleting local meal $id'); + await (_db.delete(_db.mealTable)..where((t) => t.id.equals(id))).go(); } // --- Meal items --- + /// Creation still goes through REST (server-assigned PK and `order`); + /// PowerSync replicates the row down for subsequent local edits/deletes. Future> createMealItem(Map data) async { return _base.post(data, _base.makeUrl(mealItemPath)); } - Future deleteMealItem(int id) async { - return _base.deleteRequest(mealItemPath, id); + /// Updates a meal item via the local Drift table. PowerSync picks the + /// change up and PATCHes it to the backend. + Future editMealItemLocalDrift(MealItem item) async { + final id = item.id; + if (id == null) { + throw StateError('Cannot edit a meal item without id'); + } + _logger.finer('Updating local meal item $id'); + await (_db.update(_db.mealItemTable)..where((t) => t.id.equals(id))).write(item.toCompanion()); + } + + /// Deletes a meal item via the local Drift table. + Future deleteMealItemLocalDrift(int id) async { + _logger.finer('Deleting local meal item $id'); + await (_db.delete(_db.mealItemTable)..where((t) => t.id.equals(id))).go(); } // --- Nutrition diary (logs) --- diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 5eea59b9c..0a709c08f 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -51,7 +51,11 @@ class MealForm extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + // Creation still goes through REST (server-assigned PK + order); editing + // flows through PowerSync and is therefore offline-capable. + final isCreating = _meal.id == null; final isOnline = ref.watch(networkStatusProvider); + final canSubmit = !isCreating || isOnline; return Container( margin: const EdgeInsets.all(20), child: Form( @@ -91,7 +95,7 @@ class MealForm extends ConsumerWidget { ElevatedButton( key: const Key(SUBMIT_BUTTON_KEY_NAME), child: Text(AppLocalizations.of(context).save), - onPressed: isOnline + onPressed: canSubmit ? () { if (!_form.currentState!.validate()) { return; @@ -99,9 +103,7 @@ class MealForm extends ConsumerWidget { _form.currentState!.save(); final notifier = ref.read(nutritionProvider.notifier); - _meal.id == null - ? notifier.addMeal(_meal, _planId) - : notifier.editMeal(_meal); + isCreating ? notifier.addMeal(_meal, _planId) : notifier.editMeal(_meal); Navigator.of(context).pop(); } @@ -547,7 +549,11 @@ class _PlanFormState extends ConsumerState { @override Widget build(BuildContext context) { final dateFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode); + // Creation still goes through REST (server-assigned PK + creation_date); + // editing flows through PowerSync and is therefore offline-capable. + final isCreating = widget._plan.id == null; final isOnline = ref.watch(networkStatusProvider); + final canSubmit = !isCreating || isOnline; return Form( key: _form, @@ -759,7 +765,7 @@ class _PlanFormState extends ConsumerState { ElevatedButton( key: const Key(SUBMIT_BUTTON_KEY_NAME), child: Text(AppLocalizations.of(context).save), - onPressed: isOnline + onPressed: canSubmit ? () async { // Validate and save the current values to the plan final isValid = _form.currentState!.validate(); @@ -770,7 +776,7 @@ class _PlanFormState extends ConsumerState { // Save to DB final notifier = ref.read(nutritionProvider.notifier); - if (widget._plan.id != null) { + if (!isCreating) { await notifier.editPlan(widget._plan); if (context.mounted) { Navigator.of(context).pop(); diff --git a/lib/widgets/nutrition/meal.dart b/lib/widgets/nutrition/meal.dart index d102c3478..e8e6a0f9e 100644 --- a/lib/widgets/nutrition/meal.dart +++ b/lib/widgets/nutrition/meal.dart @@ -128,37 +128,33 @@ class _MealWidgetState extends ConsumerState { ), TextButton.icon( label: Text(AppLocalizations.of(context).edit), - onPressed: isOnline - ? () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).edit, - MealForm(widget._meal.planId, widget._meal), - ), - ); - } - : null, + onPressed: () { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).edit, + MealForm(widget._meal.planId, widget._meal), + ), + ); + }, icon: const Icon(Icons.timer), ), TextButton.icon( - onPressed: isOnline - ? () { - // Delete the meal - ref.read(nutritionProvider.notifier).deleteMeal(widget._meal); + onPressed: () { + // Delete the meal + ref.read(nutritionProvider.notifier).deleteMeal(widget._meal); - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - } - : null, + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, label: Text(AppLocalizations.of(context).delete), icon: const Icon(Icons.delete), ), @@ -236,7 +232,6 @@ class MealItemEditableFullTile extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final values = _item.nutritionalValues; final i18n = AppLocalizations.of(context); - final isOnline = ref.watch(networkStatusProvider); final String amountText = _item.weightUnitObj != null ? '${_item.amount.toStringAsFixed(0)} × ${_item.weightUnitObj!.name}' @@ -257,22 +252,20 @@ class MealItemEditableFullTile extends ConsumerWidget { icon: const Icon(Icons.delete, size: ICON_SIZE_SMALL), tooltip: i18n.delete, iconSize: ICON_SIZE_SMALL, - onPressed: isOnline - ? () { - // Delete the meal item - ref.read(nutritionProvider.notifier).deleteMealItem(_item); + onPressed: () { + // Delete the meal item — goes through PowerSync, so offline is fine. + ref.read(nutritionProvider.notifier).deleteMealItem(_item); - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - i18n.successfullyDeleted, - textAlign: TextAlign.center, - ), - ), - ); - } - : null, + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + i18n.successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, ) : null, ); diff --git a/test/measurements/measurement_entries_screen_test.mocks.dart b/test/measurements/measurement_entries_screen_test.mocks.dart index 593ca8970..afbb079a6 100644 --- a/test/measurements/measurement_entries_screen_test.mocks.dart +++ b/test/measurements/measurement_entries_screen_test.mocks.dart @@ -3,18 +3,19 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; +import 'dart:async' as _i3; -import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/measurements/measurement_category.dart' as _i5; -import 'package:wger/models/measurements/measurement_entry.dart' as _i6; -import 'package:wger/models/nutrition/ingredient.dart' as _i11; -import 'package:wger/models/nutrition/log.dart' as _i9; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i8; -import 'package:wger/providers/ingredient_repository.dart' as _i10; -import 'package:wger/providers/measurement_repository.dart' as _i3; -import 'package:wger/providers/nutrition_repository.dart' as _i7; +import 'package:wger/models/measurements/measurement_category.dart' as _i4; +import 'package:wger/models/measurements/measurement_entry.dart' as _i5; +import 'package:wger/models/nutrition/ingredient.dart' as _i12; +import 'package:wger/models/nutrition/log.dart' as _i10; +import 'package:wger/models/nutrition/meal.dart' as _i8; +import 'package:wger/models/nutrition/meal_item.dart' as _i9; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i7; +import 'package:wger/providers/ingredient_repository.dart' as _i11; +import 'package:wger/providers/measurement_repository.dart' as _i2; +import 'package:wger/providers/nutrition_repository.dart' as _i6; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -31,267 +32,266 @@ import 'package:wger/providers/nutrition_repository.dart' as _i7; // ignore_for_file: subtype_of_sealed_class // ignore_for_file: invalid_use_of_internal_member -class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); -} - /// A class which mocks [MeasurementRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockMeasurementRepository extends _i1.Mock implements _i3.MeasurementRepository { +class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepository { MockMeasurementRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream> watchAll() => + _i3.Stream> watchAll() => (super.noSuchMethod( Invocation.method(#watchAll, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Stream<_i5.MeasurementCategory?> watchLocalDriftCategoryById( + _i3.Stream<_i4.MeasurementCategory?> watchLocalDriftCategoryById( String? id, ) => (super.noSuchMethod( Invocation.method(#watchLocalDriftCategoryById, [id]), - returnValue: _i4.Stream<_i5.MeasurementCategory?>.empty(), + returnValue: _i3.Stream<_i4.MeasurementCategory?>.empty(), ) - as _i4.Stream<_i5.MeasurementCategory?>); + as _i3.Stream<_i4.MeasurementCategory?>); @override - _i4.Future deleteLocalDrift(String? id) => + _i3.Future deleteLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future updateLocalDrift(_i6.MeasurementEntry? entry) => + _i3.Future updateLocalDrift(_i5.MeasurementEntry? entry) => (super.noSuchMethod( Invocation.method(#updateLocalDrift, [entry]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future addLocalDrift(_i6.MeasurementEntry? entry) => + _i3.Future addLocalDrift(_i5.MeasurementEntry? entry) => (super.noSuchMethod( Invocation.method(#addLocalDrift, [entry]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLocalDriftCategory(String? id) => + _i3.Future deleteLocalDriftCategory(String? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDriftCategory, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future updateLocalDriftCategory( - _i5.MeasurementCategory? category, + _i3.Future updateLocalDriftCategory( + _i4.MeasurementCategory? category, ) => (super.noSuchMethod( Invocation.method(#updateLocalDriftCategory, [category]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future addLocalDriftCategory(_i5.MeasurementCategory? category) => + _i3.Future addLocalDriftCategory(_i4.MeasurementCategory? category) => (super.noSuchMethod( Invocation.method(#addLocalDriftCategory, [category]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); } /// A class which mocks [NutritionRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepository { +class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepository { MockNutritionRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Future> fetchPlanSparse(int? planId) => + _i3.Future> fetchPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanSparse, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> fetchPlanFull(int? planId) => + _i3.Future> fetchPlanFull(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanFull, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> createPlan(Map? data) => + _i3.Future> createPlan(Map? data) => (super.noSuchMethod( Invocation.method(#createPlan, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Stream> watchAllDrift() => + _i3.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future editLocalDrift(_i8.NutritionalPlan? plan) => + _i3.Future editLocalDrift(_i7.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method(#editLocalDrift, [plan]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLocalDrift(int? id) => + _i3.Future deleteLocalDrift(int? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future> createMeal(Map? data) => + _i3.Future> createMeal(Map? data) => (super.noSuchMethod( Invocation.method(#createMeal, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> updateMeal( - int? id, - Map? data, - ) => + _i3.Future editMealLocalDrift(_i8.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i4.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future>); + as _i3.Future); @override - _i4.Future<_i2.Response> deleteMeal(int? id) => + _i3.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Future> createMealItem(Map? data) => + _i3.Future> createMealItem(Map? data) => (super.noSuchMethod( Invocation.method(#createMealItem, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i2.Response> deleteMealItem(int? id) => + _i3.Future editMealItemLocalDrift(_i9.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Stream> watchAllLogsHydrated() => + _i3.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); + + @override + _i3.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future addLogLocalDrift(_i9.LogItem? log) => + _i3.Future addLogLocalDrift(_i10.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLogLocalDrift(String? id) => + _i3.Future deleteLogLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLogLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); } /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i10.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i11.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i11.Ingredient?> watchById(int? id) => + _i3.Stream<_i12.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i11.Ingredient?>.empty(), + returnValue: _i3.Stream<_i12.Ingredient?>.empty(), ) - as _i4.Stream<_i11.Ingredient?>); + as _i3.Stream<_i12.Ingredient?>); @override - _i4.Future<_i11.Ingredient?> getById(int? id) => + _i3.Future<_i12.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i11.Ingredient?>.value(), + returnValue: _i3.Future<_i12.Ingredient?>.value(), ) - as _i4.Future<_i11.Ingredient?>); + as _i3.Future<_i12.Ingredient?>); @override - _i4.Future> searchIngredientLocal( + _i3.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i11.NutriScore? nutriscoreMax, + _i12.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -305,20 +305,20 @@ class MockIngredientRepository extends _i1.Mock implements _i10.IngredientReposi #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i11.Ingredient>[], + returnValue: _i3.Future>.value( + <_i12.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> searchIngredientServer( + _i3.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i10.IngredientSearchLanguage? searchLanguage = _i10.IngredientSearchLanguage.current, + _i11.IngredientSearchLanguage? searchLanguage = _i11.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i11.NutriScore? nutriscoreMax, + _i12.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -332,17 +332,17 @@ class MockIngredientRepository extends _i1.Mock implements _i10.IngredientReposi #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i4.Future>.value( - <_i11.Ingredient>[], + returnValue: _i3.Future>.value( + <_i12.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i11.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i3.Future<_i12.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i4.Future<_i11.Ingredient?>.value(), + returnValue: _i3.Future<_i12.Ingredient?>.value(), ) - as _i4.Future<_i11.Ingredient?>); + as _i3.Future<_i12.Ingredient?>); } diff --git a/test/nutrition/nutrition_provider_test.dart b/test/nutrition/nutrition_provider_test.dart index e1561eaa1..87b459580 100644 --- a/test/nutrition/nutrition_provider_test.dart +++ b/test/nutrition/nutrition_provider_test.dart @@ -23,6 +23,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:wger/models/nutrition/ingredient.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/ingredient_repository.dart'; import 'package:wger/providers/nutrition_notifier.dart'; @@ -83,6 +85,10 @@ void main() { // Edit + delete now go through Drift instead of REST. when(mockRepo.editLocalDrift(any)).thenAnswer((_) async => Future.value()); when(mockRepo.deleteLocalDrift(any)).thenAnswer((_) async => Future.value()); + when(mockRepo.editMealLocalDrift(any)).thenAnswer((_) async => Future.value()); + when(mockRepo.deleteMealLocalDrift(any)).thenAnswer((_) async => Future.value()); + when(mockRepo.editMealItemLocalDrift(any)).thenAnswer((_) async => Future.value()); + when(mockRepo.deleteMealItemLocalDrift(any)).thenAnswer((_) async => Future.value()); nutritionalPlanInfoResponse = jsonDecode( fixture('nutrition/nutritional_plan_info_detail_response.json'), @@ -294,4 +300,61 @@ void main() { verify(mockRepo.deleteLocalDrift(1)).called(1); }); }); + + group('meal write operations', () { + test('editMeal delegates to editMealLocalDrift (PowerSync), not REST', () async { + final meal = Meal(id: 5, plan: 1, name: 'breakfast'); + final container = makeContainer(); + + await container.read(nutritionProvider.notifier).editMeal(meal); + + verify(mockRepo.editMealLocalDrift(meal)).called(1); + }); + + test('deleteMeal delegates to deleteMealLocalDrift and updates state', () async { + final meal = Meal(id: 5, plan: 7, name: 'breakfast'); + final plan = NutritionalPlan( + id: 7, + description: 'plan', + startDate: now, + creationDate: now, + )..meals = [meal]; + final container = await containerWithPlans([plan]); + + await container.read(nutritionProvider.notifier).deleteMeal(meal); + + verify(mockRepo.deleteMealLocalDrift(5)).called(1); + final plans = container.read(nutritionProvider).value?.plans ?? const []; + expect(plans.single.meals, isEmpty); + }); + }); + + group('meal item write operations', () { + test('editMealItem delegates to editMealItemLocalDrift (PowerSync)', () async { + final item = MealItem(id: 9, mealId: 5, ingredientId: 1, amount: 100); + final container = makeContainer(); + + await container.read(nutritionProvider.notifier).editMealItem(item); + + verify(mockRepo.editMealItemLocalDrift(item)).called(1); + }); + + test('deleteMealItem delegates to deleteMealItemLocalDrift and updates state', () async { + final item = MealItem(id: 9, mealId: 5, ingredientId: 1, amount: 100); + final meal = Meal(id: 5, plan: 7, name: 'breakfast')..mealItems = [item]; + final plan = NutritionalPlan( + id: 7, + description: 'plan', + startDate: now, + creationDate: now, + )..meals = [meal]; + final container = await containerWithPlans([plan]); + + await container.read(nutritionProvider.notifier).deleteMealItem(item); + + verify(mockRepo.deleteMealItemLocalDrift(9)).called(1); + final plans = container.read(nutritionProvider).value?.plans ?? const []; + expect(plans.single.meals.single.mealItems, isEmpty); + }); + }); } diff --git a/test/nutrition/nutrition_provider_test.mocks.dart b/test/nutrition/nutrition_provider_test.mocks.dart index 09467aec4..e92ff7bfb 100644 --- a/test/nutrition/nutrition_provider_test.mocks.dart +++ b/test/nutrition/nutrition_provider_test.mocks.dart @@ -3,15 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; +import 'dart:async' as _i3; -import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i8; -import 'package:wger/models/nutrition/log.dart' as _i6; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; -import 'package:wger/providers/ingredient_repository.dart' as _i7; -import 'package:wger/providers/nutrition_repository.dart' as _i3; +import 'package:wger/models/nutrition/ingredient.dart' as _i9; +import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:wger/models/nutrition/meal.dart' as _i5; +import 'package:wger/models/nutrition/meal_item.dart' as _i6; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; +import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/nutrition_repository.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -28,184 +29,183 @@ import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: subtype_of_sealed_class // ignore_for_file: invalid_use_of_internal_member -class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); -} - /// A class which mocks [NutritionRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepository { +class MockNutritionRepository extends _i1.Mock implements _i2.NutritionRepository { MockNutritionRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Future> fetchPlanSparse(int? planId) => + _i3.Future> fetchPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanSparse, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> fetchPlanFull(int? planId) => + _i3.Future> fetchPlanFull(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanFull, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> createPlan(Map? data) => + _i3.Future> createPlan(Map? data) => (super.noSuchMethod( Invocation.method(#createPlan, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Stream> watchAllDrift() => + _i3.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future editLocalDrift(_i5.NutritionalPlan? plan) => + _i3.Future editLocalDrift(_i4.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method(#editLocalDrift, [plan]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLocalDrift(int? id) => + _i3.Future deleteLocalDrift(int? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future> createMeal(Map? data) => + _i3.Future> createMeal(Map? data) => (super.noSuchMethod( Invocation.method(#createMeal, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> updateMeal( - int? id, - Map? data, - ) => + _i3.Future editMealLocalDrift(_i5.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i4.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future>); + as _i3.Future); @override - _i4.Future<_i2.Response> deleteMeal(int? id) => + _i3.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Future> createMealItem(Map? data) => + _i3.Future> createMealItem(Map? data) => (super.noSuchMethod( Invocation.method(#createMealItem, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i2.Response> deleteMealItem(int? id) => + _i3.Future editMealItemLocalDrift(_i6.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Stream> watchAllLogsHydrated() => + _i3.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); + + @override + _i3.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future addLogLocalDrift(_i6.LogItem? log) => + _i3.Future addLogLocalDrift(_i7.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLogLocalDrift(String? id) => + _i3.Future deleteLogLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLogLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); } /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i8.Ingredient?> watchById(int? id) => + _i3.Stream<_i9.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i8.Ingredient?>.empty(), + returnValue: _i3.Stream<_i9.Ingredient?>.empty(), ) - as _i4.Stream<_i8.Ingredient?>); + as _i3.Stream<_i9.Ingredient?>); @override - _i4.Future<_i8.Ingredient?> getById(int? id) => + _i3.Future<_i9.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i3.Future<_i9.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i3.Future<_i9.Ingredient?>); @override - _i4.Future> searchIngredientLocal( + _i3.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -219,20 +219,20 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i3.Future>.value( + <_i9.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> searchIngredientServer( + _i3.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -246,17 +246,17 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i3.Future>.value( + <_i9.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i3.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i3.Future<_i9.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i3.Future<_i9.Ingredient?>); } diff --git a/test/nutrition/nutrition_repository_test.dart b/test/nutrition/nutrition_repository_test.dart index 4e0a53529..a32f21038 100644 --- a/test/nutrition/nutrition_repository_test.dart +++ b/test/nutrition/nutrition_repository_test.dart @@ -16,12 +16,14 @@ * along with this program. If not, see . */ +import 'package:drift/drift.dart' as drift; import 'package:flutter_test/flutter_test.dart'; -import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:wger/database/powersync/database.dart'; import 'package:wger/models/nutrition/log.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/base_provider.dart'; import 'package:wger/providers/nutrition_repository.dart'; @@ -121,6 +123,38 @@ void main() { ); } + Future seedMeal({required int id, required int planId, String name = ''}) async { + await db + .into(db.mealTable) + .insert( + MealTableCompanion.insert( + id: id, + planId: planId, + order: 1, + name: drift.Value(name), + ), + ); + } + + Future seedMealItem({ + required int id, + required int mealId, + required int ingredientId, + double amount = 100, + }) async { + await db + .into(db.mealItemTable) + .insert( + MealItemTableCompanion.insert( + id: id, + mealId: mealId, + ingredientId: ingredientId, + order: 1, + amount: amount, + ), + ); + } + // --------------------------------------------------------------------------- group('Plans — REST', () { @@ -203,7 +237,7 @@ void main() { }); }); - group('Meals — REST', () { + group('Meals', () { test('createMeal POSTs to /meal/', () async { final uri = Uri.https('localhost', 'api/v2/meal/'); when(mockBase.makeUrl('meal')).thenReturn(uri); @@ -214,26 +248,37 @@ void main() { verify(mockBase.post({'name': 'breakfast'}, uri)).called(1); }); - test('updateMeal PATCHes /meal//', () async { - final uri = Uri.https('localhost', 'api/v2/meal/5/'); - when(mockBase.makeUrl('meal', id: 5)).thenReturn(uri); - when(mockBase.patch(any, uri)).thenAnswer((_) async => {'id': 5}); + test('editMealLocalDrift overwrites the meal with matching id', () async { + await seedPlan(id: 1); + await seedMeal(id: 5, planId: 1, name: 'breakfast'); - await repo.updateMeal(5, {'name': 'lunch'}); + final updated = Meal(id: 5, plan: 1, name: 'lunch'); + await repo.editMealLocalDrift(updated); - verify(mockBase.patch({'name': 'lunch'}, uri)).called(1); + final row = await (db.select( + db.mealTable, + )..where((t) => t.id.equals(5))).getSingle(); + expect(row.name, 'lunch'); }); - test('deleteMeal sends a DELETE for /meal//', () async { - when(mockBase.deleteRequest('meal', 5)).thenAnswer((_) async => http.Response('', 204)); + test('editMealLocalDrift throws StateError when id is null', () async { + final meal = Meal(plan: 1, name: 'no id'); + expect(() => repo.editMealLocalDrift(meal), throwsStateError); + }); - await repo.deleteMeal(5); + test('deleteMealLocalDrift removes the meal with matching id', () async { + await seedPlan(id: 1); + await seedMeal(id: 5, planId: 1); + await seedMeal(id: 6, planId: 1); - verify(mockBase.deleteRequest('meal', 5)).called(1); + await repo.deleteMealLocalDrift(5); + + final remaining = await db.select(db.mealTable).get(); + expect(remaining.map((m) => m.id), [6]); }); }); - group('Meal items — REST', () { + group('Meal items', () { test('createMealItem POSTs to /mealitem/', () async { final uri = Uri.https('localhost', 'api/v2/mealitem/'); when(mockBase.makeUrl('mealitem')).thenReturn(uri); @@ -244,14 +289,37 @@ void main() { verify(mockBase.post({'meal': 1, 'amount': 100}, uri)).called(1); }); - test('deleteMealItem sends a DELETE for /mealitem//', () async { - when( - mockBase.deleteRequest('mealitem', 7), - ).thenAnswer((_) async => http.Response('', 204)); + test('editMealItemLocalDrift overwrites the item with matching id', () async { + await seedPlan(id: 1); + await seedMeal(id: 1, planId: 1); + await seedIngredient(id: 1, name: 'Apple'); + await seedMealItem(id: 7, mealId: 1, ingredientId: 1, amount: 100); - await repo.deleteMealItem(7); + final updated = MealItem(id: 7, mealId: 1, ingredientId: 1, amount: 250); + await repo.editMealItemLocalDrift(updated); - verify(mockBase.deleteRequest('mealitem', 7)).called(1); + final row = await (db.select( + db.mealItemTable, + )..where((t) => t.id.equals(7))).getSingle(); + expect(row.amount, 250); + }); + + test('editMealItemLocalDrift throws StateError when id is null', () async { + final item = MealItem(mealId: 1, ingredientId: 1, amount: 50); + expect(() => repo.editMealItemLocalDrift(item), throwsStateError); + }); + + test('deleteMealItemLocalDrift removes the item with matching id', () async { + await seedPlan(id: 1); + await seedMeal(id: 1, planId: 1); + await seedIngredient(id: 1, name: 'Apple'); + await seedMealItem(id: 7, mealId: 1, ingredientId: 1); + await seedMealItem(id: 8, mealId: 1, ingredientId: 1); + + await repo.deleteMealItemLocalDrift(7); + + final remaining = await db.select(db.mealItemTable).get(); + expect(remaining.map((m) => m.id), [8]); }); }); diff --git a/test/nutrition/nutritional_meal_form_test.dart b/test/nutrition/nutritional_meal_form_test.dart index 8b990b98e..5b9967082 100644 --- a/test/nutrition/nutritional_meal_form_test.dart +++ b/test/nutrition/nutritional_meal_form_test.dart @@ -53,7 +53,7 @@ void main() { mockRepo = MockNutritionRepository(); mockIngredientRepo = MockIngredientRepository(); - when(mockRepo.updateMeal(any, any)).thenAnswer((_) async => Meal(id: 1, plan: 1).toJson()); + when(mockRepo.editMealLocalDrift(any)).thenAnswer((_) async => Future.value()); when(mockRepo.createMeal(any)).thenAnswer((_) async => Meal(id: 99, plan: 1).toJson()); // NutritionNotifier.build() subscribes to two Drift streams (plans + // diary entries) — emit the seed plan and an empty diary so the @@ -126,7 +126,7 @@ void main() { await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); // Correct method was called - verify(mockRepo.updateMeal(any, any)); + verify(mockRepo.editMealLocalDrift(any)); verifyNever(mockRepo.createMeal(any)); }); @@ -165,7 +165,7 @@ void main() { await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); // Correct method was called - verifyNever(mockRepo.updateMeal(any, any)); + verifyNever(mockRepo.editMealLocalDrift(any)); verify(mockRepo.createMeal(any)); }); @@ -173,7 +173,7 @@ void main() { // ... }); - testWidgets('Submit is disabled when offline and updateMeal is not called', ( + testWidgets('Submit is disabled offline only when creating a new meal', ( WidgetTester tester, ) async { // Build a fresh container that overrides the network status to offline. @@ -185,9 +185,33 @@ void main() { ], ); addTearDown(offlineContainer.dispose); - // The button is disabled offline — submit never fires, so we don't - // need to wait for the Drift-stream emission to populate the plan. + // 1) Creating a new meal offline: button must be disabled (REST POST). + final newMeal = Meal(time: const TimeOfDay(hour: 8, minute: 0)); + await tester.pumpWidget( + UncontrolledProviderScope( + container: offlineContainer, + child: MaterialApp( + locale: const Locale('en'), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Scaffold(body: MealForm(1, newMeal)), + ), + ), + ); + await tester.pumpAndSettle(); + + final createButton = tester.widget( + find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), + ); + expect(createButton.onPressed, isNull); + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), warnIfMissed: false); + await tester.pump(); + verifyNever(mockRepo.createMeal(any)); + verifyNever(mockRepo.editMealLocalDrift(any)); + + // 2) Editing an existing meal offline: PowerSync handles it locally, + // so the button must remain enabled. await tester.pumpWidget( UncontrolledProviderScope( container: offlineContainer, @@ -200,15 +224,13 @@ void main() { ), ); await tester.pumpAndSettle(); - - final button = tester.widget( + final editButton = tester.widget( find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), ); - expect(button.onPressed, isNull); + expect(editButton.onPressed, isNotNull); - await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), warnIfMissed: false); + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); await tester.pump(); - verifyNever(mockRepo.updateMeal(any, any)); - verifyNever(mockRepo.createMeal(any)); + verify(mockRepo.editMealLocalDrift(any)).called(1); }); } diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index 27bbaa0bc..b0e041445 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -3,15 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; +import 'dart:async' as _i3; -import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i8; -import 'package:wger/models/nutrition/log.dart' as _i6; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; -import 'package:wger/providers/ingredient_repository.dart' as _i7; -import 'package:wger/providers/nutrition_repository.dart' as _i3; +import 'package:wger/models/nutrition/ingredient.dart' as _i9; +import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:wger/models/nutrition/meal.dart' as _i5; +import 'package:wger/models/nutrition/meal_item.dart' as _i6; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; +import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/nutrition_repository.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -28,184 +29,183 @@ import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: subtype_of_sealed_class // ignore_for_file: invalid_use_of_internal_member -class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); -} - /// A class which mocks [NutritionRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepository { +class MockNutritionRepository extends _i1.Mock implements _i2.NutritionRepository { MockNutritionRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Future> fetchPlanSparse(int? planId) => + _i3.Future> fetchPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanSparse, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> fetchPlanFull(int? planId) => + _i3.Future> fetchPlanFull(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanFull, [planId]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> createPlan(Map? data) => + _i3.Future> createPlan(Map? data) => (super.noSuchMethod( Invocation.method(#createPlan, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Stream> watchAllDrift() => + _i3.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future editLocalDrift(_i5.NutritionalPlan? plan) => + _i3.Future editLocalDrift(_i4.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method(#editLocalDrift, [plan]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLocalDrift(int? id) => + _i3.Future deleteLocalDrift(int? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future> createMeal(Map? data) => + _i3.Future> createMeal(Map? data) => (super.noSuchMethod( Invocation.method(#createMeal, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> updateMeal( - int? id, - Map? data, - ) => + _i3.Future editMealLocalDrift(_i5.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i4.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future>); + as _i3.Future); @override - _i4.Future<_i2.Response> deleteMeal(int? id) => + _i3.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Future> createMealItem(Map? data) => + _i3.Future> createMealItem(Map? data) => (super.noSuchMethod( Invocation.method(#createMealItem, [data]), - returnValue: _i4.Future>.value( + returnValue: _i3.Future>.value( {}, ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i2.Response> deleteMealItem(int? id) => + _i3.Future editMealItemLocalDrift(_i6.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i3.Future); @override - _i4.Stream> watchAllLogsHydrated() => + _i3.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); + + @override + _i3.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i3.Stream>.empty(), ) - as _i4.Stream>); + as _i3.Stream>); @override - _i4.Future addLogLocalDrift(_i6.LogItem? log) => + _i3.Future addLogLocalDrift(_i7.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); @override - _i4.Future deleteLogLocalDrift(String? id) => + _i3.Future deleteLogLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLogLocalDrift, [id]), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), ) - as _i4.Future); + as _i3.Future); } /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i8.Ingredient?> watchById(int? id) => + _i3.Stream<_i9.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i8.Ingredient?>.empty(), + returnValue: _i3.Stream<_i9.Ingredient?>.empty(), ) - as _i4.Stream<_i8.Ingredient?>); + as _i3.Stream<_i9.Ingredient?>); @override - _i4.Future<_i8.Ingredient?> getById(int? id) => + _i3.Future<_i9.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i3.Future<_i9.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i3.Future<_i9.Ingredient?>); @override - _i4.Future> searchIngredientLocal( + _i3.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -219,20 +219,20 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i3.Future>.value( + <_i9.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future> searchIngredientServer( + _i3.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -246,17 +246,17 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i3.Future>.value( + <_i9.Ingredient>[], ), ) - as _i4.Future>); + as _i3.Future>); @override - _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i3.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i3.Future<_i9.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i3.Future<_i9.Ingredient?>); } diff --git a/test/nutrition/nutritional_plan_screen_test.mocks.dart b/test/nutrition/nutritional_plan_screen_test.mocks.dart index 8a2063ac6..d2285a434 100644 --- a/test/nutrition/nutritional_plan_screen_test.mocks.dart +++ b/test/nutrition/nutritional_plan_screen_test.mocks.dart @@ -4,18 +4,20 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i4; -import 'dart:convert' as _i9; -import 'dart:typed_data' as _i11; +import 'dart:convert' as _i11; +import 'dart:typed_data' as _i13; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i10; -import 'package:wger/models/body_weight/weight_entry.dart' as _i13; -import 'package:wger/models/nutrition/ingredient.dart' as _i8; -import 'package:wger/models/nutrition/log.dart' as _i6; +import 'package:mockito/src/dummies.dart' as _i12; +import 'package:wger/models/body_weight/weight_entry.dart' as _i15; +import 'package:wger/models/nutrition/ingredient.dart' as _i10; +import 'package:wger/models/nutrition/log.dart' as _i8; +import 'package:wger/models/nutrition/meal.dart' as _i6; +import 'package:wger/models/nutrition/meal_item.dart' as _i7; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; -import 'package:wger/providers/body_weight_repository.dart' as _i12; -import 'package:wger/providers/ingredient_repository.dart' as _i7; +import 'package:wger/providers/body_weight_repository.dart' as _i14; +import 'package:wger/providers/ingredient_repository.dart' as _i9; import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: type=lint @@ -117,27 +119,22 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor as _i4.Future>); @override - _i4.Future> updateMeal( - int? id, - Map? data, - ) => + _i4.Future editMealLocalDrift(_i6.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i4.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i4.Future>); + as _i4.Future); @override - _i4.Future<_i2.Response> deleteMeal(int? id) => + _i4.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i4.Future); @override _i4.Future> createMealItem(Map? data) => @@ -150,25 +147,33 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor as _i4.Future>); @override - _i4.Future<_i2.Response> deleteMealItem(int? id) => + _i4.Future editMealItemLocalDrift(_i7.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i4.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i4.Future<_i2.Response>); + as _i4.Future); @override - _i4.Stream> watchAllLogsHydrated() => + _i4.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) + as _i4.Future); + + @override + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override - _i4.Future addLogLocalDrift(_i6.LogItem? log) => + _i4.Future addLogLocalDrift(_i8.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i4.Future.value(), @@ -189,33 +194,33 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i8.Ingredient?> watchById(int? id) => + _i4.Stream<_i10.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i8.Ingredient?>.empty(), + returnValue: _i4.Stream<_i10.Ingredient?>.empty(), ) - as _i4.Stream<_i8.Ingredient?>); + as _i4.Stream<_i10.Ingredient?>); @override - _i4.Future<_i8.Ingredient?> getById(int? id) => + _i4.Future<_i10.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i4.Future<_i10.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i4.Future<_i10.Ingredient?>); @override - _i4.Future> searchIngredientLocal( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i10.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -229,20 +234,20 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i4.Future>.value( + <_i10.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); @override - _i4.Future> searchIngredientServer( + _i4.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + _i9.IngredientSearchLanguage? searchLanguage = _i9.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i8.NutriScore? nutriscoreMax, + _i10.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -256,19 +261,19 @@ class MockIngredientRepository extends _i1.Mock implements _i7.IngredientReposit #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i4.Future>.value( - <_i8.Ingredient>[], + returnValue: _i4.Future>.value( + <_i10.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); @override - _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i4.Future<_i10.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i4.Future<_i8.Ingredient?>.value(), + returnValue: _i4.Future<_i10.Ingredient?>.value(), ) - as _i4.Future<_i8.Ingredient?>); + as _i4.Future<_i10.Ingredient?>); } /// A class which mocks [Client]. @@ -310,7 +315,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i9.Encoding? encoding, + _i11.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -336,7 +341,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i9.Encoding? encoding, + _i11.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -362,7 +367,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i9.Encoding? encoding, + _i11.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -388,7 +393,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i9.Encoding? encoding, + _i11.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -414,7 +419,7 @@ class MockClient extends _i1.Mock implements _i2.Client { (super.noSuchMethod( Invocation.method(#read, [url], {#headers: headers}), returnValue: _i4.Future.value( - _i10.dummyValue( + _i12.dummyValue( this, Invocation.method(#read, [url], {#headers: headers}), ), @@ -423,15 +428,15 @@ class MockClient extends _i1.Mock implements _i2.Client { as _i4.Future); @override - _i4.Future<_i11.Uint8List> readBytes( + _i4.Future<_i13.Uint8List> readBytes( Uri? url, { Map? headers, }) => (super.noSuchMethod( Invocation.method(#readBytes, [url], {#headers: headers}), - returnValue: _i4.Future<_i11.Uint8List>.value(_i11.Uint8List(0)), + returnValue: _i4.Future<_i13.Uint8List>.value(_i13.Uint8List(0)), ) - as _i4.Future<_i11.Uint8List>); + as _i4.Future<_i13.Uint8List>); @override _i4.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => @@ -456,18 +461,18 @@ class MockClient extends _i1.Mock implements _i2.Client { /// A class which mocks [BodyWeightRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightRepository { +class MockBodyWeightRepository extends _i1.Mock implements _i14.BodyWeightRepository { MockBodyWeightRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream> watchAllDrift() => + _i4.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override _i4.Future deleteLocalDrift(String? id) => @@ -479,7 +484,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightReposi as _i4.Future); @override - _i4.Future updateLocalDrift(_i13.WeightEntry? entry) => + _i4.Future updateLocalDrift(_i15.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#updateLocalDrift, [entry]), returnValue: _i4.Future.value(), @@ -488,7 +493,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightReposi as _i4.Future); @override - _i4.Future addLocalDrift(_i13.WeightEntry? entry) => + _i4.Future addLocalDrift(_i15.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#addLocalDrift, [entry]), returnValue: _i4.Future.value(), diff --git a/test/nutrition/nutritional_plans_screen_test.mocks.dart b/test/nutrition/nutritional_plans_screen_test.mocks.dart index b4d7d3b34..98fe246f2 100644 --- a/test/nutrition/nutritional_plans_screen_test.mocks.dart +++ b/test/nutrition/nutritional_plans_screen_test.mocks.dart @@ -4,21 +4,23 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i5; -import 'dart:convert' as _i10; -import 'dart:typed_data' as _i12; +import 'dart:convert' as _i12; +import 'dart:typed_data' as _i14; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i11; -import 'package:wger/models/body_weight/weight_entry.dart' as _i14; -import 'package:wger/models/nutrition/ingredient.dart' as _i9; -import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:mockito/src/dummies.dart' as _i13; +import 'package:wger/models/body_weight/weight_entry.dart' as _i16; +import 'package:wger/models/nutrition/ingredient.dart' as _i11; +import 'package:wger/models/nutrition/log.dart' as _i9; +import 'package:wger/models/nutrition/meal.dart' as _i7; +import 'package:wger/models/nutrition/meal_item.dart' as _i8; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6; import 'package:wger/models/user/profile.dart' as _i3; -import 'package:wger/providers/body_weight_repository.dart' as _i13; -import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/body_weight_repository.dart' as _i15; +import 'package:wger/providers/ingredient_repository.dart' as _i10; import 'package:wger/providers/nutrition_repository.dart' as _i4; -import 'package:wger/providers/user_profile_repository.dart' as _i15; +import 'package:wger/providers/user_profile_repository.dart' as _i17; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -123,27 +125,22 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor as _i5.Future>); @override - _i5.Future> updateMeal( - int? id, - Map? data, - ) => + _i5.Future editMealLocalDrift(_i7.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i5.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), ) - as _i5.Future>); + as _i5.Future); @override - _i5.Future<_i2.Response> deleteMeal(int? id) => + _i5.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i5.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), ) - as _i5.Future<_i2.Response>); + as _i5.Future); @override _i5.Future> createMealItem(Map? data) => @@ -156,25 +153,33 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor as _i5.Future>); @override - _i5.Future<_i2.Response> deleteMealItem(int? id) => + _i5.Future editMealItemLocalDrift(_i8.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i5.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), ) - as _i5.Future<_i2.Response>); + as _i5.Future); @override - _i5.Stream> watchAllLogsHydrated() => + _i5.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) + as _i5.Future); + + @override + _i5.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i5.Stream>.empty(), ) - as _i5.Stream>); + as _i5.Stream>); @override - _i5.Future addLogLocalDrift(_i7.LogItem? log) => + _i5.Future addLogLocalDrift(_i9.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i5.Future.value(), @@ -195,33 +200,33 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i10.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream<_i9.Ingredient?> watchById(int? id) => + _i5.Stream<_i11.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i5.Stream<_i9.Ingredient?>.empty(), + returnValue: _i5.Stream<_i11.Ingredient?>.empty(), ) - as _i5.Stream<_i9.Ingredient?>); + as _i5.Stream<_i11.Ingredient?>); @override - _i5.Future<_i9.Ingredient?> getById(int? id) => + _i5.Future<_i11.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i5.Future<_i9.Ingredient?>.value(), + returnValue: _i5.Future<_i11.Ingredient?>.value(), ) - as _i5.Future<_i9.Ingredient?>); + as _i5.Future<_i11.Ingredient?>); @override - _i5.Future> searchIngredientLocal( + _i5.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, + _i11.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -235,20 +240,20 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #limit: limit, }, ), - returnValue: _i5.Future>.value( - <_i9.Ingredient>[], + returnValue: _i5.Future>.value( + <_i11.Ingredient>[], ), ) - as _i5.Future>); + as _i5.Future>); @override - _i5.Future> searchIngredientServer( + _i5.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, + _i10.IngredientSearchLanguage? searchLanguage = _i10.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, + _i11.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -262,19 +267,19 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i5.Future>.value( - <_i9.Ingredient>[], + returnValue: _i5.Future>.value( + <_i11.Ingredient>[], ), ) - as _i5.Future>); + as _i5.Future>); @override - _i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i5.Future<_i11.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i5.Future<_i9.Ingredient?>.value(), + returnValue: _i5.Future<_i11.Ingredient?>.value(), ) - as _i5.Future<_i9.Ingredient?>); + as _i5.Future<_i11.Ingredient?>); } /// A class which mocks [Client]. @@ -316,7 +321,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i10.Encoding? encoding, + _i12.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -342,7 +347,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i10.Encoding? encoding, + _i12.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -368,7 +373,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i10.Encoding? encoding, + _i12.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -394,7 +399,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i10.Encoding? encoding, + _i12.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -420,7 +425,7 @@ class MockClient extends _i1.Mock implements _i2.Client { (super.noSuchMethod( Invocation.method(#read, [url], {#headers: headers}), returnValue: _i5.Future.value( - _i11.dummyValue( + _i13.dummyValue( this, Invocation.method(#read, [url], {#headers: headers}), ), @@ -429,15 +434,15 @@ class MockClient extends _i1.Mock implements _i2.Client { as _i5.Future); @override - _i5.Future<_i12.Uint8List> readBytes( + _i5.Future<_i14.Uint8List> readBytes( Uri? url, { Map? headers, }) => (super.noSuchMethod( Invocation.method(#readBytes, [url], {#headers: headers}), - returnValue: _i5.Future<_i12.Uint8List>.value(_i12.Uint8List(0)), + returnValue: _i5.Future<_i14.Uint8List>.value(_i14.Uint8List(0)), ) - as _i5.Future<_i12.Uint8List>); + as _i5.Future<_i14.Uint8List>); @override _i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => @@ -462,18 +467,18 @@ class MockClient extends _i1.Mock implements _i2.Client { /// A class which mocks [BodyWeightRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockBodyWeightRepository extends _i1.Mock implements _i13.BodyWeightRepository { +class MockBodyWeightRepository extends _i1.Mock implements _i15.BodyWeightRepository { MockBodyWeightRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream> watchAllDrift() => + _i5.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i5.Stream>.empty(), ) - as _i5.Stream>); + as _i5.Stream>); @override _i5.Future deleteLocalDrift(String? id) => @@ -485,7 +490,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i13.BodyWeightReposi as _i5.Future); @override - _i5.Future updateLocalDrift(_i14.WeightEntry? entry) => + _i5.Future updateLocalDrift(_i16.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#updateLocalDrift, [entry]), returnValue: _i5.Future.value(), @@ -494,7 +499,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i13.BodyWeightReposi as _i5.Future); @override - _i5.Future addLocalDrift(_i14.WeightEntry? entry) => + _i5.Future addLocalDrift(_i16.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#addLocalDrift, [entry]), returnValue: _i5.Future.value(), @@ -506,7 +511,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i13.BodyWeightReposi /// A class which mocks [UserProfileRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockUserProfileRepository extends _i1.Mock implements _i15.UserProfileRepository { +class MockUserProfileRepository extends _i1.Mock implements _i17.UserProfileRepository { MockUserProfileRepository() { _i1.throwOnMissingStub(this); } diff --git a/test/routine/routines_provider_repository_test.mocks.dart b/test/routine/routines_provider_repository_test.mocks.dart index 8ddae7dc7..499b1a6f4 100644 --- a/test/routine/routines_provider_repository_test.mocks.dart +++ b/test/routine/routines_provider_repository_test.mocks.dart @@ -201,101 +201,111 @@ class _Fake$IngredientWeightUnitTableTable_28 extends _i1.SmartFake ) : super(parent, parentInvocation); } -class _Fake$LogItemTableTable_29 extends _i1.SmartFake implements _i4.$LogItemTableTable { - _Fake$LogItemTableTable_29(Object parent, Invocation parentInvocation) +class _Fake$MealTableTable_29 extends _i1.SmartFake implements _i4.$MealTableTable { + _Fake$MealTableTable_29(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _Fake$GalleryImageTableTable_30 extends _i1.SmartFake implements _i4.$GalleryImageTableTable { - _Fake$GalleryImageTableTable_30(Object parent, Invocation parentInvocation) +class _Fake$MealItemTableTable_30 extends _i1.SmartFake implements _i4.$MealItemTableTable { + _Fake$MealItemTableTable_30(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeDriftDatabaseOptions_31 extends _i1.SmartFake implements _i3.DriftDatabaseOptions { - _FakeDriftDatabaseOptions_31(Object parent, Invocation parentInvocation) +class _Fake$LogItemTableTable_31 extends _i1.SmartFake implements _i4.$LogItemTableTable { + _Fake$LogItemTableTable_31(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeGeneratedDatabase_32 extends _i1.SmartFake implements _i3.GeneratedDatabase { - _FakeGeneratedDatabase_32(Object parent, Invocation parentInvocation) +class _Fake$GalleryImageTableTable_32 extends _i1.SmartFake implements _i4.$GalleryImageTableTable { + _Fake$GalleryImageTableTable_32(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeStreamQueryUpdateRules_33 extends _i1.SmartFake implements _i3.StreamQueryUpdateRules { - _FakeStreamQueryUpdateRules_33(Object parent, Invocation parentInvocation) +class _FakeDriftDatabaseOptions_33 extends _i1.SmartFake implements _i3.DriftDatabaseOptions { + _FakeDriftDatabaseOptions_33(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeDatabaseConnection_34 extends _i1.SmartFake implements _i3.DatabaseConnection { - _FakeDatabaseConnection_34(Object parent, Invocation parentInvocation) +class _FakeGeneratedDatabase_34 extends _i1.SmartFake implements _i3.GeneratedDatabase { + _FakeGeneratedDatabase_34(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeQueryExecutor_35 extends _i1.SmartFake implements _i3.QueryExecutor { - _FakeQueryExecutor_35(Object parent, Invocation parentInvocation) +class _FakeStreamQueryUpdateRules_35 extends _i1.SmartFake implements _i3.StreamQueryUpdateRules { + _FakeStreamQueryUpdateRules_35(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeStreamQueryStore_36 extends _i1.SmartFake implements _i5.StreamQueryStore { - _FakeStreamQueryStore_36(Object parent, Invocation parentInvocation) +class _FakeDatabaseConnection_36 extends _i1.SmartFake implements _i3.DatabaseConnection { + _FakeDatabaseConnection_36(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeDatabaseConnectionUser_37 extends _i1.SmartFake implements _i3.DatabaseConnectionUser { - _FakeDatabaseConnectionUser_37(Object parent, Invocation parentInvocation) +class _FakeQueryExecutor_37 extends _i1.SmartFake implements _i3.QueryExecutor { + _FakeQueryExecutor_37(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeMigrator_38 extends _i1.SmartFake implements _i3.Migrator { - _FakeMigrator_38(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +class _FakeStreamQueryStore_38 extends _i1.SmartFake implements _i5.StreamQueryStore { + _FakeStreamQueryStore_38(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeFuture_39 extends _i1.SmartFake implements _i6.Future { - _FakeFuture_39(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +class _FakeDatabaseConnectionUser_39 extends _i1.SmartFake implements _i3.DatabaseConnectionUser { + _FakeDatabaseConnectionUser_39(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeInsertStatement_40 extends _i1.SmartFake +class _FakeMigrator_40 extends _i1.SmartFake implements _i3.Migrator { + _FakeMigrator_40(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +} + +class _FakeFuture_41 extends _i1.SmartFake implements _i6.Future { + _FakeFuture_41(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +} + +class _FakeInsertStatement_42 extends _i1.SmartFake implements _i3.InsertStatement { - _FakeInsertStatement_40(Object parent, Invocation parentInvocation) + _FakeInsertStatement_42(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeUpdateStatement_41 extends _i1.SmartFake +class _FakeUpdateStatement_43 extends _i1.SmartFake implements _i3.UpdateStatement { - _FakeUpdateStatement_41(Object parent, Invocation parentInvocation) + _FakeUpdateStatement_43(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeSimpleSelectStatement_42 extends _i1.SmartFake +class _FakeSimpleSelectStatement_44 extends _i1.SmartFake implements _i3.SimpleSelectStatement { - _FakeSimpleSelectStatement_42(Object parent, Invocation parentInvocation) + _FakeSimpleSelectStatement_44(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeJoinedSelectStatement_43 extends _i1.SmartFake +class _FakeJoinedSelectStatement_45 extends _i1.SmartFake implements _i3.JoinedSelectStatement { - _FakeJoinedSelectStatement_43(Object parent, Invocation parentInvocation) + _FakeJoinedSelectStatement_45(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeBaseSelectStatement_44 extends _i1.SmartFake +class _FakeBaseSelectStatement_46 extends _i1.SmartFake implements _i3.BaseSelectStatement { - _FakeBaseSelectStatement_44(Object parent, Invocation parentInvocation) + _FakeBaseSelectStatement_46(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeDeleteStatement_45 extends _i1.SmartFake +class _FakeDeleteStatement_47 extends _i1.SmartFake implements _i3.DeleteStatement { - _FakeDeleteStatement_45(Object parent, Invocation parentInvocation) + _FakeDeleteStatement_47(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeSelectable_46 extends _i1.SmartFake implements _i3.Selectable { - _FakeSelectable_46(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +class _FakeSelectable_48 extends _i1.SmartFake implements _i3.Selectable { + _FakeSelectable_48(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeGenerationContext_47 extends _i1.SmartFake implements _i3.GenerationContext { - _FakeGenerationContext_47(Object parent, Invocation parentInvocation) +class _FakeGenerationContext_49 extends _i1.SmartFake implements _i3.GenerationContext { + _FakeGenerationContext_49(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } @@ -744,11 +754,33 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ) as _i4.$IngredientWeightUnitTableTable); + @override + _i4.$MealTableTable get mealTable => + (super.noSuchMethod( + Invocation.getter(#mealTable), + returnValue: _Fake$MealTableTable_29( + this, + Invocation.getter(#mealTable), + ), + ) + as _i4.$MealTableTable); + + @override + _i4.$MealItemTableTable get mealItemTable => + (super.noSuchMethod( + Invocation.getter(#mealItemTable), + returnValue: _Fake$MealItemTableTable_30( + this, + Invocation.getter(#mealItemTable), + ), + ) + as _i4.$MealItemTableTable); + @override _i4.$LogItemTableTable get logItemTable => (super.noSuchMethod( Invocation.getter(#logItemTable), - returnValue: _Fake$LogItemTableTable_29( + returnValue: _Fake$LogItemTableTable_31( this, Invocation.getter(#logItemTable), ), @@ -759,7 +791,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i4.$GalleryImageTableTable get galleryImageTable => (super.noSuchMethod( Invocation.getter(#galleryImageTable), - returnValue: _Fake$GalleryImageTableTable_30( + returnValue: _Fake$GalleryImageTableTable_32( this, Invocation.getter(#galleryImageTable), ), @@ -786,7 +818,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.DriftDatabaseOptions get options => (super.noSuchMethod( Invocation.getter(#options), - returnValue: _FakeDriftDatabaseOptions_31( + returnValue: _FakeDriftDatabaseOptions_33( this, Invocation.getter(#options), ), @@ -797,7 +829,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.GeneratedDatabase get attachedDatabase => (super.noSuchMethod( Invocation.getter(#attachedDatabase), - returnValue: _FakeGeneratedDatabase_32( + returnValue: _FakeGeneratedDatabase_34( this, Invocation.getter(#attachedDatabase), ), @@ -808,7 +840,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.StreamQueryUpdateRules get streamUpdateRules => (super.noSuchMethod( Invocation.getter(#streamUpdateRules), - returnValue: _FakeStreamQueryUpdateRules_33( + returnValue: _FakeStreamQueryUpdateRules_35( this, Invocation.getter(#streamUpdateRules), ), @@ -819,7 +851,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.DatabaseConnection get connection => (super.noSuchMethod( Invocation.getter(#connection), - returnValue: _FakeDatabaseConnection_34( + returnValue: _FakeDatabaseConnection_36( this, Invocation.getter(#connection), ), @@ -841,7 +873,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.QueryExecutor get executor => (super.noSuchMethod( Invocation.getter(#executor), - returnValue: _FakeQueryExecutor_35( + returnValue: _FakeQueryExecutor_37( this, Invocation.getter(#executor), ), @@ -852,7 +884,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i5.StreamQueryStore get streamQueries => (super.noSuchMethod( Invocation.getter(#streamQueries), - returnValue: _FakeStreamQueryStore_36( + returnValue: _FakeStreamQueryStore_38( this, Invocation.getter(#streamQueries), ), @@ -863,7 +895,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.DatabaseConnectionUser get resolvedEngine => (super.noSuchMethod( Invocation.getter(#resolvedEngine), - returnValue: _FakeDatabaseConnectionUser_37( + returnValue: _FakeDatabaseConnectionUser_39( this, Invocation.getter(#resolvedEngine), ), @@ -874,7 +906,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD _i3.Migrator createMigrator() => (super.noSuchMethod( Invocation.method(#createMigrator, []), - returnValue: _FakeMigrator_38( + returnValue: _FakeMigrator_40( this, Invocation.method(#createMigrator, []), ), @@ -923,7 +955,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ), (Ret v) => _i6.Future.value(v), ) ?? - _FakeFuture_39( + _FakeFuture_41( this, Invocation.method(#computeWithDatabase, [], { #computation: computation, @@ -990,7 +1022,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ), (T v) => _i6.Future.value(v), ) ?? - _FakeFuture_39(this, Invocation.method(#doWhenOpened, [fn])), + _FakeFuture_41(this, Invocation.method(#doWhenOpened, [fn])), ) as _i6.Future); @@ -1000,7 +1032,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ) => (super.noSuchMethod( Invocation.method(#into, [table]), - returnValue: _FakeInsertStatement_40( + returnValue: _FakeInsertStatement_42( this, Invocation.method(#into, [table]), ), @@ -1013,7 +1045,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ) => (super.noSuchMethod( Invocation.method(#update, [table]), - returnValue: _FakeUpdateStatement_41( + returnValue: _FakeUpdateStatement_43( this, Invocation.method(#update, [table]), ), @@ -1027,7 +1059,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD }) => (super.noSuchMethod( Invocation.method(#select, [table], {#distinct: distinct}), - returnValue: _FakeSimpleSelectStatement_42( + returnValue: _FakeSimpleSelectStatement_44( this, Invocation.method(#select, [table], {#distinct: distinct}), ), @@ -1041,7 +1073,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD }) => (super.noSuchMethod( Invocation.method(#selectOnly, [table], {#distinct: distinct}), - returnValue: _FakeJoinedSelectStatement_43( + returnValue: _FakeJoinedSelectStatement_45( this, Invocation.method(#selectOnly, [table], {#distinct: distinct}), ), @@ -1054,7 +1086,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ) => (super.noSuchMethod( Invocation.method(#selectExpressions, [columns]), - returnValue: _FakeBaseSelectStatement_44<_i3.TypedResult>( + returnValue: _FakeBaseSelectStatement_46<_i3.TypedResult>( this, Invocation.method(#selectExpressions, [columns]), ), @@ -1067,7 +1099,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ) => (super.noSuchMethod( Invocation.method(#delete, [table]), - returnValue: _FakeDeleteStatement_45( + returnValue: _FakeDeleteStatement_47( this, Invocation.method(#delete, [table]), ), @@ -1144,7 +1176,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD [query], {#variables: variables, #readsFrom: readsFrom}, ), - returnValue: _FakeSelectable_46<_i3.QueryRow>( + returnValue: _FakeSelectable_48<_i3.QueryRow>( this, Invocation.method( #customSelect, @@ -1167,7 +1199,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD [query], {#variables: variables, #readsFrom: readsFrom}, ), - returnValue: _FakeSelectable_46<_i3.QueryRow>( + returnValue: _FakeSelectable_48<_i3.QueryRow>( this, Invocation.method( #customSelectQuery, @@ -1210,7 +1242,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ), (T v) => _i6.Future.value(v), ) ?? - _FakeFuture_39( + _FakeFuture_41( this, Invocation.method( #transaction, @@ -1233,7 +1265,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ), (T v) => _i6.Future.value(v), ) ?? - _FakeFuture_39( + _FakeFuture_41( this, Invocation.method(#exclusively, [action]), ), @@ -1272,7 +1304,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD ), (T v) => _i6.Future.value(v), ) ?? - _FakeFuture_39( + _FakeFuture_41( this, Invocation.method( #runWithInterceptor, @@ -1295,7 +1327,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD [component], {#hasMultipleTables: hasMultipleTables, #startIndex: startIndex}, ), - returnValue: _FakeGenerationContext_47( + returnValue: _FakeGenerationContext_49( this, Invocation.method( #$write, @@ -1321,7 +1353,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD [table, insertable], {#startIndex: startIndex}, ), - returnValue: _FakeGenerationContext_47( + returnValue: _FakeGenerationContext_49( this, Invocation.method( #$writeInsertable, diff --git a/test/weight/weight_screen_test.mocks.dart b/test/weight/weight_screen_test.mocks.dart index da3792e07..50c5443c7 100644 --- a/test/weight/weight_screen_test.mocks.dart +++ b/test/weight/weight_screen_test.mocks.dart @@ -3,19 +3,20 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; +import 'dart:async' as _i4; -import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/body_weight/weight_entry.dart' as _i11; -import 'package:wger/models/nutrition/ingredient.dart' as _i9; -import 'package:wger/models/nutrition/log.dart' as _i7; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6; -import 'package:wger/models/user/profile.dart' as _i3; -import 'package:wger/providers/body_weight_repository.dart' as _i10; -import 'package:wger/providers/ingredient_repository.dart' as _i8; -import 'package:wger/providers/nutrition_repository.dart' as _i4; -import 'package:wger/providers/user_profile_repository.dart' as _i12; +import 'package:wger/models/body_weight/weight_entry.dart' as _i12; +import 'package:wger/models/nutrition/ingredient.dart' as _i10; +import 'package:wger/models/nutrition/log.dart' as _i8; +import 'package:wger/models/nutrition/meal.dart' as _i6; +import 'package:wger/models/nutrition/meal_item.dart' as _i7; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; +import 'package:wger/models/user/profile.dart' as _i2; +import 'package:wger/providers/body_weight_repository.dart' as _i11; +import 'package:wger/providers/ingredient_repository.dart' as _i9; +import 'package:wger/providers/nutrition_repository.dart' as _i3; +import 'package:wger/providers/user_profile_repository.dart' as _i13; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -32,188 +33,187 @@ import 'package:wger/providers/user_profile_repository.dart' as _i12; // ignore_for_file: subtype_of_sealed_class // ignore_for_file: invalid_use_of_internal_member -class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); -} - -class _FakeProfile_1 extends _i1.SmartFake implements _i3.Profile { - _FakeProfile_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); +class _FakeProfile_0 extends _i1.SmartFake implements _i2.Profile { + _FakeProfile_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } /// A class which mocks [NutritionRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepository { +class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepository { MockNutritionRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Future> fetchPlanSparse(int? planId) => + _i4.Future> fetchPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanSparse, [planId]), - returnValue: _i5.Future>.value( + returnValue: _i4.Future>.value( {}, ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future> fetchPlanFull(int? planId) => + _i4.Future> fetchPlanFull(int? planId) => (super.noSuchMethod( Invocation.method(#fetchPlanFull, [planId]), - returnValue: _i5.Future>.value( + returnValue: _i4.Future>.value( {}, ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future> createPlan(Map? data) => + _i4.Future> createPlan(Map? data) => (super.noSuchMethod( Invocation.method(#createPlan, [data]), - returnValue: _i5.Future>.value( + returnValue: _i4.Future>.value( {}, ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Stream> watchAllDrift() => + _i4.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i5.Stream>); + as _i4.Stream>); @override - _i5.Future editLocalDrift(_i6.NutritionalPlan? plan) => + _i4.Future editLocalDrift(_i5.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method(#editLocalDrift, [plan]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future deleteLocalDrift(int? id) => + _i4.Future deleteLocalDrift(int? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future> createMeal(Map? data) => + _i4.Future> createMeal(Map? data) => (super.noSuchMethod( Invocation.method(#createMeal, [data]), - returnValue: _i5.Future>.value( + returnValue: _i4.Future>.value( {}, ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future> updateMeal( - int? id, - Map? data, - ) => + _i4.Future editMealLocalDrift(_i6.Meal? meal) => (super.noSuchMethod( - Invocation.method(#updateMeal, [id, data]), - returnValue: _i5.Future>.value( - {}, - ), + Invocation.method(#editMealLocalDrift, [meal]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future>); + as _i4.Future); @override - _i5.Future<_i2.Response> deleteMeal(int? id) => + _i4.Future deleteMealLocalDrift(int? id) => (super.noSuchMethod( - Invocation.method(#deleteMeal, [id]), - returnValue: _i5.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMeal, [id])), - ), + Invocation.method(#deleteMealLocalDrift, [id]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future<_i2.Response>); + as _i4.Future); @override - _i5.Future> createMealItem(Map? data) => + _i4.Future> createMealItem(Map? data) => (super.noSuchMethod( Invocation.method(#createMealItem, [data]), - returnValue: _i5.Future>.value( + returnValue: _i4.Future>.value( {}, ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future<_i2.Response> deleteMealItem(int? id) => + _i4.Future editMealItemLocalDrift(_i7.MealItem? item) => (super.noSuchMethod( - Invocation.method(#deleteMealItem, [id]), - returnValue: _i5.Future<_i2.Response>.value( - _FakeResponse_0(this, Invocation.method(#deleteMealItem, [id])), - ), + Invocation.method(#editMealItemLocalDrift, [item]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future<_i2.Response>); + as _i4.Future); @override - _i5.Stream> watchAllLogsHydrated() => + _i4.Future deleteMealItemLocalDrift(int? id) => + (super.noSuchMethod( + Invocation.method(#deleteMealItemLocalDrift, [id]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) + as _i4.Future); + + @override + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i5.Stream>); + as _i4.Stream>); @override - _i5.Future addLogLocalDrift(_i7.LogItem? log) => + _i4.Future addLogLocalDrift(_i8.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future deleteLogLocalDrift(String? id) => + _i4.Future deleteLogLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLogLocalDrift, [id]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); } /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream<_i9.Ingredient?> watchById(int? id) => + _i4.Stream<_i10.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i5.Stream<_i9.Ingredient?>.empty(), + returnValue: _i4.Stream<_i10.Ingredient?>.empty(), ) - as _i5.Stream<_i9.Ingredient?>); + as _i4.Stream<_i10.Ingredient?>); @override - _i5.Future<_i9.Ingredient?> getById(int? id) => + _i4.Future<_i10.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i5.Future<_i9.Ingredient?>.value(), + returnValue: _i4.Future<_i10.Ingredient?>.value(), ) - as _i5.Future<_i9.Ingredient?>); + as _i4.Future<_i10.Ingredient?>); @override - _i5.Future> searchIngredientLocal( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, + _i10.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( @@ -227,20 +227,20 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #limit: limit, }, ), - returnValue: _i5.Future>.value( - <_i9.Ingredient>[], + returnValue: _i4.Future>.value( + <_i10.Ingredient>[], ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future> searchIngredientServer( + _i4.Future> searchIngredientServer( String? name, { String? languageCode = 'en', - _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, + _i9.IngredientSearchLanguage? searchLanguage = _i9.IngredientSearchLanguage.current, bool? isVegan = false, bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, + _i10.NutriScore? nutriscoreMax, }) => (super.noSuchMethod( Invocation.method( @@ -254,98 +254,98 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #nutriscoreMax: nutriscoreMax, }, ), - returnValue: _i5.Future>.value( - <_i9.Ingredient>[], + returnValue: _i4.Future>.value( + <_i10.Ingredient>[], ), ) - as _i5.Future>); + as _i4.Future>); @override - _i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => + _i4.Future<_i10.Ingredient?> searchIngredientByBarcode(String? barcode) => (super.noSuchMethod( Invocation.method(#searchIngredientByBarcode, [barcode]), - returnValue: _i5.Future<_i9.Ingredient?>.value(), + returnValue: _i4.Future<_i10.Ingredient?>.value(), ) - as _i5.Future<_i9.Ingredient?>); + as _i4.Future<_i10.Ingredient?>); } /// A class which mocks [BodyWeightRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockBodyWeightRepository extends _i1.Mock implements _i10.BodyWeightRepository { +class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightRepository { MockBodyWeightRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream> watchAllDrift() => + _i4.Stream> watchAllDrift() => (super.noSuchMethod( Invocation.method(#watchAllDrift, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i5.Stream>); + as _i4.Stream>); @override - _i5.Future deleteLocalDrift(String? id) => + _i4.Future deleteLocalDrift(String? id) => (super.noSuchMethod( Invocation.method(#deleteLocalDrift, [id]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future updateLocalDrift(_i11.WeightEntry? entry) => + _i4.Future updateLocalDrift(_i12.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#updateLocalDrift, [entry]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future addLocalDrift(_i11.WeightEntry? entry) => + _i4.Future addLocalDrift(_i12.WeightEntry? entry) => (super.noSuchMethod( Invocation.method(#addLocalDrift, [entry]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); } /// A class which mocks [UserProfileRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockUserProfileRepository extends _i1.Mock implements _i12.UserProfileRepository { +class MockUserProfileRepository extends _i1.Mock implements _i13.UserProfileRepository { MockUserProfileRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Future<_i3.Profile> fetchProfile() => + _i4.Future<_i2.Profile> fetchProfile() => (super.noSuchMethod( Invocation.method(#fetchProfile, []), - returnValue: _i5.Future<_i3.Profile>.value( - _FakeProfile_1(this, Invocation.method(#fetchProfile, [])), + returnValue: _i4.Future<_i2.Profile>.value( + _FakeProfile_0(this, Invocation.method(#fetchProfile, [])), ), ) - as _i5.Future<_i3.Profile>); + as _i4.Future<_i2.Profile>); @override - _i5.Future saveProfile(_i3.Profile? profile) => + _i4.Future saveProfile(_i2.Profile? profile) => (super.noSuchMethod( Invocation.method(#saveProfile, [profile]), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); @override - _i5.Future verifyEmail() => + _i4.Future verifyEmail() => (super.noSuchMethod( Invocation.method(#verifyEmail, []), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), ) - as _i5.Future); + as _i4.Future); }