mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Merge pull request #214 from wger-project/feature/ingredient-images
Add ingredient images
This commit is contained in:
@@ -11,12 +11,12 @@ import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
import '../test/other/base_provider_test.mocks.dart';
|
||||
import '../test/utils.dart';
|
||||
import '../test/user/provider_test.mocks.dart';
|
||||
|
||||
Widget createNutritionalPlanScreen({locale = 'en'}) {
|
||||
var mockBaseProvider = MockWgerBaseProvider();
|
||||
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final client = MockClient();
|
||||
|
||||
final muesli = Ingredient(
|
||||
id: 1,
|
||||
@@ -96,7 +96,7 @@ Widget createNutritionalPlanScreen({locale = 'en'}) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(testAuthProvider, [], client),
|
||||
create: (context) => NutritionPlansProvider(mockBaseProvider, []),
|
||||
),
|
||||
ChangeNotifierProvider<BodyWeightProvider>(
|
||||
create: (context) => BodyWeightProvider(mockBaseProvider),
|
||||
|
||||
@@ -84,9 +84,12 @@ class MyApp extends StatelessWidget {
|
||||
previous ?? WorkoutPlansProvider(WgerBaseProvider(auth), exercises, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
|
||||
create: (context) =>
|
||||
NutritionPlansProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) => previous ?? NutritionPlansProvider(auth, []),
|
||||
create: (context) => NutritionPlansProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false)),
|
||||
[],
|
||||
),
|
||||
update: (context, auth, previous) =>
|
||||
previous ?? NutritionPlansProvider(WgerBaseProvider(auth), []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, MeasurementProvider>(
|
||||
create: (context) => MeasurementProvider(
|
||||
|
||||
52
lib/models/nutrition/image.dart
Normal file
52
lib/models/nutrition/image.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) 2020, 2021 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'image.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class IngredientImage {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
|
||||
/// Barcode of the product
|
||||
@JsonKey(required: true)
|
||||
final String uuid;
|
||||
|
||||
/// Name of the product
|
||||
@JsonKey(required: true, name: 'ingredient_id')
|
||||
final String ingredientId;
|
||||
|
||||
@JsonKey(required: true)
|
||||
final String image;
|
||||
|
||||
/// Size in bytes
|
||||
@JsonKey(required: true)
|
||||
final int size;
|
||||
|
||||
const IngredientImage(
|
||||
{required this.id,
|
||||
required this.uuid,
|
||||
required this.ingredientId,
|
||||
required this.image,
|
||||
required this.size});
|
||||
|
||||
// Boilerplate
|
||||
factory IngredientImage.fromJson(Map<String, dynamic> json) => _$IngredientImageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$IngredientImageToJson(this);
|
||||
}
|
||||
29
lib/models/nutrition/image.g.dart
Normal file
29
lib/models/nutrition/image.g.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'image.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
IngredientImage _$IngredientImageFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(
|
||||
json,
|
||||
requiredKeys: const ['id', 'uuid', 'ingredient_id', 'image', 'size'],
|
||||
);
|
||||
return IngredientImage(
|
||||
id: json['id'] as int,
|
||||
uuid: json['uuid'] as String,
|
||||
ingredientId: json['ingredient_id'] as String,
|
||||
image: json['image'] as String,
|
||||
size: json['size'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$IngredientImageToJson(IngredientImage instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'ingredient_id': instance.ingredientId,
|
||||
'image': instance.image,
|
||||
'size': instance.size,
|
||||
};
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:wger/models/nutrition/image.dart';
|
||||
|
||||
part 'ingredient.g.dart';
|
||||
|
||||
@@ -68,7 +69,9 @@ class Ingredient {
|
||||
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString)
|
||||
final num sodium;
|
||||
|
||||
const Ingredient({
|
||||
IngredientImage? image;
|
||||
|
||||
Ingredient({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
@@ -81,6 +84,7 @@ class Ingredient {
|
||||
required this.fatSaturated,
|
||||
required this.fibres,
|
||||
required this.sodium,
|
||||
this.image,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -37,6 +37,9 @@ Ingredient _$IngredientFromJson(Map<String, dynamic> json) {
|
||||
fatSaturated: stringToNum(json['fat_saturated'] as String?),
|
||||
fibres: stringToNum(json['fibres'] as String?),
|
||||
sodium: stringToNum(json['sodium'] as String?),
|
||||
image: json['image'] == null
|
||||
? null
|
||||
: IngredientImage.fromJson(json['image'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,4 +56,5 @@ Map<String, dynamic> _$IngredientToJson(Ingredient instance) => <String, dynamic
|
||||
'fat_saturated': numToString(instance.fatSaturated),
|
||||
'fibres': numToString(instance.fibres),
|
||||
'sodium': numToString(instance.sodium),
|
||||
'image': instance.image,
|
||||
};
|
||||
|
||||
@@ -32,7 +32,6 @@ class MeasurementProvider with ChangeNotifier {
|
||||
List<MeasurementCategory> _categories = [];
|
||||
|
||||
MeasurementProvider(this.baseProvider);
|
||||
//: super(auth, client);
|
||||
|
||||
List<MeasurementCategory> get categories => _categories;
|
||||
|
||||
|
||||
@@ -18,23 +18,21 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/exceptions/no_such_entry_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/nutrition/image.dart';
|
||||
import 'package:wger/models/nutrition/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';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
|
||||
class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
class NutritionPlansProvider with ChangeNotifier {
|
||||
static const _nutritionalPlansPath = 'nutritionplan';
|
||||
static const _nutritionalPlansInfoPath = 'nutritionplaninfo';
|
||||
static const _mealPath = 'meal';
|
||||
@@ -42,18 +40,22 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
static const _ingredientPath = 'ingredient';
|
||||
static const _ingredientSearchPath = 'ingredient/search';
|
||||
static const _nutritionDiaryPath = 'nutritiondiary';
|
||||
static const _ingredientImagePath = 'ingredient-image';
|
||||
|
||||
final WgerBaseProvider baseProvider;
|
||||
List<NutritionalPlan> _plans = [];
|
||||
List<Ingredient> _ingredients = [];
|
||||
|
||||
NutritionPlansProvider(AuthProvider auth, List<NutritionalPlan> entries, [http.Client? client])
|
||||
: _plans = entries,
|
||||
super(auth, client);
|
||||
NutritionPlansProvider(this.baseProvider, List<NutritionalPlan> entries) : _plans = entries;
|
||||
|
||||
List<NutritionalPlan> get items {
|
||||
return [..._plans];
|
||||
}
|
||||
|
||||
set ingredients(items) {
|
||||
_ingredients = items;
|
||||
}
|
||||
|
||||
/// Clears all lists
|
||||
void clear() {
|
||||
_plans = [];
|
||||
@@ -88,9 +90,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Fetches and sets all plans sparsely, i.e. only with the data on the plan
|
||||
/// object itself and no child attributes
|
||||
Future<void> fetchAndSetAllPlansSparse() async {
|
||||
final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
|
||||
final data = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
|
||||
_plans = [];
|
||||
for (final planData in data['results']) {
|
||||
for (final planData in data) {
|
||||
final plan = NutritionalPlan.fromJson(planData);
|
||||
_plans.add(plan);
|
||||
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
|
||||
@@ -100,8 +103,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Fetches and sets all plans fully, i.e. with all corresponding child objects
|
||||
Future<void> fetchAndSetAllPlansFull() async {
|
||||
final data = await fetch(makeUrl(_nutritionalPlansPath));
|
||||
for (final entry in data['results']) {
|
||||
final data = await baseProvider.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath));
|
||||
for (final entry in data) {
|
||||
await fetchAndSetPlanFull(entry['id']);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +114,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// This method only loads the data on the nutritional plan object itself,
|
||||
/// no meals, etc.
|
||||
Future<NutritionalPlan> fetchAndSetPlanSparse(int planId) async {
|
||||
final planData = await fetch(makeUrl(_nutritionalPlansPath, id: planId));
|
||||
final url = baseProvider.makeUrl(_nutritionalPlansPath, id: planId);
|
||||
final planData = await baseProvider.fetch(url);
|
||||
final plan = NutritionalPlan.fromJson(planData);
|
||||
_plans.add(plan);
|
||||
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
|
||||
@@ -125,12 +129,13 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
NutritionalPlan plan;
|
||||
try {
|
||||
plan = findById(planId);
|
||||
} on NoSuchEntryException catch (e) {
|
||||
} on NoSuchEntryException {
|
||||
plan = await fetchAndSetPlanSparse(planId);
|
||||
}
|
||||
|
||||
// Plan
|
||||
final fullPlanData = await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId));
|
||||
final url = baseProvider.makeUrl(_nutritionalPlansInfoPath, id: planId);
|
||||
final fullPlanData = await baseProvider.fetch(url);
|
||||
|
||||
// Meals
|
||||
final List<Meal> meals = [];
|
||||
@@ -140,7 +145,13 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
for (final mealItemData in mealData['meal_items']) {
|
||||
final mealItem = MealItem.fromJson(mealItemData);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
|
||||
final ingredient = Ingredient.fromJson(mealItemData['ingredient_obj']);
|
||||
if (mealItemData['image'] != null) {
|
||||
final image = IngredientImage.fromJson(mealItemData['image']);
|
||||
ingredient.image = image;
|
||||
}
|
||||
mealItem.ingredientObj = ingredient;
|
||||
mealItems.add(mealItem);
|
||||
}
|
||||
meal.mealItems = mealItems;
|
||||
@@ -157,7 +168,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<NutritionalPlan> addPlan(NutritionalPlan planData) async {
|
||||
final data = await post(planData.toJson(), makeUrl(_nutritionalPlansPath));
|
||||
final data = await baseProvider.post(
|
||||
planData.toJson(),
|
||||
baseProvider.makeUrl(_nutritionalPlansPath),
|
||||
);
|
||||
final plan = NutritionalPlan.fromJson(data);
|
||||
_plans.add(plan);
|
||||
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
|
||||
@@ -166,7 +180,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editPlan(NutritionalPlan plan) async {
|
||||
await patch(plan.toJson(), makeUrl(_nutritionalPlansPath, id: plan.id));
|
||||
await baseProvider.patch(
|
||||
plan.toJson(),
|
||||
baseProvider.makeUrl(_nutritionalPlansPath, id: plan.id),
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -176,7 +193,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_plans.removeAt(existingPlanIndex);
|
||||
notifyListeners();
|
||||
|
||||
final response = await deleteRequest(_nutritionalPlansPath, id);
|
||||
final response = await baseProvider.deleteRequest(_nutritionalPlansPath, id);
|
||||
|
||||
if (response.statusCode >= 400) {
|
||||
_plans.insert(existingPlanIndex, existingPlan);
|
||||
@@ -189,7 +206,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Adds a meal to a plan
|
||||
Future<Meal> addMeal(Meal meal, int planId) async {
|
||||
final plan = findById(planId);
|
||||
final data = await post(meal.toJson(), makeUrl(_mealPath));
|
||||
final data = await baseProvider.post(
|
||||
meal.toJson(),
|
||||
baseProvider.makeUrl(_mealPath),
|
||||
);
|
||||
|
||||
meal = Meal.fromJson(data);
|
||||
plan.meals.add(meal);
|
||||
@@ -200,7 +220,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Edits an existing meal
|
||||
Future<Meal> editMeal(Meal meal) async {
|
||||
final data = await patch(meal.toJson(), makeUrl(_mealPath, id: meal.id));
|
||||
final data = await baseProvider.patch(
|
||||
meal.toJson(),
|
||||
baseProvider.makeUrl(_mealPath, id: meal.id),
|
||||
);
|
||||
meal = Meal.fromJson(data);
|
||||
|
||||
notifyListeners();
|
||||
@@ -217,7 +240,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealPath, meal.id!);
|
||||
final response = await baseProvider.deleteRequest(_mealPath, meal.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
plan.meals.insert(mealIndex, existingMeal);
|
||||
notifyListeners();
|
||||
@@ -227,7 +250,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Adds a meal item to a meal
|
||||
Future<MealItem> addMealItem(MealItem mealItem, Meal meal) async {
|
||||
final data = await post(mealItem.toJson(), makeUrl(_mealItemPath));
|
||||
final data = await baseProvider.post(mealItem.toJson(), baseProvider.makeUrl(_mealItemPath));
|
||||
|
||||
mealItem = MealItem.fromJson(data);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
@@ -247,7 +270,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealItemPath, mealItem.id!);
|
||||
final response = await baseProvider.deleteRequest(_mealItemPath, mealItem.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
meal.mealItems.insert(mealItemIndex, existingMealItem);
|
||||
notifyListeners();
|
||||
@@ -267,7 +290,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Get ingredient from the server and save to cache
|
||||
} on StateError {
|
||||
final data = await fetch(makeUrl(_ingredientPath, id: ingredientId));
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientPath, id: ingredientId),
|
||||
);
|
||||
ingredient = Ingredient.fromJson(data);
|
||||
_ingredients.add(ingredient);
|
||||
|
||||
@@ -305,30 +330,28 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Searches for an ingredient
|
||||
Future<List> searchIngredient(String name, [String languageCode = 'en']) async {
|
||||
Future<List> searchIngredient(
|
||||
String name, {
|
||||
String languageCode = 'en',
|
||||
bool searchEnglish = false,
|
||||
}) async {
|
||||
if (name.length <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
makeUrl(
|
||||
_ingredientSearchPath,
|
||||
query: {'term': name, 'language': languageCode},
|
||||
),
|
||||
headers: <String, String>{
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
},
|
||||
);
|
||||
|
||||
// Something wrong with our request
|
||||
if (response.statusCode >= 400) {
|
||||
throw WgerHttpException(response.body);
|
||||
final languages = [languageCode];
|
||||
if (searchEnglish && languageCode != LANGUAGE_SHORT_ENGLISH) {
|
||||
languages.add(LANGUAGE_SHORT_ENGLISH);
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await baseProvider.fetch(
|
||||
baseProvider
|
||||
.makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languages.join(',')}),
|
||||
);
|
||||
|
||||
// Process the response
|
||||
return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
|
||||
return response['suggestions'];
|
||||
}
|
||||
|
||||
/// Searches for an ingredient with code
|
||||
@@ -338,14 +361,11 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final data = await fetch(
|
||||
makeUrl(
|
||||
_ingredientPath,
|
||||
query: {'code': code},
|
||||
),
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientPath, query: {'code': code}),
|
||||
);
|
||||
|
||||
if (data["count"] == 0) {
|
||||
if (data['count'] == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return Ingredient.fromJson(data['results'][0]);
|
||||
@@ -358,7 +378,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
final plan = findById(meal.planId);
|
||||
final Log log = Log.fromMealItem(item, plan.id!, meal.id);
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
final data = await baseProvider.post(
|
||||
log.toJson(),
|
||||
baseProvider.makeUrl(_nutritionDiaryPath),
|
||||
);
|
||||
log.id = data['id'];
|
||||
plan.logs.add(log);
|
||||
}
|
||||
@@ -371,7 +394,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
final Log log = Log.fromMealItem(mealItem, plan.id!, null, dateTime);
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
final data = await baseProvider.post(log.toJson(), baseProvider.makeUrl(_nutritionDiaryPath));
|
||||
log.id = data['id'];
|
||||
plan.logs.add(log);
|
||||
notifyListeners();
|
||||
@@ -379,7 +402,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Deletes a log entry
|
||||
Future<void> deleteLog(int logId, int planId) async {
|
||||
await deleteRequest(_nutritionDiaryPath, logId);
|
||||
await baseProvider.deleteRequest(_nutritionDiaryPath, logId);
|
||||
|
||||
final plan = findById(planId);
|
||||
plan.logs.removeWhere((element) => element.id == logId);
|
||||
@@ -388,13 +411,15 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Load nutrition diary entries for plan
|
||||
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
|
||||
// TODO(x): update fetch to that it can use the pagination
|
||||
final data = await fetch(
|
||||
makeUrl(_nutritionDiaryPath, query: {'plan': plan.id.toString(), 'limit': '1000'}),
|
||||
final data = await baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(
|
||||
_nutritionDiaryPath,
|
||||
query: {'plan': plan.id.toString(), 'limit': '999'},
|
||||
),
|
||||
);
|
||||
|
||||
plan.logs = [];
|
||||
for (final logData in data['results']) {
|
||||
for (final logData in data) {
|
||||
final log = Log.fromJson(logData);
|
||||
final ingredient = await fetchIngredient(log.ingredientId);
|
||||
log.ingredientObj = ingredient;
|
||||
|
||||
@@ -58,3 +58,24 @@ class Pill extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CircleIconAvatar extends StatelessWidget {
|
||||
final double radius;
|
||||
final Icon _icon;
|
||||
|
||||
final Color color;
|
||||
|
||||
const CircleIconAvatar(this._icon, {this.radius = 20, this.color = Colors.black12});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CircleAvatar(
|
||||
backgroundColor: color,
|
||||
radius: radius,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50.0),
|
||||
child: _icon,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
@@ -148,9 +147,9 @@ class MealItemForm extends StatelessWidget {
|
||||
IngredientTypeahead(
|
||||
_ingredientIdController,
|
||||
_ingredientController,
|
||||
true,
|
||||
_barcode,
|
||||
_test,
|
||||
showScanner: true,
|
||||
barcode: _barcode,
|
||||
test: _test,
|
||||
),
|
||||
TextFormField(
|
||||
key: const Key('field-weight'),
|
||||
@@ -255,9 +254,6 @@ class IngredientLogForm extends StatelessWidget {
|
||||
IngredientTypeahead(
|
||||
_ingredientIdController,
|
||||
_ingredientController,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
|
||||
@@ -277,7 +273,8 @@ class IngredientLogForm extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
readOnly: true, // Stop keyboard from appearing
|
||||
readOnly: true,
|
||||
// Stop keyboard from appearing
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).date,
|
||||
suffixIcon: const Icon(Icons.calendar_today_outlined),
|
||||
|
||||
@@ -17,29 +17,29 @@
|
||||
*/
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_values.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
|
||||
List<Widget> getMutedNutritionalValues(NutritionalValues values, BuildContext context) {
|
||||
final List<Widget> out = [
|
||||
MutedText(
|
||||
Text(
|
||||
'${AppLocalizations.of(context).energy}: '
|
||||
'${values.energy.toStringAsFixed(0)}'
|
||||
'${AppLocalizations.of(context).kcal}',
|
||||
),
|
||||
MutedText(
|
||||
Text(
|
||||
'${AppLocalizations.of(context).protein}: '
|
||||
'${values.protein.toStringAsFixed(0)}'
|
||||
'${AppLocalizations.of(context).g}',
|
||||
),
|
||||
MutedText(
|
||||
Text(
|
||||
'${AppLocalizations.of(context).carbohydrates}: '
|
||||
'${values.carbohydrates.toStringAsFixed(0)} '
|
||||
'${AppLocalizations.of(context).g} '
|
||||
'(${values.carbohydratesSugar.toStringAsFixed(0)} ${AppLocalizations.of(context).sugars})',
|
||||
),
|
||||
MutedText(
|
||||
Text(
|
||||
'${AppLocalizations.of(context).fat}: '
|
||||
'${values.fat.toStringAsFixed(0)}'
|
||||
'${AppLocalizations.of(context).g} '
|
||||
|
||||
@@ -25,6 +25,7 @@ import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
import 'package:wger/widgets/nutrition/helpers.dart';
|
||||
|
||||
@@ -160,46 +161,37 @@ class MealItemWidget extends StatelessWidget {
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
final values = _item.nutritionalValues;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
'${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredientObj.name}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)),
|
||||
if (_expanded)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
iconSize: ICON_SIZE_SMALL,
|
||||
onPressed: () {
|
||||
// Delete the meal item
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.deleteMealItem(_item);
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
)),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_expanded) ...getMutedNutritionalValues(values, context),
|
||||
],
|
||||
return ListTile(
|
||||
leading: _item.ingredientObj.image != null
|
||||
? CircleAvatar(backgroundImage: NetworkImage(_item.ingredientObj.image!.image))
|
||||
: const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)),
|
||||
title: Text(
|
||||
'${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredientObj.name}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [if (_expanded) ...getMutedNutritionalValues(values, context)],
|
||||
),
|
||||
trailing: _expanded
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
iconSize: ICON_SIZE_SMALL,
|
||||
onPressed: () {
|
||||
// Delete the meal item
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false).deleteMealItem(_item);
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
)),
|
||||
);
|
||||
},
|
||||
)
|
||||
: const SizedBox(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,30 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
|
||||
class IngredientTypeahead extends StatefulWidget {
|
||||
final TextEditingController _ingredientController;
|
||||
final TextEditingController _ingredientIdController;
|
||||
late String? _barcode;
|
||||
late final bool? _test;
|
||||
final bool _showScanner;
|
||||
|
||||
IngredientTypeahead(this._ingredientIdController, this._ingredientController, this._showScanner,
|
||||
[this._barcode, this._test]);
|
||||
String? barcode = '';
|
||||
late final bool? test;
|
||||
final bool showScanner;
|
||||
|
||||
IngredientTypeahead(
|
||||
this._ingredientIdController,
|
||||
this._ingredientController, {
|
||||
this.showScanner = true,
|
||||
this.test = false,
|
||||
this.barcode = '',
|
||||
});
|
||||
|
||||
@override
|
||||
_IngredientTypeaheadState createState() => _IngredientTypeaheadState();
|
||||
@@ -44,7 +51,12 @@ Future<String> scanBarcode(BuildContext context) async {
|
||||
String barcode;
|
||||
try {
|
||||
barcode = await FlutterBarcodeScanner.scanBarcode(
|
||||
'#ff6666', AppLocalizations.of(context).close, true, ScanMode.BARCODE);
|
||||
'#ff6666',
|
||||
AppLocalizations.of(context).close,
|
||||
true,
|
||||
ScanMode.BARCODE,
|
||||
);
|
||||
|
||||
if (barcode.compareTo('-1') == 0) {
|
||||
return '';
|
||||
}
|
||||
@@ -56,113 +68,134 @@ Future<String> scanBarcode(BuildContext context) async {
|
||||
}
|
||||
|
||||
class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
var _searchEnglish = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TypeAheadFormField(
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: widget._ingredientController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
labelText: AppLocalizations.of(context).searchIngredient,
|
||||
suffixIcon: widget._showScanner ? scanButton() : null,
|
||||
return Column(
|
||||
children: [
|
||||
TypeAheadFormField(
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: widget._ingredientController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
labelText: AppLocalizations.of(context).searchIngredient,
|
||||
suffixIcon: widget.showScanner ? scanButton() : null,
|
||||
),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return Provider.of<NutritionPlansProvider>(context, listen: false).searchIngredient(
|
||||
pattern,
|
||||
languageCode: Localizations.localeOf(context).languageCode,
|
||||
searchEnglish: _searchEnglish,
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, dynamic suggestion) {
|
||||
final url = context.read<NutritionPlansProvider>().baseProvider.auth.serverUrl;
|
||||
return ListTile(
|
||||
leading: suggestion['data']['image'] != null
|
||||
? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image']))
|
||||
: const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)),
|
||||
title: Text(suggestion['value']),
|
||||
);
|
||||
},
|
||||
transitionBuilder: (context, suggestionsBox, controller) {
|
||||
return suggestionsBox;
|
||||
},
|
||||
onSuggestionSelected: (dynamic suggestion) {
|
||||
widget._ingredientIdController.text = suggestion['data']['id'].toString();
|
||||
widget._ingredientController.text = suggestion['value'];
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
return AppLocalizations.of(context).selectIngredient;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return Provider.of<NutritionPlansProvider>(context, listen: false).searchIngredient(
|
||||
pattern,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, dynamic suggestion) {
|
||||
return ListTile(
|
||||
title: Text(suggestion['value']),
|
||||
subtitle: Text(suggestion['data']['id'].toString()),
|
||||
);
|
||||
},
|
||||
transitionBuilder: (context, suggestionsBox, controller) {
|
||||
return suggestionsBox;
|
||||
},
|
||||
onSuggestionSelected: (dynamic suggestion) {
|
||||
widget._ingredientIdController.text = suggestion['data']['id'].toString();
|
||||
widget._ingredientController.text = suggestion['value'];
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
return AppLocalizations.of(context).selectIngredient;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
if (Localizations.localeOf(context).languageCode != LANGUAGE_SHORT_ENGLISH)
|
||||
SwitchListTile(
|
||||
title: Text(AppLocalizations.of(context).searchNamesInEnglish),
|
||||
value: _searchEnglish,
|
||||
onChanged: (_) {
|
||||
setState(() {
|
||||
_searchEnglish = !_searchEnglish;
|
||||
});
|
||||
},
|
||||
dense: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget scanButton() {
|
||||
return IconButton(
|
||||
key: const Key('scan-button'),
|
||||
onPressed: () async {
|
||||
try {
|
||||
if (!widget._test!) {
|
||||
widget._barcode = await scanBarcode(context);
|
||||
}
|
||||
|
||||
if (widget._barcode!.isNotEmpty) {
|
||||
final result = await Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.searchIngredientWithCode(widget._barcode!);
|
||||
|
||||
if (result != null) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
key: const Key('found-dialog'),
|
||||
title: Text(AppLocalizations.of(context).productFound),
|
||||
content:
|
||||
Text(AppLocalizations.of(context).productFoundDescription(result.name)),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('found-dialog-confirm-button'),
|
||||
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
|
||||
onPressed: () {
|
||||
widget._ingredientController.text = result.name;
|
||||
widget._ingredientIdController.text = result.id.toString();
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
key: const Key('found-dialog-close-button'),
|
||||
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
//nothing is matching barcode
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
key: const Key('notFound-dialog'),
|
||||
title: Text(AppLocalizations.of(context).productNotFound),
|
||||
content: Text(
|
||||
AppLocalizations.of(context).productNotFoundDescription(widget._barcode!),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('notFound-dialog-close-button'),
|
||||
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
showErrorDialog(e, context);
|
||||
key: const Key('scan-button'),
|
||||
onPressed: () async {
|
||||
try {
|
||||
if (!widget.test!) {
|
||||
widget.barcode = await scanBarcode(context);
|
||||
}
|
||||
},
|
||||
icon: Image.asset('assets/images/barcode_scanner_icon.png'));
|
||||
|
||||
if (widget.barcode!.isNotEmpty) {
|
||||
final result = await Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.searchIngredientWithCode(widget.barcode!);
|
||||
|
||||
if (result != null) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
key: const Key('found-dialog'),
|
||||
title: Text(AppLocalizations.of(context).productFound),
|
||||
content: Text(AppLocalizations.of(context).productFoundDescription(result.name)),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('found-dialog-confirm-button'),
|
||||
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
|
||||
onPressed: () {
|
||||
widget._ingredientController.text = result.name;
|
||||
widget._ingredientIdController.text = result.id.toString();
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
key: const Key('found-dialog-close-button'),
|
||||
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
//nothing is matching barcode
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
key: const Key('notFound-dialog'),
|
||||
title: Text(AppLocalizations.of(context).productNotFound),
|
||||
content: Text(
|
||||
AppLocalizations.of(context).productNotFoundDescription(widget.barcode!),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('notFound-dialog-close-button'),
|
||||
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
showErrorDialog(e, context);
|
||||
}
|
||||
},
|
||||
icon: Image.asset('assets/images/barcode_scanner_icon.png'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
18
test/fixtures/nutrition/ingredient_10065_response.json
vendored
Normal file
18
test/fixtures/nutrition/ingredient_10065_response.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"id": 10065,
|
||||
"code": "0043647440020",
|
||||
"name": "'Old Times' Orange Fine Cut Marmalade",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 269,
|
||||
"protein": "0.000",
|
||||
"carbohydrates": "67.000",
|
||||
"carbohydrates_sugar": "66.000",
|
||||
"fat": "0.000",
|
||||
"fat_saturated": "0.000",
|
||||
"fibres": null,
|
||||
"sodium": "0.000",
|
||||
"license": 5,
|
||||
"license_author": "Open Food Facts",
|
||||
"language": 2
|
||||
}
|
||||
18
test/fixtures/nutrition/ingredient_58300_response.json
vendored
Normal file
18
test/fixtures/nutrition/ingredient_58300_response.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"id": 58300,
|
||||
"code": "4071800000992",
|
||||
"name": "1688 Mehrkorn",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 229,
|
||||
"protein": "7.680",
|
||||
"carbohydrates": "35.700",
|
||||
"carbohydrates_sugar": "2.320",
|
||||
"fat": "4.820",
|
||||
"fat_saturated": "0.714",
|
||||
"fibres": "6.960",
|
||||
"sodium": "0.000",
|
||||
"license": 5,
|
||||
"license_author": "Open Food Facts",
|
||||
"language": 2
|
||||
}
|
||||
18
test/fixtures/nutrition/ingredient_59887_response.json
vendored
Normal file
18
test/fixtures/nutrition/ingredient_59887_response.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"id": 59887,
|
||||
"code": "4311501354155",
|
||||
"name": "Baked Beans",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 86,
|
||||
"protein": "4.400",
|
||||
"carbohydrates": "11.000",
|
||||
"carbohydrates_sugar": "5.300",
|
||||
"fat": "0.100",
|
||||
"fat_saturated": "0.000",
|
||||
"fibres": "5.000",
|
||||
"sodium": "0.480",
|
||||
"license": 5,
|
||||
"license_author": "Open Food Facts",
|
||||
"language": 1
|
||||
}
|
||||
34
test/fixtures/nutrition/nutrition_diary_response.json
vendored
Normal file
34
test/fixtures/nutrition/nutrition_diary_response.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
7
test/fixtures/nutrition/nutritional_plan_detail_response.json
vendored
Normal file
7
test/fixtures/nutrition/nutritional_plan_detail_response.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"id": 1,
|
||||
"creation_date": "2022-08-09",
|
||||
"description": "",
|
||||
"has_goal_calories": false,
|
||||
"language": 1
|
||||
}
|
||||
191
test/fixtures/nutrition/nutritional_plan_info_detail_response.json
vendored
Normal file
191
test/fixtures/nutrition/nutritional_plan_info_detail_response.json
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
{
|
||||
"id": 1,
|
||||
"language": {
|
||||
"id": 1,
|
||||
"short_name": "de",
|
||||
"full_name": "Deutsch"
|
||||
},
|
||||
"creation_date": "2022-08-09",
|
||||
"description": "",
|
||||
"get_nutritional_values": {
|
||||
"total": {
|
||||
"energy": 853.0,
|
||||
"protein": 12.08,
|
||||
"carbohydrates": 180.7,
|
||||
"carbohydrates_sugar": 139.62,
|
||||
"fat": 4.92,
|
||||
"fat_saturated": 0.71,
|
||||
"fibres": 11.96,
|
||||
"sodium": 0.48,
|
||||
"energy_kilojoule": 3568.95
|
||||
},
|
||||
"percent": {
|
||||
"protein": 5.66,
|
||||
"carbohydrates": 84.74,
|
||||
"fat": 5.19
|
||||
},
|
||||
"per_kg": {
|
||||
"protein": 0.0,
|
||||
"carbohydrates": 0.0,
|
||||
"fat": 0.0
|
||||
}
|
||||
},
|
||||
"meals": [
|
||||
{
|
||||
"id": 1,
|
||||
"plan": 1,
|
||||
"order": 1,
|
||||
"time": "08:00:00",
|
||||
"name": "Frühstück",
|
||||
"meal_items": [
|
||||
{
|
||||
"id": 1,
|
||||
"meal": 1,
|
||||
"ingredient": 59887,
|
||||
"ingredient_obj": {
|
||||
"id": 59887,
|
||||
"code": "4311501354155",
|
||||
"name": "Baked Beans",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 86,
|
||||
"protein": "4.400",
|
||||
"carbohydrates": "11.000",
|
||||
"carbohydrates_sugar": "5.300",
|
||||
"fat": "0.100",
|
||||
"fat_saturated": "0.000",
|
||||
"fibres": "5.000",
|
||||
"sodium": "0.480",
|
||||
"license": {
|
||||
"id": 5,
|
||||
"full_name": "Open Data Commons Open Database License",
|
||||
"short_name": "ODbL",
|
||||
"url": "https://opendatacommons.org/licenses/odbl/"
|
||||
},
|
||||
"license_author": "Open Food Facts",
|
||||
"ingredientweightunit_set": [],
|
||||
"language": {
|
||||
"id": 1,
|
||||
"short_name": "de",
|
||||
"full_name": "Deutsch"
|
||||
}
|
||||
},
|
||||
"weight_unit": null,
|
||||
"weight_unit_obj": null,
|
||||
"image": null,
|
||||
"order": 1,
|
||||
"amount": "100.00"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"meal": 1,
|
||||
"ingredient": 58300,
|
||||
"ingredient_obj": {
|
||||
"id": 58300,
|
||||
"code": "4071800000992",
|
||||
"name": "1688 Mehrkorn",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 229,
|
||||
"protein": "7.680",
|
||||
"carbohydrates": "35.700",
|
||||
"carbohydrates_sugar": "2.320",
|
||||
"fat": "4.820",
|
||||
"fat_saturated": "0.714",
|
||||
"fibres": "6.960",
|
||||
"sodium": "0.000",
|
||||
"license": {
|
||||
"id": 5,
|
||||
"full_name": "Open Data Commons Open Database License",
|
||||
"short_name": "ODbL",
|
||||
"url": "https://opendatacommons.org/licenses/odbl/"
|
||||
},
|
||||
"license_author": "Open Food Facts",
|
||||
"ingredientweightunit_set": [],
|
||||
"language": {
|
||||
"id": 2,
|
||||
"short_name": "en",
|
||||
"full_name": "English"
|
||||
}
|
||||
},
|
||||
"weight_unit": null,
|
||||
"weight_unit_obj": null,
|
||||
"image": {
|
||||
"id": 3,
|
||||
"uuid": "778fe5cb-a5d9-42e5-9df2-2a47022b720f",
|
||||
"ingredient_id": "58300",
|
||||
"ingredient_uuid": "60e1f479-9af1-4bd4-b2a8-1ebe8974258e",
|
||||
"image": "http://localhost:8000/media/ingredients/60e1f479-9af1-4bd4-b2a8-1ebe8974258e/778fe5cb-a5d9-42e5-9df2-2a47022b720f.jpg",
|
||||
"last_update": "2022-08-09T15:31:46.833918+02:00",
|
||||
"size": 33617,
|
||||
"source_url": "",
|
||||
"license": 1,
|
||||
"license_author": "kiliweb"
|
||||
},
|
||||
"order": 1,
|
||||
"amount": "100.00"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"meal": 1,
|
||||
"ingredient": 10065,
|
||||
"ingredient_obj": {
|
||||
"id": 10065,
|
||||
"code": "0043647440020",
|
||||
"name": "'Old Times' Orange Fine Cut Marmalade",
|
||||
"creation_date": "2020-12-20",
|
||||
"update_date": "2022-08-09",
|
||||
"energy": 269,
|
||||
"protein": "0.000",
|
||||
"carbohydrates": "67.000",
|
||||
"carbohydrates_sugar": "66.000",
|
||||
"fat": "0.000",
|
||||
"fat_saturated": "0.000",
|
||||
"fibres": null,
|
||||
"sodium": "0.000",
|
||||
"license": {
|
||||
"id": 5,
|
||||
"full_name": "Open Data Commons Open Database License",
|
||||
"short_name": "ODbL",
|
||||
"url": "https://opendatacommons.org/licenses/odbl/"
|
||||
},
|
||||
"license_author": "Open Food Facts",
|
||||
"ingredientweightunit_set": [],
|
||||
"language": {
|
||||
"id": 2,
|
||||
"short_name": "en",
|
||||
"full_name": "English"
|
||||
}
|
||||
},
|
||||
"weight_unit": null,
|
||||
"weight_unit_obj": null,
|
||||
"image": {
|
||||
"id": 5,
|
||||
"uuid": "81c07bef-02ea-47ba-a18e-d7388dc2bc01",
|
||||
"ingredient_id": "10065",
|
||||
"ingredient_uuid": "b0c47fa4-3898-4705-b8f5-184877d50b78",
|
||||
"image": "http://localhost:8000/media/ingredients/b0c47fa4-3898-4705-b8f5-184877d50b78/81c07bef-02ea-47ba-a18e-d7388dc2bc01.jpg",
|
||||
"last_update": "2022-08-09T15:45:58.511169+02:00",
|
||||
"size": 43397,
|
||||
"source_url": "",
|
||||
"license": 1,
|
||||
"license_author": "tacinte"
|
||||
},
|
||||
"order": 1,
|
||||
"amount": "200.00"
|
||||
}
|
||||
],
|
||||
"get_nutritional_values": {
|
||||
"energy": 853.0,
|
||||
"protein": 12.08,
|
||||
"carbohydrates": 180.7,
|
||||
"carbohydrates_sugar": 139.62,
|
||||
"fat": 4.92,
|
||||
"fat_saturated": 0.71,
|
||||
"fibres": 11.96,
|
||||
"sodium": 0.48,
|
||||
"energy_kilojoule": 3568.95
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
89
test/nutrition/nutrition_provider_test.dart
Normal file
89
test/nutrition/nutrition_provider_test.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
|
||||
import '../fixtures/fixture_reader.dart';
|
||||
import '../measurements/measurement_provider_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late NutritionPlansProvider nutritionProvider;
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
|
||||
setUp(() {
|
||||
mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, []);
|
||||
|
||||
const String planInfoUrl = 'nutritionplaninfo';
|
||||
const String planUrl = 'nutritionplan';
|
||||
const String diaryUrl = 'nutritiondiary';
|
||||
const String ingredientUrl = 'ingredient';
|
||||
|
||||
final Map<String, dynamic> NutritionalPlanInfoResponse = jsonDecode(
|
||||
fixture('nutrition/nutritional_plan_info_detail_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> NutritionalPlanDetailResponse = jsonDecode(
|
||||
fixture('nutrition/nutritional_plan_detail_response.json'),
|
||||
);
|
||||
final List<dynamic> NutritionDiaryResponse = jsonDecode(
|
||||
fixture('nutrition/nutrition_diary_response.json'),
|
||||
)['results'];
|
||||
final Map<String, dynamic> Ingredient59887Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_59887_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> Ingredient10065Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_10065_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> Ingredient58300Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_58300_response.json'),
|
||||
);
|
||||
|
||||
final ingredientList = [
|
||||
Ingredient.fromJson(Ingredient59887Response),
|
||||
Ingredient.fromJson(Ingredient10065Response),
|
||||
Ingredient.fromJson(Ingredient58300Response),
|
||||
];
|
||||
|
||||
nutritionProvider.ingredients = ingredientList;
|
||||
|
||||
final Uri planInfoUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$planInfoUrl/1',
|
||||
);
|
||||
final Uri planUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$planUrl',
|
||||
);
|
||||
final Uri diaryUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$diaryUrl',
|
||||
);
|
||||
when(mockWgerBaseProvider.makeUrl(planInfoUrl, id: anyNamed('id'))).thenReturn(planInfoUri);
|
||||
when(mockWgerBaseProvider.makeUrl(planUrl, id: anyNamed('id'))).thenReturn(planUri);
|
||||
when(mockWgerBaseProvider.makeUrl(diaryUrl, query: anyNamed('query'))).thenReturn(diaryUri);
|
||||
when(mockWgerBaseProvider.fetch(planInfoUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(NutritionalPlanInfoResponse),
|
||||
);
|
||||
when(mockWgerBaseProvider.fetch(planUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(NutritionalPlanDetailResponse),
|
||||
);
|
||||
when(mockWgerBaseProvider.fetchPaginated(diaryUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(NutritionDiaryResponse),
|
||||
);
|
||||
});
|
||||
|
||||
group('fetchAndSetPlanFull', () {
|
||||
test('should correctly load a full nutritional plan', () async {
|
||||
// arrange
|
||||
await nutritionProvider.fetchAndSetPlanFull(1);
|
||||
|
||||
// assert
|
||||
expect(nutritionProvider.items.isEmpty, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -3,17 +3,16 @@
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i9;
|
||||
import 'dart:ui' as _i10;
|
||||
import 'dart:async' as _i8;
|
||||
import 'dart:ui' as _i9;
|
||||
|
||||
import 'package:http/http.dart' as _i3;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/models/nutrition/ingredient.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/auth.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
|
||||
import 'package:wger/models/nutrition/meal.dart' as _i4;
|
||||
import 'package:wger/models/nutrition/meal_item.dart' as _i5;
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3;
|
||||
import 'package:wger/providers/base_provider.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -26,8 +25,8 @@ import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
_FakeAuthProvider_0(
|
||||
class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider {
|
||||
_FakeWgerBaseProvider_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -36,8 +35,8 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
_FakeClient_1(
|
||||
class _FakeNutritionalPlan_1 extends _i1.SmartFake implements _i3.NutritionalPlan {
|
||||
_FakeNutritionalPlan_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -46,8 +45,8 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan {
|
||||
_FakeNutritionalPlan_2(
|
||||
class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal {
|
||||
_FakeMeal_2(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -56,8 +55,8 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
_FakeMeal_3(
|
||||
class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem {
|
||||
_FakeMealItem_3(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -66,38 +65,8 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
_FakeMealItem_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
_FakeIngredient_5(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_6 extends _i1.SmartFake implements Uri {
|
||||
_FakeUri_6(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
_FakeResponse_7(
|
||||
class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient {
|
||||
_FakeIngredient_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -109,45 +78,29 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
/// A class which mocks [NutritionPlansProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansProvider {
|
||||
class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansProvider {
|
||||
MockNutritionPlansProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i4.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
@override
|
||||
List<_i3.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
) as List<_i4.NutritionalPlan>);
|
||||
returnValue: <_i3.NutritionalPlan>[],
|
||||
) as List<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
@override
|
||||
set auth(_i2.AuthProvider? _auth) => super.noSuchMethod(
|
||||
set ingredients(dynamic items) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
_auth,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
@override
|
||||
set client(_i3.Client? _client) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
_client,
|
||||
#ingredients,
|
||||
items,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@@ -165,105 +118,105 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i4.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
_i3.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
returnValue: _FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i4.NutritionalPlan);
|
||||
) as _i3.NutritionalPlan);
|
||||
@override
|
||||
_i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
_i4.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
)) as _i5.Meal?);
|
||||
)) as _i4.Meal?);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
_i8.Future<void> editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
_i8.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deletePlan,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> addMeal(
|
||||
_i5.Meal? meal,
|
||||
_i8.Future<_i4.Meal> addMeal(
|
||||
_i4.Meal? meal,
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
@@ -274,7 +227,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
@@ -284,34 +237,34 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
) as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
) as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteMeal(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i6.MealItem> addMealItem(
|
||||
_i6.MealItem? mealItem,
|
||||
_i5.Meal? meal,
|
||||
_i8.Future<_i5.MealItem> addMealItem(
|
||||
_i5.MealItem? mealItem,
|
||||
_i4.Meal? meal,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -321,7 +274,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4(
|
||||
returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
@@ -331,74 +284,76 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i6.MealItem>);
|
||||
) as _i8.Future<_i5.MealItem>);
|
||||
@override
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteMealItem(_i5.MealItem? mealItem) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(
|
||||
_i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5(
|
||||
returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i7.Ingredient>);
|
||||
) as _i8.Future<_i6.Ingredient>);
|
||||
@override
|
||||
_i9.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<List<dynamic>> searchIngredient(
|
||||
String? name, [
|
||||
_i8.Future<List<dynamic>> searchIngredient(
|
||||
String? name, {
|
||||
String? languageCode = r'en',
|
||||
]) =>
|
||||
bool? searchEnglish = false,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[
|
||||
name,
|
||||
languageCode,
|
||||
],
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i9.Future<List<dynamic>>);
|
||||
returnValue: _i8.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i8.Future<List<dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(
|
||||
_i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithCode,
|
||||
[code],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
) as _i9.Future<_i7.Ingredient?>);
|
||||
returnValue: _i8.Future<_i6.Ingredient?>.value(),
|
||||
) as _i8.Future<_i6.Ingredient?>);
|
||||
@override
|
||||
_i9.Future<void> logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> logIngredentToDiary(
|
||||
_i6.MealItem? mealItem,
|
||||
_i8.Future<void> logIngredentToDiary(
|
||||
_i5.MealItem? mealItem,
|
||||
int? planId, [
|
||||
DateTime? dateTime,
|
||||
]) =>
|
||||
@@ -411,11 +366,11 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deleteLog(
|
||||
_i8.Future<void> deleteLog(
|
||||
int? logId,
|
||||
int? planId,
|
||||
) =>
|
||||
@@ -427,129 +382,20 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetLogs(_i3.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
@override
|
||||
Uri makeUrl(
|
||||
String? path, {
|
||||
int? id,
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
returnValue: _FakeUri_6(
|
||||
this,
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
),
|
||||
) as Uri);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i9.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i9.Future<List<dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> post(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> patch(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i3.Response> deleteRequest(
|
||||
String? url,
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i3.Response>);
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
void addListener(_i9.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
@@ -557,7 +403,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
void removeListener(_i9.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
|
||||
@@ -19,12 +19,12 @@ import 'package:wger/widgets/nutrition/forms.dart';
|
||||
|
||||
import '../../test_data/nutritional_plans.dart';
|
||||
import '../fixtures/fixture_reader.dart';
|
||||
import '../measurements/measurement_provider_test.mocks.dart';
|
||||
import '../other/base_provider_test.mocks.dart';
|
||||
import '../utils.dart';
|
||||
import 'nutritional_plan_form_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
Ingredient ingr = Ingredient(
|
||||
final ingredient = Ingredient(
|
||||
id: 1,
|
||||
code: '123456787',
|
||||
name: 'Water',
|
||||
@@ -39,9 +39,14 @@ void main() {
|
||||
sodium: 0.5,
|
||||
);
|
||||
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
|
||||
var mockNutrition = MockNutritionPlansProvider();
|
||||
final client = MockClient();
|
||||
final mockNutritionWithClient = NutritionPlansProvider(testAuthProvider, [], client);
|
||||
|
||||
setUp(() {
|
||||
mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
});
|
||||
|
||||
var plan1 = NutritionalPlan.empty();
|
||||
var meal1 = Meal();
|
||||
@@ -50,22 +55,25 @@ void main() {
|
||||
final Uri tUriEmptyCode = Uri.parse('https://localhost/api/v2/ingredient/?code=\"%20\"');
|
||||
final Uri tUriBadCode = Uri.parse('https://localhost/api/v2/ingredient/?code=222');
|
||||
|
||||
when(client.get(tUriRightCode, headers: anyNamed('headers'))).thenAnswer((_) =>
|
||||
Future.value(http.Response(fixture('nutrition/search_ingredient_right_code.json'), 200)));
|
||||
when(client.get(tUriRightCode, headers: anyNamed('headers'))).thenAnswer(
|
||||
(_) => Future.value(http.Response(fixture('nutrition/search_ingredient_right_code.json'), 200)),
|
||||
);
|
||||
|
||||
when(client.get(tUriEmptyCode, headers: anyNamed('headers'))).thenAnswer((_) =>
|
||||
Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)));
|
||||
when(client.get(tUriEmptyCode, headers: anyNamed('headers'))).thenAnswer(
|
||||
(_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)),
|
||||
);
|
||||
|
||||
when(client.get(tUriBadCode, headers: anyNamed('headers'))).thenAnswer((_) =>
|
||||
Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)));
|
||||
when(client.get(tUriBadCode, headers: anyNamed('headers'))).thenAnswer(
|
||||
(_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)),
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
plan1 = getNutritionalPlan();
|
||||
meal1 = plan1.meals.first;
|
||||
final MealItem mealItem = MealItem(ingredientId: ingr.id, amount: 2);
|
||||
final MealItem mealItem = MealItem(ingredientId: ingredient.id, amount: 2);
|
||||
mockNutrition = MockNutritionPlansProvider();
|
||||
|
||||
when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingr));
|
||||
when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingredient));
|
||||
when(mockNutrition.searchIngredientWithCode('')).thenAnswer((_) => Future.value(null));
|
||||
when(mockNutrition.searchIngredientWithCode('222')).thenAnswer((_) => Future.value(null));
|
||||
when(mockNutrition.searchIngredient(any)).thenAnswer((_) =>
|
||||
@@ -138,6 +146,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
group('Test searchIngredientWithCode() function', () {
|
||||
test('with correct code', () async {
|
||||
final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode('123');
|
||||
@@ -155,6 +164,8 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
group('Test weight formfield', () {
|
||||
testWidgets('add empty weight', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true));
|
||||
|
||||
@@ -3,17 +3,16 @@
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i9;
|
||||
import 'dart:ui' as _i10;
|
||||
import 'dart:async' as _i8;
|
||||
import 'dart:ui' as _i9;
|
||||
|
||||
import 'package:http/http.dart' as _i3;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/models/nutrition/ingredient.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/auth.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
|
||||
import 'package:wger/models/nutrition/meal.dart' as _i4;
|
||||
import 'package:wger/models/nutrition/meal_item.dart' as _i5;
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3;
|
||||
import 'package:wger/providers/base_provider.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -26,8 +25,8 @@ import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
_FakeAuthProvider_0(
|
||||
class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider {
|
||||
_FakeWgerBaseProvider_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -36,8 +35,8 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
_FakeClient_1(
|
||||
class _FakeNutritionalPlan_1 extends _i1.SmartFake implements _i3.NutritionalPlan {
|
||||
_FakeNutritionalPlan_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -46,8 +45,8 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan {
|
||||
_FakeNutritionalPlan_2(
|
||||
class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal {
|
||||
_FakeMeal_2(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -56,8 +55,8 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
_FakeMeal_3(
|
||||
class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem {
|
||||
_FakeMealItem_3(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -66,38 +65,8 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
_FakeMealItem_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
_FakeIngredient_5(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_6 extends _i1.SmartFake implements Uri {
|
||||
_FakeUri_6(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
_FakeResponse_7(
|
||||
class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient {
|
||||
_FakeIngredient_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -109,45 +78,29 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
/// A class which mocks [NutritionPlansProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansProvider {
|
||||
class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansProvider {
|
||||
MockNutritionPlansProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i4.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
@override
|
||||
List<_i3.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
) as List<_i4.NutritionalPlan>);
|
||||
returnValue: <_i3.NutritionalPlan>[],
|
||||
) as List<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
@override
|
||||
set auth(_i2.AuthProvider? _auth) => super.noSuchMethod(
|
||||
set ingredients(dynamic items) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
_auth,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
@override
|
||||
set client(_i3.Client? _client) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
_client,
|
||||
#ingredients,
|
||||
items,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@@ -165,105 +118,105 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i4.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
_i3.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
returnValue: _FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i4.NutritionalPlan);
|
||||
) as _i3.NutritionalPlan);
|
||||
@override
|
||||
_i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
_i4.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
)) as _i5.Meal?);
|
||||
)) as _i4.Meal?);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
_i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
) as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
_i8.Future<void> editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
_i8.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deletePlan,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> addMeal(
|
||||
_i5.Meal? meal,
|
||||
_i8.Future<_i4.Meal> addMeal(
|
||||
_i4.Meal? meal,
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
@@ -274,7 +227,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
@@ -284,34 +237,34 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
) as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
) as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteMeal(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i6.MealItem> addMealItem(
|
||||
_i6.MealItem? mealItem,
|
||||
_i5.Meal? meal,
|
||||
_i8.Future<_i5.MealItem> addMealItem(
|
||||
_i5.MealItem? mealItem,
|
||||
_i4.Meal? meal,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -321,7 +274,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4(
|
||||
returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
@@ -331,74 +284,76 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i6.MealItem>);
|
||||
) as _i8.Future<_i5.MealItem>);
|
||||
@override
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteMealItem(_i5.MealItem? mealItem) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(
|
||||
_i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5(
|
||||
returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i7.Ingredient>);
|
||||
) as _i8.Future<_i6.Ingredient>);
|
||||
@override
|
||||
_i9.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<List<dynamic>> searchIngredient(
|
||||
String? name, [
|
||||
_i8.Future<List<dynamic>> searchIngredient(
|
||||
String? name, {
|
||||
String? languageCode = r'en',
|
||||
]) =>
|
||||
bool? searchEnglish = false,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[
|
||||
name,
|
||||
languageCode,
|
||||
],
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i9.Future<List<dynamic>>);
|
||||
returnValue: _i8.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i8.Future<List<dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(
|
||||
_i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithCode,
|
||||
[code],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
) as _i9.Future<_i7.Ingredient?>);
|
||||
returnValue: _i8.Future<_i6.Ingredient?>.value(),
|
||||
) as _i8.Future<_i6.Ingredient?>);
|
||||
@override
|
||||
_i9.Future<void> logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> logIngredentToDiary(
|
||||
_i6.MealItem? mealItem,
|
||||
_i8.Future<void> logIngredentToDiary(
|
||||
_i5.MealItem? mealItem,
|
||||
int? planId, [
|
||||
DateTime? dateTime,
|
||||
]) =>
|
||||
@@ -411,11 +366,11 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deleteLog(
|
||||
_i8.Future<void> deleteLog(
|
||||
int? logId,
|
||||
int? planId,
|
||||
) =>
|
||||
@@ -427,129 +382,20 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetLogs(_i3.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value(),
|
||||
) as _i8.Future<void>);
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
@override
|
||||
Uri makeUrl(
|
||||
String? path, {
|
||||
int? id,
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
returnValue: _FakeUri_6(
|
||||
this,
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
),
|
||||
) as Uri);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i9.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i9.Future<List<dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> post(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> patch(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i3.Response> deleteRequest(
|
||||
String? url,
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i3.Response>);
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
void addListener(_i9.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
@@ -557,7 +403,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
void removeListener(_i9.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
|
||||
@@ -36,16 +36,14 @@ import 'nutritional_plan_screen_test.mocks.dart';
|
||||
void main() {
|
||||
Widget createNutritionalPlan({locale = 'en'}) {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final client = MockClient();
|
||||
final mockBaseProvider = MockWgerBaseProvider();
|
||||
final mockAuthProvider = MockAuthProvider();
|
||||
|
||||
final plan = getNutritionalPlan();
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(mockAuthProvider, [], client),
|
||||
create: (context) => NutritionPlansProvider(mockBaseProvider, []),
|
||||
),
|
||||
ChangeNotifierProvider<BodyWeightProvider>(
|
||||
create: (context) => BodyWeightProvider(mockBaseProvider),
|
||||
|
||||
@@ -25,6 +25,7 @@ import 'package:mockito/mockito.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/screens/nutritional_plans_screen.dart';
|
||||
@@ -32,9 +33,10 @@ import 'package:wger/widgets/nutrition/forms.dart';
|
||||
|
||||
import 'nutritional_plan_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([AuthProvider, http.Client])
|
||||
@GenerateMocks([AuthProvider, WgerBaseProvider, http.Client])
|
||||
void main() {
|
||||
final mockAuthProvider = MockAuthProvider();
|
||||
final mockBaseProvider = MockWgerBaseProvider();
|
||||
final client = MockClient();
|
||||
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
@@ -43,13 +45,17 @@ void main() {
|
||||
headers: anyNamed('headers'),
|
||||
)).thenAnswer((_) async => http.Response('', 200));
|
||||
|
||||
when(mockBaseProvider.deleteRequest(any, any)).thenAnswer(
|
||||
(_) async => http.Response('', 200),
|
||||
);
|
||||
|
||||
when(mockAuthProvider.token).thenReturn('1234');
|
||||
when(mockAuthProvider.serverUrl).thenReturn('http://localhost');
|
||||
when(mockAuthProvider.getAppNameHeader()).thenReturn('wger app');
|
||||
|
||||
return ChangeNotifierProvider<NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(
|
||||
mockAuthProvider,
|
||||
mockBaseProvider,
|
||||
[
|
||||
NutritionalPlan(
|
||||
id: 1,
|
||||
@@ -62,7 +68,6 @@ void main() {
|
||||
creationDate: DateTime(2021, 01, 10),
|
||||
),
|
||||
],
|
||||
client,
|
||||
),
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i5;
|
||||
import 'dart:convert' as _i7;
|
||||
import 'dart:typed_data' as _i8;
|
||||
import 'dart:convert' as _i8;
|
||||
import 'dart:typed_data' as _i9;
|
||||
import 'dart:ui' as _i6;
|
||||
|
||||
import 'package:http/http.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:package_info/package_info.dart' as _i4;
|
||||
import 'package:wger/providers/auth.dart' as _i3;
|
||||
import 'package:wger/providers/base_provider.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -34,8 +35,8 @@ class _FakeClient_0 extends _i1.SmartFake implements _i2.Client {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_1 extends _i1.SmartFake implements _i2.Response {
|
||||
_FakeResponse_1(
|
||||
class _FakeAuthProvider_1 extends _i1.SmartFake implements _i3.AuthProvider {
|
||||
_FakeAuthProvider_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -44,8 +45,28 @@ class _FakeResponse_1 extends _i1.SmartFake implements _i2.Response {
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeStreamedResponse_2 extends _i1.SmartFake implements _i2.StreamedResponse {
|
||||
_FakeStreamedResponse_2(
|
||||
class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
_FakeUri_2(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_3 extends _i1.SmartFake implements _i2.Response {
|
||||
_FakeResponse_3(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeStreamedResponse_4 extends _i1.SmartFake implements _i2.StreamedResponse {
|
||||
_FakeStreamedResponse_4(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
@@ -293,6 +314,157 @@ class MockAuthProvider extends _i1.Mock implements _i3.AuthProvider {
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [WgerBaseProvider].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockWgerBaseProvider extends _i1.Mock implements _i7.WgerBaseProvider {
|
||||
MockWgerBaseProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_1(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i3.AuthProvider);
|
||||
@override
|
||||
set auth(_i3.AuthProvider? _auth) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
_auth,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
_i2.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_0(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i2.Client);
|
||||
@override
|
||||
set client(_i2.Client? _client) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
_client,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
@override
|
||||
Uri makeUrl(
|
||||
String? path, {
|
||||
int? id,
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
returnValue: _FakeUri_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#makeUrl,
|
||||
[path],
|
||||
{
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query,
|
||||
},
|
||||
),
|
||||
),
|
||||
) as Uri);
|
||||
@override
|
||||
_i5.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i5.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i5.Future<List<dynamic>>);
|
||||
@override
|
||||
_i5.Future<Map<String, dynamic>> post(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i5.Future<Map<String, dynamic>> patch(
|
||||
Map<String, dynamic>? data,
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i5.Future<_i2.Response> deleteRequest(
|
||||
String? url,
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i5.Future<_i2.Response>);
|
||||
}
|
||||
|
||||
/// A class which mocks [Client].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
@@ -312,7 +484,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#head,
|
||||
@@ -332,7 +504,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#get,
|
||||
@@ -346,7 +518,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Uri? url, {
|
||||
Map<String, String>? headers,
|
||||
Object? body,
|
||||
_i7.Encoding? encoding,
|
||||
_i8.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -358,7 +530,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#post,
|
||||
@@ -376,7 +548,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Uri? url, {
|
||||
Map<String, String>? headers,
|
||||
Object? body,
|
||||
_i7.Encoding? encoding,
|
||||
_i8.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -388,7 +560,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#put,
|
||||
@@ -406,7 +578,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Uri? url, {
|
||||
Map<String, String>? headers,
|
||||
Object? body,
|
||||
_i7.Encoding? encoding,
|
||||
_i8.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -418,7 +590,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#patch,
|
||||
@@ -436,7 +608,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Uri? url, {
|
||||
Map<String, String>? headers,
|
||||
Object? body,
|
||||
_i7.Encoding? encoding,
|
||||
_i8.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -448,7 +620,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1(
|
||||
returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#delete,
|
||||
@@ -475,7 +647,7 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
returnValue: _i5.Future<String>.value(''),
|
||||
) as _i5.Future<String>);
|
||||
@override
|
||||
_i5.Future<_i8.Uint8List> readBytes(
|
||||
_i5.Future<_i9.Uint8List> readBytes(
|
||||
Uri? url, {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
@@ -485,15 +657,15 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i5.Future<_i8.Uint8List>.value(_i8.Uint8List(0)),
|
||||
) as _i5.Future<_i8.Uint8List>);
|
||||
returnValue: _i5.Future<_i9.Uint8List>.value(_i9.Uint8List(0)),
|
||||
) as _i5.Future<_i9.Uint8List>);
|
||||
@override
|
||||
_i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
returnValue: _i5.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_2(
|
||||
returnValue: _i5.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#send,
|
||||
|
||||
Reference in New Issue
Block a user