Sync nutritional logs

This commit is contained in:
Roland Geider
2026-04-30 18:10:02 +02:00
parent 445063b1a9
commit d1f6fc2dfe
28 changed files with 1507 additions and 463 deletions

View File

@@ -38,6 +38,7 @@ import 'package:wger/models/measurements/measurement_entry.dart';
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/nutritional_plan.dart';
import 'package:wger/models/workouts/log.dart';
import 'package:wger/models/workouts/repetition_unit.dart';
@@ -94,6 +95,7 @@ part 'database.g.dart';
IngredientTable,
IngredientImageTable,
IngredientWeightUnitTable,
LogItemTable,
],
//include: {'queries.drift'},
)

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,8 @@
import 'package:drift/drift.dart';
import 'package:powersync/powersync.dart' as ps;
import 'package:wger/database/powersync/tables/ingredient.dart';
import 'package:wger/models/nutrition/log.dart';
import 'package:wger/models/nutrition/nutritional_plan.dart';
@UseRowClass(NutritionalPlan)
@@ -55,3 +57,40 @@ const PowersyncNutritionalPlanTable = ps.Table(
ps.Column.integer('has_goal_calories'),
],
);
/// Diary log entries (`nutrition_logitem`).
///
/// The client identifies rows by uuid; the sync rules emit
/// `SELECT uuid AS id` so locally we just see a TEXT primary key. The
/// integer `LogItem.id` from the backend stays server-side.
@UseRowClass(LogItem)
class LogItemTable extends Table {
@override
String get tableName => 'nutrition_logitem';
TextColumn get id => text().clientDefault(() => ps.uuid.v4())();
IntColumn get planId => integer().named('plan_id').references(NutritionalPlanTable, #id)();
IntColumn get mealId => integer().nullable().named('meal_id')();
IntColumn get ingredientId => integer().named('ingredient_id').references(IngredientTable, #id)();
IntColumn get weightUnitId => integer().nullable().named('weight_unit_id')();
DateTimeColumn get datetime => dateTime()();
RealColumn get amount => real()();
TextColumn get comment => text().nullable()();
}
const PowersyncLogItemTable = ps.Table(
'nutrition_logitem',
[
ps.Column.integer('plan_id'),
ps.Column.integer('meal_id'),
ps.Column.integer('ingredient_id'),
ps.Column.integer('weight_unit_id'),
ps.Column.text('datetime'),
ps.Column.real('amount'),
ps.Column.text('comment'),
],
indexes: [
ps.Index('plan_idx', [ps.IndexedColumn('plan_id')]),
ps.Index('ingredient_idx', [ps.IndexedColumn('ingredient_id')]),
],
);

View File

@@ -16,76 +16,86 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/helpers/json.dart';
import 'package:drift/drift.dart' as drift;
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/meal_item.dart';
import 'package:wger/models/nutrition/nutritional_values.dart';
part 'log.g.dart';
/// Diary log entry — one ingredient consumed at a point in time.
///
/// Lives entirely in PowerSync/Drift now: row IDs are client-generated UUIDs
/// (so we can write before the server has assigned an integer PK), and the
/// `Ingredient` / `IngredientWeightUnit` relations are hydrated from the same
/// local Drift database by the repository's watch. No JSON round-trip.
///
/// Named `LogItem` to mirror the Django model and Drift table name, and to
/// avoid clashing with the workouts `Log`.
class LogItem {
/// Client-generated UUID. `null` only for instances built in-memory before
/// the first persist; Drift fills it in via the table's `clientDefault`.
String? id;
@JsonSerializable()
class Log {
@JsonKey(required: true)
int? id;
@JsonKey(required: false, name: 'meal')
int? mealId;
@JsonKey(required: true, name: 'plan')
int planId;
@JsonKey(required: true, fromJson: utcIso8601ToLocalDate, toJson: dateToUtcIso8601)
int? mealId;
int ingredientId;
int? weightUnitId;
late DateTime datetime;
late num amount;
String? comment;
@JsonKey(required: true, name: 'ingredient')
late int ingredientId;
@JsonKey(includeFromJson: false, includeToJson: false)
/// Hydrated by the repository after a Drift JOIN.
late Ingredient ingredient;
@JsonKey(required: true, name: 'weight_unit')
int? weightUnitId;
@JsonKey(includeFromJson: false, includeToJson: false)
/// Optional weight unit reference; `null` means the amount is in grams.
IngredientWeightUnit? weightUnitObj;
@JsonKey(required: true, fromJson: stringToNum)
late num amount;
Log({
LogItem({
this.id,
required this.mealId,
this.mealId,
required this.ingredientId,
required this.weightUnitId,
required this.amount,
this.weightUnitId,
required num amount,
required this.planId,
required this.datetime,
required DateTime datetime,
this.comment,
});
}) {
this.amount = amount;
this.datetime = datetime;
}
Log.fromMealItem(MealItem mealItem, this.planId, this.mealId, [DateTime? dateTime]) {
ingredientId = mealItem.ingredientId;
/// Builds a new log row from a meal-plan item, e.g. when the user taps
/// "log this meal". The `id` stays null and is assigned by Drift on insert.
LogItem.fromMealItem(MealItem mealItem, this.planId, this.mealId, [DateTime? dateTime])
: ingredientId = mealItem.ingredientId,
weightUnitId = mealItem.weightUnitId {
ingredient = mealItem.ingredient;
weightUnitId = mealItem.weightUnitId;
datetime = dateTime ?? DateTime.now();
amount = mealItem.amount;
}
// Boilerplate
factory Log.fromJson(Map<String, dynamic> json) => _$LogFromJson(json);
/// Drift companion for inserts/updates against `nutrition_logitem`.
///
/// On insert we leave `id` absent so the table's `clientDefault` UUID kicks
/// in. On update set `includeId: true` to address the existing row.
LogItemTableCompanion toCompanion({bool includeId = false}) {
return LogItemTableCompanion(
id: includeId && id != null ? drift.Value(id!) : const drift.Value.absent(),
planId: drift.Value(planId),
mealId: mealId == null ? const drift.Value.absent() : drift.Value(mealId!),
ingredientId: drift.Value(ingredientId),
weightUnitId: weightUnitId == null ? const drift.Value.absent() : drift.Value(weightUnitId!),
datetime: drift.Value(datetime.toUtc()),
amount: drift.Value(amount.toDouble()),
comment: comment == null ? const drift.Value.absent() : drift.Value(comment!),
);
}
Map<String, dynamic> toJson() => _$LogToJson(this);
/// Calculations
/// Total nutritional contribution of this entry. Server pre-computes the
/// same value, but doing it locally keeps offline mode honest.
NutritionalValues get nutritionalValues {
// This is already done on the server. It might be better to read it from there.
final weight = weightUnitObj == null ? amount : amount * weightUnitObj!.grams;
return ingredient.nutritionalValues / (100 / weight);
}
}

View File

@@ -1,42 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'log.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Log _$LogFromJson(Map<String, dynamic> json) {
$checkKeys(
json,
requiredKeys: const [
'id',
'plan',
'datetime',
'ingredient',
'weight_unit',
'amount',
],
);
return Log(
id: (json['id'] as num?)?.toInt(),
mealId: (json['meal'] as num?)?.toInt(),
ingredientId: (json['ingredient'] as num).toInt(),
weightUnitId: (json['weight_unit'] as num?)?.toInt(),
amount: stringToNum(json['amount'] as String?),
planId: (json['plan'] as num).toInt(),
datetime: utcIso8601ToLocalDate(json['datetime'] as String),
comment: json['comment'] as String?,
);
}
Map<String, dynamic> _$LogToJson(Log instance) => <String, dynamic>{
'id': instance.id,
'meal': instance.mealId,
'plan': instance.planId,
'datetime': dateToUtcIso8601(instance.datetime),
'comment': instance.comment,
'ingredient': instance.ingredientId,
'weight_unit': instance.weightUnitId,
'amount': instance.amount,
};

View File

@@ -45,9 +45,9 @@ class Meal {
List<MealItem> mealItems = [];
@JsonKey(includeFromJson: false, includeToJson: false, defaultValue: [])
List<Log> diaryEntries = [];
List<LogItem> diaryEntries = [];
List<Log> get diaryEntriesToday =>
List<LogItem> get diaryEntriesToday =>
diaryEntries.where((element) => element.datetime.isSameDayAs(DateTime.now())).toList();
Meal({
@@ -56,7 +56,7 @@ class Meal {
this.time,
String? name,
List<MealItem>? mealItems,
List<Log>? diaryEntries,
List<LogItem>? diaryEntries,
}) {
if (plan != null) {
planId = plan;
@@ -95,7 +95,7 @@ class Meal {
TimeOfDay? time,
String? name,
List<MealItem>? mealItems,
List<Log>? diaryEntries,
List<LogItem>? diaryEntries,
}) {
return Meal(
id: id ?? this.id,

View File

@@ -82,7 +82,7 @@ class NutritionalPlan {
List<Meal> meals = [];
@JsonKey(includeFromJson: false, includeToJson: false, defaultValue: [])
List<Log> diaryEntries = [];
List<LogItem> diaryEntries = [];
NutritionalPlan({
this.id,
@@ -98,7 +98,7 @@ class NutritionalPlan {
this.goalFat,
this.goalFiber,
List<Meal>? meals,
List<Log>? diaryEntries,
List<LogItem>? diaryEntries,
}) : creationDate = creationDate ?? DateTime.now() {
this.meals = meals ?? [];
this.diaryEntries = diaryEntries ?? [];
@@ -254,8 +254,8 @@ class NutritionalPlan {
}
/// Returns the nutritional logs for the given date
List<Log> getLogsForDate(DateTime date) {
final List<Log> out = [];
List<LogItem> getLogsForDate(DateTime date) {
final List<LogItem> out = [];
for (final log in diaryEntries) {
final dateKey = DateTime(date.year, date.month, date.day);
final logKey = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
@@ -288,8 +288,8 @@ class NutritionalPlan {
/// returns diary entries
/// deduped by the combination of amount and ingredient ID
List<Log> get dedupDiaryEntries {
final out = <Log>[];
List<LogItem> get dedupDiaryEntries {
final out = <LogItem>[];
for (final log in diaryEntries) {
final found = out.firstWhereOrNull(
(e) => e.amount == log.amount && e.ingredientId == log.ingredientId,

View File

@@ -48,6 +48,7 @@ Schema schema = const Schema([
PowersyncIngredientImageTable,
PowersyncIngredientWeightUnitTable,
PowersyncNutritionalPlanTable,
PowersyncLogItemTable,
// Body weight
PowersyncWeightEntryTable,

View File

@@ -19,6 +19,7 @@
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/ingredient.dart';
@@ -88,20 +89,26 @@ class NutritionNotifier extends _$NutritionNotifier {
_logger.fine('Building NutritionNotifier');
ref.keepAlive();
// Top-level plan list comes from PowerSync (Drift stream over the synced
// `nutrition_nutritionplan` table). The sub-hierarchy (meals, meal items,
// diary entries) still lives behind REST and is layered on top by callers
// via [fetchAndSetPlanFull]. To prevent that sub-data from being wiped
// every time the stream re-emits the top-level row (e.g. after a remote
// edit), we re-attach it from the previous state below.
// Top-level plans and diary entries both come from synced tables. The
// hierarchy in between meals and meal items still lives behind REST and
// is layered on top by callers via [fetchAndSetPlanFull]; we re-attach
// it from the previous state on every emission so a remote edit doesn't
// wipe locally-hydrated meals.
//
// [combineLatest] holds back the first emission until both streams have
// produced a value, so the resulting plans always carry coherent diary
// data
final repo = ref.read(nutritionRepositoryProvider);
return repo.watchAllDrift().map((freshPlans) {
return repo.watchAllDrift().combineLatest(repo.watchAllLogsHydrated(), (freshPlans, allLogs) {
final existing = state.value?.plans ?? const <NutritionalPlan>[];
for (final fresh in freshPlans) {
final old = existing.firstWhereOrNull((p) => p.id == fresh.id);
if (old != null) {
fresh.meals = old.meals;
fresh.diaryEntries = old.diaryEntries;
}
fresh.diaryEntries = allLogs.where((l) => l.planId == fresh.id).toList();
for (final meal in fresh.meals) {
meal.diaryEntries = fresh.diaryEntries.where((l) => l.mealId == meal.id).toList();
}
}
return NutritionState(plans: freshPlans);
@@ -191,8 +198,9 @@ class NutritionNotifier extends _$NutritionNotifier {
}
plan.meals = meals;
// Logs
await fetchAndSetLogs(plan);
// Diary entries are streamed in by build() from PowerSync. Distribute
// the logs we already have onto the freshly-loaded meals so the UI sees
// them immediately, before the next stream tick.
for (final meal in meals) {
meal.diaryEntries = plan.diaryEntries.where((e) => e.mealId == meal.id).toList();
}
@@ -327,12 +335,9 @@ class NutritionNotifier extends _$NutritionNotifier {
final repo = ref.read(nutritionRepositoryProvider);
final plan = findById(meal.planId);
for (final item in meal.mealItems) {
final log = Log.fromMealItem(item, plan.id!, meal.id, mealDateTime);
final data = await repo.createLog(log.toJson());
log.id = data['id'];
plan.diaryEntries.add(log);
final log = LogItem.fromMealItem(item, plan.id!, meal.id, mealDateTime);
await repo.addLogLocalDrift(log);
}
_notifyAfterInPlaceMutation();
}
Future<void> logIngredientToDiary(
@@ -342,43 +347,12 @@ class NutritionNotifier extends _$NutritionNotifier {
]) async {
final repo = ref.read(nutritionRepositoryProvider);
final plan = findById(planId);
final log = Log.fromMealItem(mealItem, plan.id!, null, dateTime);
final data = await repo.createLog(log.toJson());
log.id = data['id'];
plan.diaryEntries.add(log);
_notifyAfterInPlaceMutation();
final log = LogItem.fromMealItem(mealItem, plan.id!, null, dateTime);
await repo.addLogLocalDrift(log);
}
Future<void> deleteLog(int logId, int planId) async {
Future<void> deleteLog(String logId) async {
final repo = ref.read(nutritionRepositoryProvider);
await repo.deleteLog(logId);
final plan = findById(planId);
plan.diaryEntries.removeWhere((element) => element.id == logId);
_notifyAfterInPlaceMutation();
}
/// Loads nutrition diary entries for the given plan and resolves ingredient
/// references against the local PowerSync-backed Drift table. Logs whose
/// ingredient is not present locally are skipped with a warning.
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
final repo = ref.read(nutritionRepositoryProvider);
final ingredientRepo = ref.read(ingredientRepositoryProvider);
final data = await repo.fetchLogsForPlan(plan.id!);
plan.diaryEntries = [];
for (final logData in data) {
final log = Log.fromJson(logData);
final ingredient = await ingredientRepo.getById(log.ingredientId);
if (ingredient == null) {
_logger.warning(
'Ingredient ${log.ingredientId} for log ${log.id} not in local DB, skipping',
);
continue;
}
log.ingredient = ingredient;
plan.diaryEntries.add(log);
}
_notifyAfterInPlaceMutation();
await repo.deleteLogLocalDrift(logId);
}
}

View File

@@ -33,7 +33,7 @@ final class NutritionNotifierProvider
NutritionNotifier create() => NutritionNotifier();
}
String _$nutritionNotifierHash() => r'b7767a3f43668a7f03eb297dbfac223a1154f4e0';
String _$nutritionNotifierHash() => r'f878ce8a83635739948af8b2f27fd8d239880207';
abstract class _$NutritionNotifier extends $StreamNotifier<NutritionState> {
Stream<NutritionState> build();

View File

@@ -16,13 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:drift/drift.dart' show OrderingTerm;
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/helpers/consts.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/nutritional_plan.dart';
import 'package:wger/providers/base_provider.dart';
import 'package:wger/providers/wger_base.dart';
@@ -41,10 +44,11 @@ final nutritionRepositoryProvider = Provider<NutritionRepository>((ref) {
/// Data access for nutrition-related entities.
///
/// HTTP for everything that hasn't been migrated to PowerSync yet (creation,
/// meals, meal items, diary). Top-level [NutritionalPlan] reads as well as
/// edit/delete go through the local PowerSync-backed Drift table — see
/// [watchAllDrift], [editLocalDrift], [deleteLocalDrift].
/// 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].
///
/// Local ingredient lookups are handled by [IngredientRepository] (PowerSync).
class NutritionRepository {
@@ -57,7 +61,6 @@ class NutritionRepository {
static const mealPath = 'meal';
static const mealItemPath = 'mealitem';
static const ingredientInfoPath = 'ingredientinfo';
static const nutritionDiaryPath = 'nutritiondiary';
NutritionRepository(this._base, this._db);
@@ -217,24 +220,79 @@ class NutritionRepository {
// --- Nutrition diary (logs) ---
Future<List<dynamic>> fetchLogsForPlan(int planId) async {
return _base.fetchPaginated(
_base.makeUrl(
nutritionDiaryPath,
query: {
'plan': planId.toString(),
'limit': API_MAX_PAGE_SIZE,
'ordering': 'datetime',
},
/// Streams all of the user's diary entries with their related [Ingredient]
/// (incl. its image and weight units) hydrated from the same Drift database
/// in one query. Re-emits whenever any of the joined tables changes.
Stream<List<LogItem>> watchAllLogsHydrated() {
_logger.finer('Watching all local diary entries');
final query = _db.select(_db.logItemTable).join([
innerJoin(
_db.ingredientTable,
_db.ingredientTable.id.equalsExp(_db.logItemTable.ingredientId),
),
);
leftOuterJoin(
_db.ingredientImageTable,
_db.ingredientImageTable.ingredientId.equalsExp(_db.ingredientTable.id),
),
leftOuterJoin(
_db.ingredientWeightUnitTable,
_db.ingredientWeightUnitTable.ingredientId.equalsExp(_db.ingredientTable.id),
),
])..orderBy([OrderingTerm(expression: _db.logItemTable.datetime)]);
return query.watch().map(_hydrateLogs);
}
Future<Map<String, dynamic>> createLog(Map<String, dynamic> data) async {
return _base.post(data, _base.makeUrl(nutritionDiaryPath));
/// Collapses the cross-joined rows into hydrated [LogItem]s.
List<LogItem> _hydrateLogs(Iterable<TypedResult> rows) {
final logs = <String, LogItem>{};
final ingredients = <int, Ingredient>{};
final weightUnitsByIngredient = <int, List<IngredientWeightUnit>>{};
for (final row in rows) {
final log = row.readTable(_db.logItemTable);
final ingredient = row.readTable(_db.ingredientTable);
final image = row.readTableOrNull(_db.ingredientImageTable);
final wu = row.readTableOrNull(_db.ingredientWeightUnitTable);
final ingEntry = ingredients.putIfAbsent(ingredient.id, () => ingredient);
if (image != null) {
ingEntry.image = image;
}
if (wu != null) {
final list = weightUnitsByIngredient.putIfAbsent(ingredient.id, () => []);
if (!list.any((w) => w.id == wu.id)) {
list.add(wu);
}
}
logs.putIfAbsent(log.id!, () => log);
}
for (final ing in ingredients.values) {
ing.weightUnits = weightUnitsByIngredient[ing.id] ?? const [];
}
for (final log in logs.values) {
log.ingredient = ingredients[log.ingredientId]!;
if (log.weightUnitId != null) {
log.weightUnitObj = log.ingredient.weightUnits.firstWhereOrNull(
(w) => w.id == log.weightUnitId,
);
}
}
return logs.values.toList();
}
Future<http.Response> deleteLog(int id) async {
return _base.deleteRequest(nutritionDiaryPath, id);
/// Inserts a new diary entry
Future<void> addLogLocalDrift(LogItem log) async {
_logger.finer('Adding local diary entry for ingredient ${log.ingredientId}');
await _db.into(_db.logItemTable).insert(log.toCompanion());
}
/// Deletes a diary entry by its UUID
Future<void> deleteLogLocalDrift(String id) async {
_logger.finer('Deleting local diary entry $id');
await (_db.delete(_db.logItemTable)..where((t) => t.id.equals(id))).go();
}
}

View File

@@ -122,7 +122,7 @@ Widget getMealItemForm(
]) {
return IngredientForm(
// TODO we use planId 0 here cause we don't have one and we don't need it I think?
recent: recent.map((e) => Log.fromMealItem(e, 0, e.mealId)).toList(),
recent: recent.map((e) => LogItem.fromMealItem(e, 0, e.mealId)).toList(),
onSave: (BuildContext context, WidgetRef ref, MealItem mealItem, DateTime? dt) {
mealItem.mealId = meal.id!;
ref.read(nutritionProvider.notifier).addMealItem(mealItem, meal);
@@ -155,7 +155,7 @@ Widget getIngredientLogForm(NutritionalPlan plan) {
/// log to the diary or to add to a meal.
class IngredientForm extends ConsumerStatefulWidget {
final Function(BuildContext context, WidgetRef ref, MealItem mealItem, DateTime? dt) onSave;
final List<Log> recent;
final List<LogItem> recent;
final bool withDate;
final String barcode;
final bool test;

View File

@@ -59,7 +59,7 @@ class DiaryEntryTile extends ConsumerWidget {
this.nutritionalPlan,
});
final Log diaryEntry;
final LogItem diaryEntry;
final NutritionalPlan? nutritionalPlan;
@override
@@ -84,9 +84,7 @@ class DiaryEntryTile extends ConsumerWidget {
: IconButton(
tooltip: AppLocalizations.of(context).delete,
onPressed: () {
ref
.read(nutritionProvider.notifier)
.deleteLog(diaryEntry.id!, nutritionalPlan!.id!);
ref.read(nutritionProvider.notifier).deleteLog(diaryEntry.id!);
},
icon: const Icon(Icons.delete_outline),
iconSize: ICON_SIZE_SMALL,

View File

@@ -1,34 +0,0 @@
{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"plan": 1,
"meal": 1,
"ingredient": 59887,
"weight_unit": null,
"datetime": "2022-08-09T20:27:14.064157+02:00",
"amount": "100.00"
},
{
"id": 2,
"plan": 1,
"meal": 1,
"ingredient": 58300,
"weight_unit": null,
"datetime": "2022-08-09T20:27:14.075674+02:00",
"amount": "100.00"
},
{
"id": 3,
"plan": 1,
"meal": 1,
"ingredient": 10065,
"weight_unit": null,
"datetime": "2022-08-09T20:27:14.086133+02:00",
"amount": "200.00"
}
]
}

View File

@@ -10,8 +10,9 @@ 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 _i9;
import 'package:wger/models/nutrition/log.dart' as _i10;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i8;
import 'package:wger/providers/ingredient_repository.dart' as _i10;
import 'package:wger/providers/ingredient_repository.dart' as _i11;
import 'package:wger/providers/measurement_repository.dart' as _i3;
import 'package:wger/providers/nutrition_repository.dart' as _i7;
@@ -295,38 +296,36 @@ class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepositor
as _i4.Future<_i9.Ingredient?>);
@override
_i4.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i4.Stream<List<_i10.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i4.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i10.LogItem>>.empty(),
)
as _i4.Future<List<dynamic>>);
as _i4.Stream<List<_i10.LogItem>>);
@override
_i4.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i4.Future<void> addLogLocalDrift(_i10.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i4.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<Map<String, dynamic>>);
as _i4.Future<void>);
@override
_i4.Future<_i2.Response> deleteLog(int? id) =>
_i4.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i4.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<_i2.Response>);
as _i4.Future<void>);
}
/// 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);
}

View File

@@ -44,7 +44,6 @@ void main() {
late Map<String, dynamic> nutritionalPlanInfoResponse;
late Map<String, dynamic> nutritionalPlanDetailResponse;
late List<dynamic> nutritionDiaryResponse;
late Map<String, dynamic> ingredient10065Response;
ProviderContainer makeContainer() {
@@ -79,6 +78,8 @@ void main() {
// concurrent stream emission can't overwrite their optimistic state.
when(mockRepo.watchAllDrift()).thenAnswer((_) => const Stream.empty());
when(mockRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
// 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());
@@ -89,9 +90,6 @@ void main() {
nutritionalPlanDetailResponse = jsonDecode(
fixture('nutrition/nutritional_plan_detail_response.json'),
);
nutritionDiaryResponse = jsonDecode(
fixture('nutrition/nutrition_diary_response.json'),
)['results'];
ingredient10065Response = jsonDecode(
fixture('nutrition/ingredientinfo_10065.json'),
);
@@ -108,9 +106,7 @@ void main() {
when(mockRepo.fetchPlanFull(1)).thenAnswer(
(_) async => nutritionalPlanInfoResponse,
);
when(mockRepo.fetchLogsForPlan(any)).thenAnswer(
(_) async => nutritionDiaryResponse,
);
when(mockRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
// Ingredient lookups now go through PowerSync — stub the local repo.
final ingredient = Ingredient.fromJson(ingredient10065Response);
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => ingredient);

View File

@@ -8,8 +8,9 @@ import 'dart:async' as _i4;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -209,38 +210,36 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i4.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
)
as _i4.Future<List<dynamic>>);
as _i4.Stream<List<_i7.LogItem>>);
@override
_i4.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i4.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<Map<String, dynamic>>);
as _i4.Future<void>);
@override
_i4.Future<_i2.Response> deleteLog(int? id) =>
_i4.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i4.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<_i2.Response>);
as _i4.Future<void>);
}
/// 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);
}

View File

@@ -55,9 +55,11 @@ void main() {
when(mockRepo.updateMeal(any, any)).thenAnswer((_) async => Meal(id: 1, plan: 1).toJson());
when(mockRepo.createMeal(any)).thenAnswer((_) async => Meal(id: 99, plan: 1).toJson());
// NutritionNotifier.build() subscribes to a Drift stream — emit the seed
// plan directly through that channel.
// NutritionNotifier.build() subscribes to two Drift streams (plans +
// diary entries) — emit the seed plan and an empty diary so the
// combined stream produces a value.
when(mockRepo.watchAllDrift()).thenAnswer((_) => Stream.value([plan1]));
when(mockRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
container = ProviderContainer(
overrides: [

View File

@@ -128,9 +128,11 @@ void main() {
// the Ingredient (inlined by REST or JOINed by the repository), so no
// separate stub is needed.
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => ingredient);
// NutritionNotifier.build() now subscribes to a Drift stream — emit the
// seed plan directly so addMealItem can look up the meal/plan.
// NutritionNotifier.build() now subscribes to two Drift streams (plans
// + diary entries) — emit the seed plan and an empty diary so the
// combined stream produces a value.
when(mockRepo.watchAllDrift()).thenAnswer((_) => Stream.value([plan1]));
when(mockRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
container = ProviderContainer(
overrides: [

View File

@@ -1,13 +1,13 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 wger Team
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wger Workout Manager is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
@@ -50,10 +50,9 @@ void main() {
mockIngredientRepo = MockIngredientRepository();
when(mockRepo.createPlan(any)).thenAnswer((_) async => plan1.toJson());
// Edit now goes through Drift (PowerSync) instead of REST.
when(mockRepo.editLocalDrift(any)).thenAnswer((_) async => Future.value());
// NutritionNotifier.build() subscribes to a Drift stream.
when(mockRepo.watchAllDrift()).thenAnswer((_) => Stream.value(const []));
when(mockRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
});
Widget createHomeScreen(NutritionalPlan plan, {locale = 'en'}) {

View File

@@ -8,8 +8,9 @@ import 'dart:async' as _i4;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -209,38 +210,36 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i4.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
)
as _i4.Future<List<dynamic>>);
as _i4.Stream<List<_i7.LogItem>>);
@override
_i4.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i4.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<Map<String, dynamic>>);
as _i4.Future<void>);
@override
_i4.Future<_i2.Response> deleteLog(int? id) =>
_i4.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i4.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<_i2.Response>);
as _i4.Future<void>);
}
/// 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);
}

View File

@@ -54,7 +54,6 @@ void main() {
late Map<String, dynamic> nutritionalPlanInfoResponse;
late Map<String, dynamic> nutritionalPlanDetailResponse;
late List<dynamic> nutritionDiaryResponse;
late Ingredient fetchedIngredient;
setUp(() {
@@ -74,9 +73,6 @@ void main() {
nutritionalPlanDetailResponse = jsonDecode(
fixture('nutrition/nutritional_plan_detail_response.json'),
);
nutritionDiaryResponse = jsonDecode(
fixture('nutrition/nutrition_diary_response.json'),
)['results'];
fetchedIngredient = Ingredient.fromJson(
jsonDecode(fixture('nutrition/ingredientinfo_10065.json')),
);
@@ -85,7 +81,11 @@ void main() {
mockNutritionRepo.fetchPlanSparse(any),
).thenAnswer((_) async => nutritionalPlanDetailResponse);
when(mockNutritionRepo.fetchPlanFull(any)).thenAnswer((_) async => nutritionalPlanInfoResponse);
when(mockNutritionRepo.fetchLogsForPlan(any)).thenAnswer((_) async => nutritionDiaryResponse);
when(
mockNutritionRepo.watchAllLogsHydrated(),
).thenAnswer((_) => Stream.value(getTestNutritionLogs()));
// Ingredient lookups now go through PowerSync — stub the local repo.
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => fetchedIngredient);
when(mockIngredientRepo.watchById(any)).thenAnswer((_) => Stream.value(fetchedIngredient));

View File

@@ -4,17 +4,18 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i4;
import 'dart:convert' as _i8;
import 'dart:typed_data' as _i10;
import 'dart:convert' as _i9;
import 'dart:typed_data' as _i11;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:mockito/src/dummies.dart' as _i9;
import 'package:wger/models/body_weight/weight_entry.dart' as _i12;
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 _i6;
import 'package:wger/models/nutrition/log.dart' as _i7;
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5;
import 'package:wger/providers/body_weight_repository.dart' as _i11;
import 'package:wger/providers/ingredient_repository.dart' as _i7;
import 'package:wger/providers/body_weight_repository.dart' as _i12;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/nutrition_repository.dart' as _i3;
// ignore_for_file: type=lint
@@ -219,38 +220,36 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor
as _i4.Future<_i6.Ingredient?>);
@override
_i4.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i4.Stream<List<_i7.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i4.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i4.Stream<List<_i7.LogItem>>.empty(),
)
as _i4.Future<List<dynamic>>);
as _i4.Stream<List<_i7.LogItem>>);
@override
_i4.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i4.Future<void> addLogLocalDrift(_i7.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i4.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<Map<String, dynamic>>);
as _i4.Future<void>);
@override
_i4.Future<_i2.Response> deleteLog(int? id) =>
_i4.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i4.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
)
as _i4.Future<_i2.Response>);
as _i4.Future<void>);
}
/// 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);
}
@@ -330,7 +329,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i8.Encoding? encoding,
_i9.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -356,7 +355,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i8.Encoding? encoding,
_i9.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -382,7 +381,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i8.Encoding? encoding,
_i9.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -408,7 +407,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i8.Encoding? encoding,
_i9.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -434,7 +433,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
(super.noSuchMethod(
Invocation.method(#read, [url], {#headers: headers}),
returnValue: _i4.Future<String>.value(
_i9.dummyValue<String>(
_i10.dummyValue<String>(
this,
Invocation.method(#read, [url], {#headers: headers}),
),
@@ -443,15 +442,15 @@ class MockClient extends _i1.Mock implements _i2.Client {
as _i4.Future<String>);
@override
_i4.Future<_i10.Uint8List> readBytes(
_i4.Future<_i11.Uint8List> readBytes(
Uri? url, {
Map<String, String>? headers,
}) =>
(super.noSuchMethod(
Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: _i4.Future<_i10.Uint8List>.value(_i10.Uint8List(0)),
returnValue: _i4.Future<_i11.Uint8List>.value(_i11.Uint8List(0)),
)
as _i4.Future<_i10.Uint8List>);
as _i4.Future<_i11.Uint8List>);
@override
_i4.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
@@ -476,18 +475,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 _i11.BodyWeightRepository {
class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightRepository {
MockBodyWeightRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i4.Stream<List<_i12.WeightEntry>> watchAllDrift() =>
_i4.Stream<List<_i13.WeightEntry>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i4.Stream<List<_i12.WeightEntry>>.empty(),
returnValue: _i4.Stream<List<_i13.WeightEntry>>.empty(),
)
as _i4.Stream<List<_i12.WeightEntry>>);
as _i4.Stream<List<_i13.WeightEntry>>);
@override
_i4.Future<void> deleteLocalDrift(String? id) =>
@@ -499,7 +498,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i4.Future<void>);
@override
_i4.Future<void> updateLocalDrift(_i12.WeightEntry? entry) =>
_i4.Future<void> updateLocalDrift(_i13.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i4.Future<void>.value(),
@@ -508,7 +507,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i11.BodyWeightReposi
as _i4.Future<void>);
@override
_i4.Future<void> addLocalDrift(_i12.WeightEntry? entry) =>
_i4.Future<void> addLocalDrift(_i13.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i4.Future<void>.value(),

View File

@@ -83,6 +83,8 @@ void main() {
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null);
when(mockNutritionRepo.watchAllDrift()).thenAnswer((_) => Stream.value(plans));
// build() now combines plans + diary entries; default to an empty diary.
when(mockNutritionRepo.watchAllLogsHydrated()).thenAnswer((_) => Stream.value(const []));
when(mockNutritionRepo.deleteLocalDrift(any)).thenAnswer((_) async => Future.value());
});

View File

@@ -4,20 +4,21 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'dart:convert' as _i9;
import 'dart:typed_data' as _i11;
import 'dart:convert' as _i10;
import 'dart:typed_data' as _i12;
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: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 _i7;
import 'package:wger/models/nutrition/log.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 _i12;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/body_weight_repository.dart' as _i13;
import 'package:wger/providers/ingredient_repository.dart' as _i9;
import 'package:wger/providers/nutrition_repository.dart' as _i4;
import 'package:wger/providers/user_profile_repository.dart' as _i14;
import 'package:wger/providers/user_profile_repository.dart' as _i15;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -225,38 +226,36 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
as _i5.Future<_i7.Ingredient?>);
@override
_i5.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i5.Stream<List<_i8.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i5.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i5.Stream<List<_i8.LogItem>>.empty(),
)
as _i5.Future<List<dynamic>>);
as _i5.Stream<List<_i8.LogItem>>);
@override
_i5.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i5.Future<void> addLogLocalDrift(_i8.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<Map<String, dynamic>>);
as _i5.Future<void>);
@override
_i5.Future<_i2.Response> deleteLog(int? id) =>
_i5.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<_i2.Response>);
as _i5.Future<void>);
}
/// 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);
}
@@ -336,7 +335,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i10.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -362,7 +361,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i10.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -388,7 +387,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i10.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -414,7 +413,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
Uri? url, {
Map<String, String>? headers,
Object? body,
_i9.Encoding? encoding,
_i10.Encoding? encoding,
}) =>
(super.noSuchMethod(
Invocation.method(
@@ -440,7 +439,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
(super.noSuchMethod(
Invocation.method(#read, [url], {#headers: headers}),
returnValue: _i5.Future<String>.value(
_i10.dummyValue<String>(
_i11.dummyValue<String>(
this,
Invocation.method(#read, [url], {#headers: headers}),
),
@@ -449,15 +448,15 @@ class MockClient extends _i1.Mock implements _i2.Client {
as _i5.Future<String>);
@override
_i5.Future<_i11.Uint8List> readBytes(
_i5.Future<_i12.Uint8List> readBytes(
Uri? url, {
Map<String, String>? headers,
}) =>
(super.noSuchMethod(
Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: _i5.Future<_i11.Uint8List>.value(_i11.Uint8List(0)),
returnValue: _i5.Future<_i12.Uint8List>.value(_i12.Uint8List(0)),
)
as _i5.Future<_i11.Uint8List>);
as _i5.Future<_i12.Uint8List>);
@override
_i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
@@ -482,18 +481,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 _i13.BodyWeightRepository {
MockBodyWeightRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<List<_i13.WeightEntry>> watchAllDrift() =>
_i5.Stream<List<_i14.WeightEntry>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i5.Stream<List<_i13.WeightEntry>>.empty(),
returnValue: _i5.Stream<List<_i14.WeightEntry>>.empty(),
)
as _i5.Stream<List<_i13.WeightEntry>>);
as _i5.Stream<List<_i14.WeightEntry>>);
@override
_i5.Future<void> deleteLocalDrift(String? id) =>
@@ -505,7 +504,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> updateLocalDrift(_i13.WeightEntry? entry) =>
_i5.Future<void> updateLocalDrift(_i14.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -514,7 +513,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightReposi
as _i5.Future<void>);
@override
_i5.Future<void> addLocalDrift(_i13.WeightEntry? entry) =>
_i5.Future<void> addLocalDrift(_i14.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -526,7 +525,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i12.BodyWeightReposi
/// A class which mocks [UserProfileRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockUserProfileRepository extends _i1.Mock implements _i14.UserProfileRepository {
class MockUserProfileRepository extends _i1.Mock implements _i15.UserProfileRepository {
MockUserProfileRepository() {
_i1.throwOnMissingStub(this);
}

View File

@@ -201,91 +201,96 @@ class _Fake$IngredientWeightUnitTableTable_28 extends _i1.SmartFake
) : super(parent, parentInvocation);
}
class _FakeDriftDatabaseOptions_29 extends _i1.SmartFake implements _i3.DriftDatabaseOptions {
_FakeDriftDatabaseOptions_29(Object parent, Invocation parentInvocation)
class _Fake$LogItemTableTable_29 extends _i1.SmartFake implements _i4.$LogItemTableTable {
_Fake$LogItemTableTable_29(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeGeneratedDatabase_30 extends _i1.SmartFake implements _i3.GeneratedDatabase {
_FakeGeneratedDatabase_30(Object parent, Invocation parentInvocation)
class _FakeDriftDatabaseOptions_30 extends _i1.SmartFake implements _i3.DriftDatabaseOptions {
_FakeDriftDatabaseOptions_30(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeStreamQueryUpdateRules_31 extends _i1.SmartFake implements _i3.StreamQueryUpdateRules {
_FakeStreamQueryUpdateRules_31(Object parent, Invocation parentInvocation)
class _FakeGeneratedDatabase_31 extends _i1.SmartFake implements _i3.GeneratedDatabase {
_FakeGeneratedDatabase_31(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeDatabaseConnection_32 extends _i1.SmartFake implements _i3.DatabaseConnection {
_FakeDatabaseConnection_32(Object parent, Invocation parentInvocation)
class _FakeStreamQueryUpdateRules_32 extends _i1.SmartFake implements _i3.StreamQueryUpdateRules {
_FakeStreamQueryUpdateRules_32(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeQueryExecutor_33 extends _i1.SmartFake implements _i3.QueryExecutor {
_FakeQueryExecutor_33(Object parent, Invocation parentInvocation)
class _FakeDatabaseConnection_33 extends _i1.SmartFake implements _i3.DatabaseConnection {
_FakeDatabaseConnection_33(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeStreamQueryStore_34 extends _i1.SmartFake implements _i5.StreamQueryStore {
_FakeStreamQueryStore_34(Object parent, Invocation parentInvocation)
class _FakeQueryExecutor_34 extends _i1.SmartFake implements _i3.QueryExecutor {
_FakeQueryExecutor_34(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeDatabaseConnectionUser_35 extends _i1.SmartFake implements _i3.DatabaseConnectionUser {
_FakeDatabaseConnectionUser_35(Object parent, Invocation parentInvocation)
class _FakeStreamQueryStore_35 extends _i1.SmartFake implements _i5.StreamQueryStore {
_FakeStreamQueryStore_35(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeMigrator_36 extends _i1.SmartFake implements _i3.Migrator {
_FakeMigrator_36(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeDatabaseConnectionUser_36 extends _i1.SmartFake implements _i3.DatabaseConnectionUser {
_FakeDatabaseConnectionUser_36(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeFuture_37<T> extends _i1.SmartFake implements _i6.Future<T> {
_FakeFuture_37(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeMigrator_37 extends _i1.SmartFake implements _i3.Migrator {
_FakeMigrator_37(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeInsertStatement_38<T1 extends _i3.Table, D1> extends _i1.SmartFake
class _FakeFuture_38<T> extends _i1.SmartFake implements _i6.Future<T> {
_FakeFuture_38(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeInsertStatement_39<T1 extends _i3.Table, D1> extends _i1.SmartFake
implements _i3.InsertStatement<T1, D1> {
_FakeInsertStatement_38(Object parent, Invocation parentInvocation)
_FakeInsertStatement_39(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeUpdateStatement_39<T extends _i3.Table, D> extends _i1.SmartFake
class _FakeUpdateStatement_40<T extends _i3.Table, D> extends _i1.SmartFake
implements _i3.UpdateStatement<T, D> {
_FakeUpdateStatement_39(Object parent, Invocation parentInvocation)
_FakeUpdateStatement_40(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeSimpleSelectStatement_40<T1 extends _i3.HasResultSet, D> extends _i1.SmartFake
class _FakeSimpleSelectStatement_41<T1 extends _i3.HasResultSet, D> extends _i1.SmartFake
implements _i3.SimpleSelectStatement<T1, D> {
_FakeSimpleSelectStatement_40(Object parent, Invocation parentInvocation)
_FakeSimpleSelectStatement_41(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeJoinedSelectStatement_41<FirstT extends _i3.HasResultSet, FirstD> extends _i1.SmartFake
class _FakeJoinedSelectStatement_42<FirstT extends _i3.HasResultSet, FirstD> extends _i1.SmartFake
implements _i3.JoinedSelectStatement<FirstT, FirstD> {
_FakeJoinedSelectStatement_41(Object parent, Invocation parentInvocation)
_FakeJoinedSelectStatement_42(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeBaseSelectStatement_42<Row> extends _i1.SmartFake
class _FakeBaseSelectStatement_43<Row> extends _i1.SmartFake
implements _i3.BaseSelectStatement<Row> {
_FakeBaseSelectStatement_42(Object parent, Invocation parentInvocation)
_FakeBaseSelectStatement_43(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeDeleteStatement_43<T1 extends _i3.Table, D1> extends _i1.SmartFake
class _FakeDeleteStatement_44<T1 extends _i3.Table, D1> extends _i1.SmartFake
implements _i3.DeleteStatement<T1, D1> {
_FakeDeleteStatement_43(Object parent, Invocation parentInvocation)
_FakeDeleteStatement_44(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeSelectable_44<T> extends _i1.SmartFake implements _i3.Selectable<T> {
_FakeSelectable_44(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
class _FakeSelectable_45<T> extends _i1.SmartFake implements _i3.Selectable<T> {
_FakeSelectable_45(Object parent, Invocation parentInvocation) : super(parent, parentInvocation);
}
class _FakeGenerationContext_45 extends _i1.SmartFake implements _i3.GenerationContext {
_FakeGenerationContext_45(Object parent, Invocation parentInvocation)
class _FakeGenerationContext_46 extends _i1.SmartFake implements _i3.GenerationContext {
_FakeGenerationContext_46(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
@@ -734,6 +739,17 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
)
as _i4.$IngredientWeightUnitTableTable);
@override
_i4.$LogItemTableTable get logItemTable =>
(super.noSuchMethod(
Invocation.getter(#logItemTable),
returnValue: _Fake$LogItemTableTable_29(
this,
Invocation.getter(#logItemTable),
),
)
as _i4.$LogItemTableTable);
@override
Iterable<_i3.TableInfo<_i3.Table, Object?>> get allTables =>
(super.noSuchMethod(
@@ -754,7 +770,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.DriftDatabaseOptions get options =>
(super.noSuchMethod(
Invocation.getter(#options),
returnValue: _FakeDriftDatabaseOptions_29(
returnValue: _FakeDriftDatabaseOptions_30(
this,
Invocation.getter(#options),
),
@@ -765,7 +781,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.GeneratedDatabase get attachedDatabase =>
(super.noSuchMethod(
Invocation.getter(#attachedDatabase),
returnValue: _FakeGeneratedDatabase_30(
returnValue: _FakeGeneratedDatabase_31(
this,
Invocation.getter(#attachedDatabase),
),
@@ -776,7 +792,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.StreamQueryUpdateRules get streamUpdateRules =>
(super.noSuchMethod(
Invocation.getter(#streamUpdateRules),
returnValue: _FakeStreamQueryUpdateRules_31(
returnValue: _FakeStreamQueryUpdateRules_32(
this,
Invocation.getter(#streamUpdateRules),
),
@@ -787,7 +803,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.DatabaseConnection get connection =>
(super.noSuchMethod(
Invocation.getter(#connection),
returnValue: _FakeDatabaseConnection_32(
returnValue: _FakeDatabaseConnection_33(
this,
Invocation.getter(#connection),
),
@@ -809,7 +825,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.QueryExecutor get executor =>
(super.noSuchMethod(
Invocation.getter(#executor),
returnValue: _FakeQueryExecutor_33(
returnValue: _FakeQueryExecutor_34(
this,
Invocation.getter(#executor),
),
@@ -820,7 +836,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i5.StreamQueryStore get streamQueries =>
(super.noSuchMethod(
Invocation.getter(#streamQueries),
returnValue: _FakeStreamQueryStore_34(
returnValue: _FakeStreamQueryStore_35(
this,
Invocation.getter(#streamQueries),
),
@@ -831,7 +847,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.DatabaseConnectionUser get resolvedEngine =>
(super.noSuchMethod(
Invocation.getter(#resolvedEngine),
returnValue: _FakeDatabaseConnectionUser_35(
returnValue: _FakeDatabaseConnectionUser_36(
this,
Invocation.getter(#resolvedEngine),
),
@@ -842,7 +858,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
_i3.Migrator createMigrator() =>
(super.noSuchMethod(
Invocation.method(#createMigrator, []),
returnValue: _FakeMigrator_36(
returnValue: _FakeMigrator_37(
this,
Invocation.method(#createMigrator, []),
),
@@ -891,7 +907,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
),
(Ret v) => _i6.Future<Ret>.value(v),
) ??
_FakeFuture_37<Ret>(
_FakeFuture_38<Ret>(
this,
Invocation.method(#computeWithDatabase, [], {
#computation: computation,
@@ -958,7 +974,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
),
(T v) => _i6.Future<T>.value(v),
) ??
_FakeFuture_37<T>(this, Invocation.method(#doWhenOpened, [fn])),
_FakeFuture_38<T>(this, Invocation.method(#doWhenOpened, [fn])),
)
as _i6.Future<T>);
@@ -968,7 +984,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
) =>
(super.noSuchMethod(
Invocation.method(#into, [table]),
returnValue: _FakeInsertStatement_38<T, D>(
returnValue: _FakeInsertStatement_39<T, D>(
this,
Invocation.method(#into, [table]),
),
@@ -981,7 +997,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
) =>
(super.noSuchMethod(
Invocation.method(#update, [table]),
returnValue: _FakeUpdateStatement_39<Tbl, R>(
returnValue: _FakeUpdateStatement_40<Tbl, R>(
this,
Invocation.method(#update, [table]),
),
@@ -995,7 +1011,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
}) =>
(super.noSuchMethod(
Invocation.method(#select, [table], {#distinct: distinct}),
returnValue: _FakeSimpleSelectStatement_40<T, R>(
returnValue: _FakeSimpleSelectStatement_41<T, R>(
this,
Invocation.method(#select, [table], {#distinct: distinct}),
),
@@ -1009,7 +1025,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
}) =>
(super.noSuchMethod(
Invocation.method(#selectOnly, [table], {#distinct: distinct}),
returnValue: _FakeJoinedSelectStatement_41<T, R>(
returnValue: _FakeJoinedSelectStatement_42<T, R>(
this,
Invocation.method(#selectOnly, [table], {#distinct: distinct}),
),
@@ -1022,7 +1038,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
) =>
(super.noSuchMethod(
Invocation.method(#selectExpressions, [columns]),
returnValue: _FakeBaseSelectStatement_42<_i3.TypedResult>(
returnValue: _FakeBaseSelectStatement_43<_i3.TypedResult>(
this,
Invocation.method(#selectExpressions, [columns]),
),
@@ -1035,7 +1051,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
) =>
(super.noSuchMethod(
Invocation.method(#delete, [table]),
returnValue: _FakeDeleteStatement_43<T, D>(
returnValue: _FakeDeleteStatement_44<T, D>(
this,
Invocation.method(#delete, [table]),
),
@@ -1112,7 +1128,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
[query],
{#variables: variables, #readsFrom: readsFrom},
),
returnValue: _FakeSelectable_44<_i3.QueryRow>(
returnValue: _FakeSelectable_45<_i3.QueryRow>(
this,
Invocation.method(
#customSelect,
@@ -1135,7 +1151,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
[query],
{#variables: variables, #readsFrom: readsFrom},
),
returnValue: _FakeSelectable_44<_i3.QueryRow>(
returnValue: _FakeSelectable_45<_i3.QueryRow>(
this,
Invocation.method(
#customSelectQuery,
@@ -1178,7 +1194,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
),
(T v) => _i6.Future<T>.value(v),
) ??
_FakeFuture_37<T>(
_FakeFuture_38<T>(
this,
Invocation.method(
#transaction,
@@ -1201,7 +1217,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
),
(T v) => _i6.Future<T>.value(v),
) ??
_FakeFuture_37<T>(
_FakeFuture_38<T>(
this,
Invocation.method(#exclusively, [action]),
),
@@ -1240,7 +1256,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
),
(T v) => _i6.Future<T>.value(v),
) ??
_FakeFuture_37<T>(
_FakeFuture_38<T>(
this,
Invocation.method(
#runWithInterceptor,
@@ -1263,7 +1279,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
[component],
{#hasMultipleTables: hasMultipleTables, #startIndex: startIndex},
),
returnValue: _FakeGenerationContext_45(
returnValue: _FakeGenerationContext_46(
this,
Invocation.method(
#$write,
@@ -1289,7 +1305,7 @@ class MockDriftPowersyncDatabase extends _i1.Mock implements _i4.DriftPowersyncD
[table, insertable],
{#startIndex: startIndex},
),
returnValue: _FakeGenerationContext_45(
returnValue: _FakeGenerationContext_46(
this,
Invocation.method(
#$writeInsertable,

View File

@@ -7,14 +7,15 @@ import 'dart:async' as _i5;
import 'package:http/http.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/body_weight/weight_entry.dart' as _i10;
import 'package:wger/models/body_weight/weight_entry.dart' as _i11;
import 'package:wger/models/nutrition/ingredient.dart' as _i7;
import 'package:wger/models/nutrition/log.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 _i9;
import 'package:wger/providers/ingredient_repository.dart' as _i8;
import 'package:wger/providers/body_weight_repository.dart' as _i10;
import 'package:wger/providers/ingredient_repository.dart' as _i9;
import 'package:wger/providers/nutrition_repository.dart' as _i4;
import 'package:wger/providers/user_profile_repository.dart' as _i11;
import 'package:wger/providers/user_profile_repository.dart' as _i12;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@@ -217,38 +218,36 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor
as _i5.Future<_i7.Ingredient?>);
@override
_i5.Future<List<dynamic>> fetchLogsForPlan(int? planId) =>
_i5.Stream<List<_i8.LogItem>> watchAllLogsHydrated() =>
(super.noSuchMethod(
Invocation.method(#fetchLogsForPlan, [planId]),
returnValue: _i5.Future<List<dynamic>>.value(<dynamic>[]),
Invocation.method(#watchAllLogsHydrated, []),
returnValue: _i5.Stream<List<_i8.LogItem>>.empty(),
)
as _i5.Future<List<dynamic>>);
as _i5.Stream<List<_i8.LogItem>>);
@override
_i5.Future<Map<String, dynamic>> createLog(Map<String, dynamic>? data) =>
_i5.Future<void> addLogLocalDrift(_i8.LogItem? log) =>
(super.noSuchMethod(
Invocation.method(#createLog, [data]),
returnValue: _i5.Future<Map<String, dynamic>>.value(
<String, dynamic>{},
),
Invocation.method(#addLogLocalDrift, [log]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<Map<String, dynamic>>);
as _i5.Future<void>);
@override
_i5.Future<_i2.Response> deleteLog(int? id) =>
_i5.Future<void> deleteLogLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLog, [id]),
returnValue: _i5.Future<_i2.Response>.value(
_FakeResponse_0(this, Invocation.method(#deleteLog, [id])),
),
Invocation.method(#deleteLogLocalDrift, [id]),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
)
as _i5.Future<_i2.Response>);
as _i5.Future<void>);
}
/// 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);
}
@@ -292,18 +291,18 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit
/// A class which mocks [BodyWeightRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockBodyWeightRepository extends _i1.Mock implements _i9.BodyWeightRepository {
class MockBodyWeightRepository extends _i1.Mock implements _i10.BodyWeightRepository {
MockBodyWeightRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i5.Stream<List<_i10.WeightEntry>> watchAllDrift() =>
_i5.Stream<List<_i11.WeightEntry>> watchAllDrift() =>
(super.noSuchMethod(
Invocation.method(#watchAllDrift, []),
returnValue: _i5.Stream<List<_i10.WeightEntry>>.empty(),
returnValue: _i5.Stream<List<_i11.WeightEntry>>.empty(),
)
as _i5.Stream<List<_i10.WeightEntry>>);
as _i5.Stream<List<_i11.WeightEntry>>);
@override
_i5.Future<void> deleteLocalDrift(String? id) =>
@@ -315,7 +314,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i9.BodyWeightReposit
as _i5.Future<void>);
@override
_i5.Future<void> updateLocalDrift(_i10.WeightEntry? entry) =>
_i5.Future<void> updateLocalDrift(_i11.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -324,7 +323,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i9.BodyWeightReposit
as _i5.Future<void>);
@override
_i5.Future<void> addLocalDrift(_i10.WeightEntry? entry) =>
_i5.Future<void> addLocalDrift(_i11.WeightEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i5.Future<void>.value(),
@@ -336,7 +335,7 @@ class MockBodyWeightRepository extends _i1.Mock implements _i9.BodyWeightReposit
/// A class which mocks [UserProfileRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockUserProfileRepository extends _i1.Mock implements _i11.UserProfileRepository {
class MockUserProfileRepository extends _i1.Mock implements _i12.UserProfileRepository {
MockUserProfileRepository() {
_i1.throwOnMissingStub(this);
}

View File

@@ -153,6 +153,19 @@ final cake = Ingredient(
sodium: 0,
);
/// Three diary entries matching the meals on [getNutritionalPlan]: 100 g of
/// `ingredient1` (Water), 75 g of `ingredient2` (Burger soup), and 300 g of
/// `ingredient3` (Broccoli cake). Useful as a pre-hydrated payload for
/// `watchAllLogsHydrated` mocks.
List<LogItem> getTestNutritionLogs() => [
LogItem(planId: 1, mealId: 1, ingredientId: 1, amount: 100, datetime: DateTime(2021, 6, 1))
..ingredient = ingredient1,
LogItem(planId: 1, mealId: 1, ingredientId: 2, amount: 75, datetime: DateTime(2021, 6, 1))
..ingredient = ingredient2,
LogItem(planId: 1, mealId: 1, ingredientId: 3, amount: 300, datetime: DateTime(2021, 6, 10))
..ingredient = ingredient3,
];
NutritionalPlan getNutritionalPlan() {
final mealItem1 = MealItem(ingredientId: 1, amount: 100);
mealItem1.ingredient = ingredient1;
@@ -186,11 +199,7 @@ NutritionalPlan getNutritionalPlan() {
startDate: DateTime(2021, 5, 23),
);
plan.meals = [meal1, meal2];
// Add logs
plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1)));
plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1)));
plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10)));
plan.diaryEntries = getTestNutritionLogs();
return plan;
}
@@ -227,16 +236,16 @@ NutritionalPlan getNutritionalPlanScreenshot() {
);
// Add logs
plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime.now()));
plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime.now()));
plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime.now()));
plan.diaryEntries.add(LogItem.fromMealItem(mealItem1, 1, 1, DateTime.now()));
plan.diaryEntries.add(LogItem.fromMealItem(mealItem2, 1, 1, DateTime.now()));
plan.diaryEntries.add(LogItem.fromMealItem(mealItem3, 1, 1, DateTime.now()));
for (final i in plan.diaryEntries) {
i.datetime = DateTime.now();
i.amount = i.amount / (1.0 + random.nextDouble() * (4.0 - 1.0));
}
final log = Log(
final log = LogItem(
mealId: meal1.id,
ingredientId: 1,
weightUnitId: 1,