mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-06 15:54:31 +01:00
Recreate generated files and reformat the repo
Seems the default dart formatting rules changed recently, and this was causing huge diffs in branches
This commit is contained in:
1 parent
993e7a6bae
commit
93a11a16e4
105 files changed
+6716
-5595
No files matched your search
@@ -21,6 +21,7 @@ analyzer:
|
||||
|
||||
formatter:
|
||||
page_width: 100
|
||||
trailing_commas: preserve
|
||||
|
||||
linter:
|
||||
rules:
|
||||
|
||||
@@ -25,23 +25,27 @@ import '../test_data/routines.dart';
|
||||
Widget createDashboardScreen({String locale = 'en'}) {
|
||||
final mockWorkoutProvider = MockRoutinesProvider();
|
||||
when(mockWorkoutProvider.items).thenReturn([getTestRoutine(exercises: getScreenshotExercises())]);
|
||||
when(mockWorkoutProvider.currentRoutine)
|
||||
.thenReturn(getTestRoutine(exercises: getScreenshotExercises()));
|
||||
when(
|
||||
mockWorkoutProvider.currentRoutine,
|
||||
).thenReturn(getTestRoutine(exercises: getScreenshotExercises()));
|
||||
|
||||
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value([
|
||||
WorkoutSession(
|
||||
routineId: 1,
|
||||
date: DateTime.now().add(const Duration(days: -1)),
|
||||
timeStart: const TimeOfDay(hour: 17, minute: 34),
|
||||
timeEnd: const TimeOfDay(hour: 19, minute: 3),
|
||||
impression: 3,
|
||||
),
|
||||
]));
|
||||
when(mockWorkoutProvider.fetchSessionData()).thenAnswer(
|
||||
(a) => Future.value([
|
||||
WorkoutSession(
|
||||
routineId: 1,
|
||||
date: DateTime.now().add(const Duration(days: -1)),
|
||||
timeStart: const TimeOfDay(hour: 17, minute: 34),
|
||||
timeEnd: const TimeOfDay(hour: 19, minute: 3),
|
||||
impression: 3,
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
final mockNutritionProvider = weight.MockNutritionPlansProvider();
|
||||
|
||||
when(mockNutritionProvider.currentPlan)
|
||||
.thenAnswer((realInvocation) => getNutritionalPlanScreenshot());
|
||||
when(
|
||||
mockNutritionProvider.currentPlan,
|
||||
).thenAnswer((realInvocation) => getNutritionalPlanScreenshot());
|
||||
when(mockNutritionProvider.items).thenReturn([getNutritionalPlanScreenshot()]);
|
||||
|
||||
final mockWeightProvider = weight.MockBodyWeightProvider();
|
||||
|
||||
@@ -17,7 +17,7 @@ enum DeviceType {
|
||||
sevenInchScreenshots,
|
||||
tenInchScreenshots,
|
||||
tvScreenshots,
|
||||
wearScreenshots
|
||||
wearScreenshots,
|
||||
}
|
||||
|
||||
final destination = DeviceType.phoneScreenshots.name;
|
||||
@@ -42,7 +42,6 @@ Future<void> takeScreenshot(
|
||||
const languages = [
|
||||
// Note: it seems if too many languages are processed at once, some processes
|
||||
// disappear and no images are written. Doing this in smaller steps works fine
|
||||
|
||||
'ar',
|
||||
'ca',
|
||||
'cs-CZ',
|
||||
|
||||
@@ -85,20 +85,20 @@ class ExerciseDatabase extends _$ExerciseDatabase {
|
||||
/// will fetch everything as needed from the server
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onUpgrade: (m, from, to) async {
|
||||
// no-op, but needs to be defined
|
||||
return;
|
||||
},
|
||||
beforeOpen: (openingDetails) async {
|
||||
if (openingDetails.hadUpgrade) {
|
||||
final m = createMigrator();
|
||||
for (final table in allTables) {
|
||||
await m.deleteTable(table.actualTableName);
|
||||
await m.createTable(table);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
onUpgrade: (m, from, to) async {
|
||||
// no-op, but needs to be defined
|
||||
return;
|
||||
},
|
||||
beforeOpen: (openingDetails) async {
|
||||
if (openingDetails.hadUpgrade) {
|
||||
final m = createMigrator();
|
||||
for (final table in allTables) {
|
||||
await m.deleteTable(table.actualTableName);
|
||||
await m.createTable(table);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Future<void> deleteEverything() {
|
||||
return transaction(() async {
|
||||
|
||||
@@ -38,20 +38,20 @@ class IngredientDatabase extends _$IngredientDatabase {
|
||||
/// will fetch everything as needed from the server
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onUpgrade: (m, from, to) async {
|
||||
// no-op, but needs to be defined
|
||||
return;
|
||||
},
|
||||
beforeOpen: (openingDetails) async {
|
||||
if (openingDetails.hadUpgrade) {
|
||||
final m = createMigrator();
|
||||
for (final table in allTables) {
|
||||
await m.deleteTable(table.actualTableName);
|
||||
await m.createTable(table);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
onUpgrade: (m, from, to) async {
|
||||
// no-op, but needs to be defined
|
||||
return;
|
||||
},
|
||||
beforeOpen: (openingDetails) async {
|
||||
if (openingDetails.hadUpgrade) {
|
||||
final m = createMigrator();
|
||||
for (final table in allTables) {
|
||||
await m.deleteTable(table.actualTableName);
|
||||
await m.createTable(table);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Future<void> deleteEverything() {
|
||||
return transaction(() async {
|
||||
|
||||
@@ -25,11 +25,11 @@ extension MeasurementChartEntryListExtensions on List<MeasurementChartEntry> {
|
||||
return where((e) => e.date.isAfter(start) && (end == null || e.date.isBefore(end))).toList();
|
||||
}
|
||||
|
||||
// assures values on the start (and optionally end) dates exist, by interpolating if needed
|
||||
// this is used for when you are looking at a specific time frame (e.g. for a nutrition plan)
|
||||
// while gaps in the middle of a chart can be "visually interpolated", it's good to have a clearer
|
||||
// explicit interpolation for the start and end dates (if needed)
|
||||
// this also helps with computing delta's across the entire window
|
||||
// assures values on the start (and optionally end) dates exist, by interpolating if needed
|
||||
// this is used for when you are looking at a specific time frame (e.g. for a nutrition plan)
|
||||
// while gaps in the middle of a chart can be "visually interpolated", it's good to have a clearer
|
||||
// explicit interpolation for the start and end dates (if needed)
|
||||
// this also helps with computing delta's across the entire window
|
||||
List<MeasurementChartEntry> whereDateWithInterpolation(DateTime start, DateTime? end) {
|
||||
// Make sure our list is sorted by date
|
||||
sort((a, b) => a.date.compareTo(b.date));
|
||||
@@ -90,7 +90,10 @@ extension MeasurementChartEntryListExtensions on List<MeasurementChartEntry> {
|
||||
|
||||
// caller needs to make sure that before.date < date < after.date
|
||||
MeasurementChartEntry interpolateBetween(
|
||||
MeasurementChartEntry before, MeasurementChartEntry after, DateTime date) {
|
||||
MeasurementChartEntry before,
|
||||
MeasurementChartEntry after,
|
||||
DateTime date,
|
||||
) {
|
||||
final totalDuration = after.date.difference(before.date).inMilliseconds;
|
||||
final startDuration = date.difference(before.date).inMilliseconds;
|
||||
|
||||
|
||||
+2
-2
@@ -146,8 +146,8 @@ class MainApp extends StatelessWidget {
|
||||
future: auth.tryAutoLogin(),
|
||||
builder: (ctx, authResultSnapshot) =>
|
||||
authResultSnapshot.connectionState == ConnectionState.waiting
|
||||
? const SplashScreen()
|
||||
: const AuthScreen(),
|
||||
? const SplashScreen()
|
||||
: const AuthScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ class WeightEntry {
|
||||
}
|
||||
|
||||
WeightEntry copyWith({int? id, int? weight, DateTime? date}) => WeightEntry(
|
||||
id: id,
|
||||
weight: weight ?? this.weight,
|
||||
date: date ?? this.date,
|
||||
);
|
||||
id: id,
|
||||
weight: weight ?? this.weight,
|
||||
date: date ?? this.date,
|
||||
);
|
||||
|
||||
// Boilerplate
|
||||
factory WeightEntry.fromJson(Map<String, dynamic> json) => _$WeightEntryFromJson(json);
|
||||
|
||||
@@ -145,10 +145,10 @@ class Exercise extends Equatable {
|
||||
}
|
||||
|
||||
Exercise.fromApiDataString(String baseData, List<Language> languages)
|
||||
: this.fromApiData(ExerciseApiData.fromString(baseData), languages);
|
||||
: this.fromApiData(ExerciseApiData.fromString(baseData), languages);
|
||||
|
||||
Exercise.fromApiDataJson(Map<String, dynamic> baseData, List<Language> languages)
|
||||
: this.fromApiData(ExerciseApiData.fromJson(baseData), languages);
|
||||
: this.fromApiData(ExerciseApiData.fromJson(baseData), languages);
|
||||
|
||||
Exercise.fromApiData(ExerciseApiData exerciseData, List<Language> languages) {
|
||||
id = exerciseData.id;
|
||||
@@ -228,13 +228,13 @@ class Exercise extends Equatable {
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
uuid,
|
||||
created,
|
||||
lastUpdate,
|
||||
category,
|
||||
equipment,
|
||||
muscles,
|
||||
musclesSecondary,
|
||||
];
|
||||
id,
|
||||
uuid,
|
||||
created,
|
||||
lastUpdate,
|
||||
category,
|
||||
equipment,
|
||||
muscles,
|
||||
musclesSecondary,
|
||||
];
|
||||
}
|
||||
@@ -92,12 +92,12 @@ class Translation extends Equatable {
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
exerciseId,
|
||||
uuid,
|
||||
languageId,
|
||||
created,
|
||||
name,
|
||||
description,
|
||||
];
|
||||
id,
|
||||
exerciseId,
|
||||
uuid,
|
||||
languageId,
|
||||
created,
|
||||
name,
|
||||
description,
|
||||
];
|
||||
}
|
||||
@@ -20,11 +20,10 @@ MeasurementEntry _$MeasurementEntryFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MeasurementEntryToJson(MeasurementEntry instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'category': instance.category,
|
||||
'date': dateToYYYYMMDD(instance.date),
|
||||
'value': instance.value,
|
||||
'notes': instance.notes,
|
||||
};
|
||||
Map<String, dynamic> _$MeasurementEntryToJson(MeasurementEntry instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'category': instance.category,
|
||||
'date': dateToYYYYMMDD(instance.date),
|
||||
'value': instance.value,
|
||||
'notes': instance.notes,
|
||||
};
|
||||
@@ -84,8 +84,9 @@ class Log {
|
||||
NutritionalValues get nutritionalValues {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
|
||||
final weight =
|
||||
weightUnitObj == null ? amount : amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
final weight = weightUnitObj == null
|
||||
? amount
|
||||
: amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
|
||||
return ingredient.nutritionalValues / (100 / weight);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ class NutritionalGoals {
|
||||
(energy! - protein! * ENERGY_PROTEIN - fat! * ENERGY_FAT) / ENERGY_CARBOHYDRATES;
|
||||
assert(carbohydrates! > 0);
|
||||
} else if (fat == null && protein != null && carbohydrates != null) {
|
||||
fat = (energy! - protein! * ENERGY_PROTEIN - carbohydrates! * ENERGY_CARBOHYDRATES) /
|
||||
fat =
|
||||
(energy! - protein! * ENERGY_PROTEIN - carbohydrates! * ENERGY_CARBOHYDRATES) /
|
||||
ENERGY_FAT;
|
||||
assert(fat! > 0);
|
||||
}
|
||||
@@ -141,15 +142,15 @@ class NutritionalGoals {
|
||||
@override
|
||||
//ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hash(
|
||||
energy,
|
||||
protein,
|
||||
carbohydrates,
|
||||
carbohydratesSugar,
|
||||
fat,
|
||||
fatSaturated,
|
||||
fiber,
|
||||
sodium,
|
||||
);
|
||||
energy,
|
||||
protein,
|
||||
carbohydrates,
|
||||
carbohydratesSugar,
|
||||
fat,
|
||||
fatSaturated,
|
||||
fiber,
|
||||
sodium,
|
||||
);
|
||||
|
||||
@override
|
||||
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
|
||||
@@ -132,13 +132,13 @@ class NutritionalValues {
|
||||
@override
|
||||
//ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hash(
|
||||
energy,
|
||||
protein,
|
||||
carbohydrates,
|
||||
carbohydratesSugar,
|
||||
fat,
|
||||
fatSaturated,
|
||||
fiber,
|
||||
sodium,
|
||||
);
|
||||
energy,
|
||||
protein,
|
||||
carbohydrates,
|
||||
carbohydratesSugar,
|
||||
fat,
|
||||
fatSaturated,
|
||||
fiber,
|
||||
sodium,
|
||||
);
|
||||
}
|
||||
@@ -14,5 +14,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
|
||||
<String, dynamic>{'id': instance.id, 'name': instance.name};
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
@@ -32,13 +32,12 @@ BaseConfig _$BaseConfigFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$BaseConfigToJson(BaseConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'slot_entry': instance.slotEntryId,
|
||||
'iteration': instance.iteration,
|
||||
'value': instance.value,
|
||||
'operation': instance.operation,
|
||||
'step': instance.step,
|
||||
'repeat': instance.repeat,
|
||||
'requirements': instance.requirements,
|
||||
};
|
||||
Map<String, dynamic> _$BaseConfigToJson(BaseConfig instance) => <String, dynamic>{
|
||||
'slot_entry': instance.slotEntryId,
|
||||
'iteration': instance.iteration,
|
||||
'value': instance.value,
|
||||
'operation': instance.operation,
|
||||
'step': instance.step,
|
||||
'repeat': instance.repeat,
|
||||
'requirements': instance.requirements,
|
||||
};
|
||||
@@ -142,8 +142,13 @@ class Log {
|
||||
|
||||
/// Returns the text representation for a single setting, used in the gym mode
|
||||
String get singleLogRepTextNoNl {
|
||||
return repText(repetitions, repetitionsUnitObj, weight, weightUnitObj, rir)
|
||||
.replaceAll('\n', '');
|
||||
return repText(
|
||||
repetitions,
|
||||
repetitionsUnitObj,
|
||||
weight,
|
||||
weightUnitObj,
|
||||
rir,
|
||||
).replaceAll('\n', '');
|
||||
}
|
||||
|
||||
/// Override the equals operator
|
||||
|
||||
@@ -14,5 +14,7 @@ RepetitionUnit _$RepetitionUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) =>
|
||||
<String, dynamic>{'id': instance.id, 'name': instance.name};
|
||||
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
@@ -14,5 +14,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
|
||||
<String, dynamic>{'id': instance.id, 'name': instance.name};
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
@@ -251,7 +251,7 @@ class AuthProvider with ChangeNotifier {
|
||||
headers: {
|
||||
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
|
||||
HttpHeaders.userAgentHeader: getAppNameHeader(),
|
||||
HttpHeaders.authorizationHeader: 'Token $token'
|
||||
HttpHeaders.authorizationHeader: 'Token $token',
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
@@ -294,7 +294,8 @@ class AuthProvider with ChangeNotifier {
|
||||
String getAppNameHeader() {
|
||||
String out = '';
|
||||
if (applicationVersion != null) {
|
||||
out = '/${applicationVersion!.version} '
|
||||
out =
|
||||
'/${applicationVersion!.version} '
|
||||
'(${applicationVersion!.packageName}; '
|
||||
'build: ${applicationVersion!.buildNumber})'
|
||||
' - https://github.com/wger-project';
|
||||
|
||||
@@ -68,10 +68,12 @@ class BodyWeightProvider with ChangeNotifier {
|
||||
_logger.info('Fetching all body weight entries');
|
||||
|
||||
// Process the response
|
||||
final data = await baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
BODY_WEIGHT_URL,
|
||||
query: {'ordering': '-date', 'limit': API_MAX_PAGE_SIZE},
|
||||
));
|
||||
final data = await baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(
|
||||
BODY_WEIGHT_URL,
|
||||
query: {'ordering': '-date', 'limit': API_MAX_PAGE_SIZE},
|
||||
),
|
||||
);
|
||||
_entries = [];
|
||||
for (final entry in data) {
|
||||
_entries.add(WeightEntry.fromJson(entry));
|
||||
|
||||
@@ -8,8 +8,8 @@ const DEFAULT_DURATION = Duration(hours: 5);
|
||||
|
||||
final StateNotifierProvider<GymStateNotifier, GymState> gymStateProvider =
|
||||
StateNotifierProvider<GymStateNotifier, GymState>((ref) {
|
||||
return GymStateNotifier();
|
||||
});
|
||||
return GymStateNotifier();
|
||||
});
|
||||
|
||||
class GymState {
|
||||
final Map<Exercise, int> exercisePages;
|
||||
@@ -19,13 +19,14 @@ class GymState {
|
||||
late TimeOfDay startTime;
|
||||
late DateTime validUntil;
|
||||
|
||||
GymState(
|
||||
{this.exercisePages = const {},
|
||||
this.showExercisePages = true,
|
||||
this.currentPage = 0,
|
||||
this.dayId,
|
||||
DateTime? validUntil,
|
||||
TimeOfDay? startTime}) {
|
||||
GymState({
|
||||
this.exercisePages = const {},
|
||||
this.showExercisePages = true,
|
||||
this.currentPage = 0,
|
||||
this.dayId,
|
||||
DateTime? validUntil,
|
||||
TimeOfDay? startTime,
|
||||
}) {
|
||||
this.validUntil = validUntil ?? DateTime.now().add(DEFAULT_DURATION);
|
||||
this.startTime = startTime ?? TimeOfDay.fromDateTime(clock.now());
|
||||
}
|
||||
|
||||
@@ -133,8 +133,9 @@ class MeasurementProvider with ChangeNotifier {
|
||||
tempNewCategory.toJson(),
|
||||
baseProvider.makeUrl(_categoryUrl, id: id),
|
||||
);
|
||||
final MeasurementCategory newCategory =
|
||||
MeasurementCategory.fromJson(response).copyWith(entries: oldCategory.entries);
|
||||
final MeasurementCategory newCategory = MeasurementCategory.fromJson(
|
||||
response,
|
||||
).copyWith(entries: oldCategory.entries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, newCategory);
|
||||
notifyListeners();
|
||||
@@ -192,8 +193,10 @@ class MeasurementProvider with ChangeNotifier {
|
||||
date: newDate,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> response =
|
||||
await baseProvider.patch(tempNewEntry.toJson(), baseProvider.makeUrl(_entryUrl, id: id));
|
||||
final Map<String, dynamic> response = await baseProvider.patch(
|
||||
tempNewEntry.toJson(),
|
||||
baseProvider.makeUrl(_entryUrl, id: id),
|
||||
);
|
||||
|
||||
final MeasurementEntry newEntry = MeasurementEntry.fromJson(response);
|
||||
category.entries.removeAt(entryIndex);
|
||||
|
||||
@@ -18,8 +18,8 @@ const PREFS_KEY_PLATES = 'selectedPlates';
|
||||
|
||||
final plateCalculatorProvider =
|
||||
StateNotifierProvider<PlateCalculatorNotifier, PlateCalculatorState>((ref) {
|
||||
return PlateCalculatorNotifier();
|
||||
});
|
||||
return PlateCalculatorNotifier();
|
||||
});
|
||||
|
||||
class PlateCalculatorState {
|
||||
final _logger = Logger('PlateWeightsState');
|
||||
@@ -65,17 +65,18 @@ class PlateCalculatorState {
|
||||
this.isMetric = true,
|
||||
this.totalWeight = 0,
|
||||
List<num>? selectedPlates,
|
||||
}) : barWeight = barWeight ?? (isMetric ? DEFAULT_BAR_WEIGHT_KG : DEFAULT_BAR_WEIGHT_LB),
|
||||
selectedPlates =
|
||||
selectedPlates ?? (isMetric ? [...DEFAULT_KG_PLATES] : [...DEFAULT_LB_PLATES]);
|
||||
}) : barWeight = barWeight ?? (isMetric ? DEFAULT_BAR_WEIGHT_KG : DEFAULT_BAR_WEIGHT_LB),
|
||||
selectedPlates =
|
||||
selectedPlates ?? (isMetric ? [...DEFAULT_KG_PLATES] : [...DEFAULT_LB_PLATES]);
|
||||
|
||||
PlateCalculatorState.fromJson(Map<String, dynamic> plateData)
|
||||
: useColors = plateData['useColors'] ?? true,
|
||||
isMetric = plateData['isMetric'] ?? true,
|
||||
selectedPlates = plateData['selectedPlates']?.cast<num>() ?? [...DEFAULT_KG_PLATES],
|
||||
barWeight = plateData['barWeight'] ??
|
||||
((plateData['isMetric'] ?? true) ? DEFAULT_BAR_WEIGHT_KG : DEFAULT_BAR_WEIGHT_LB),
|
||||
totalWeight = 0;
|
||||
: useColors = plateData['useColors'] ?? true,
|
||||
isMetric = plateData['isMetric'] ?? true,
|
||||
selectedPlates = plateData['selectedPlates']?.cast<num>() ?? [...DEFAULT_KG_PLATES],
|
||||
barWeight =
|
||||
plateData['barWeight'] ??
|
||||
((plateData['isMetric'] ?? true) ? DEFAULT_BAR_WEIGHT_KG : DEFAULT_BAR_WEIGHT_LB),
|
||||
totalWeight = 0;
|
||||
|
||||
PlateCalculatorState copyWith({
|
||||
bool? useColors,
|
||||
|
||||
@@ -279,8 +279,9 @@ class RoutinesProvider with ChangeNotifier {
|
||||
final dayDataEntriesGym = dayDataGym.map((entry) => DayData.fromJson(entry)).toList();
|
||||
await setExercisesAndUnits(dayDataEntriesGym, exercises: exercises);
|
||||
|
||||
final sessionDataEntries =
|
||||
sessionData.map((entry) => WorkoutSessionApi.fromJson(entry)).toList();
|
||||
final sessionDataEntries = sessionData
|
||||
.map((entry) => WorkoutSessionApi.fromJson(entry))
|
||||
.toList();
|
||||
|
||||
for (final day in routine.days) {
|
||||
for (final slot in day.slots) {
|
||||
@@ -322,8 +323,9 @@ class RoutinesProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
if (!exercises.containsKey(log.exerciseId)) {
|
||||
exercises[log.exerciseId] =
|
||||
(await _exerciseProvider.fetchAndSetExercise(log.exerciseId))!;
|
||||
exercises[log.exerciseId] = (await _exerciseProvider.fetchAndSetExercise(
|
||||
log.exerciseId,
|
||||
))!;
|
||||
}
|
||||
|
||||
log.exerciseBase = exercises[log.exerciseId]!;
|
||||
@@ -378,8 +380,9 @@ class RoutinesProvider with ChangeNotifier {
|
||||
|
||||
/// Fetch and set weight units for workout (kg, lb, plate, etc.)
|
||||
Future<void> fetchAndSetRepetitionUnits() async {
|
||||
final response =
|
||||
await baseProvider.fetchPaginated(baseProvider.makeUrl(_repetitionUnitUrlPath));
|
||||
final response = await baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(_repetitionUnitUrlPath),
|
||||
);
|
||||
for (final unit in response) {
|
||||
_repetitionUnits.add(RepetitionUnit.fromJson(unit));
|
||||
}
|
||||
|
||||
@@ -101,10 +101,12 @@ class UserProvider with ChangeNotifier {
|
||||
|
||||
/// Verify the user's email
|
||||
Future<void> verifyEmail() async {
|
||||
await baseProvider.fetch(baseProvider.makeUrl(
|
||||
PROFILE_URL,
|
||||
objectMethod: VERIFY_EMAIL,
|
||||
));
|
||||
await baseProvider.fetch(
|
||||
baseProvider.makeUrl(
|
||||
PROFILE_URL,
|
||||
objectMethod: VERIFY_EMAIL,
|
||||
),
|
||||
);
|
||||
//log(verificationData.toString());
|
||||
}
|
||||
}
|
||||
@@ -182,11 +182,11 @@ class _AuthCardState extends State<AuthCard> {
|
||||
late LoginActions res;
|
||||
if (_authMode == AuthMode.Login) {
|
||||
res = await context.read<AuthProvider>().login(
|
||||
_authData['username']!,
|
||||
_authData['password']!,
|
||||
_authData['serverUrl']!,
|
||||
_authData['apiToken'],
|
||||
);
|
||||
_authData['username']!,
|
||||
_authData['password']!,
|
||||
_authData['serverUrl']!,
|
||||
_authData['apiToken'],
|
||||
);
|
||||
|
||||
// Register new user
|
||||
} else {
|
||||
@@ -287,8 +287,9 @@ class _AuthCardState extends State<AuthCard> {
|
||||
labelText: i18n.confirmPassword,
|
||||
prefixIcon: const Icon(Icons.password),
|
||||
suffixIcon: IconButton(
|
||||
icon:
|
||||
Icon(confirmIsObscure ? Icons.visibility_off : Icons.visibility),
|
||||
icon: Icon(
|
||||
confirmIsObscure ? Icons.visibility_off : Icons.visibility,
|
||||
),
|
||||
onPressed: () {
|
||||
updateState(() {
|
||||
confirmIsObscure = !confirmIsObscure;
|
||||
@@ -374,8 +375,9 @@ class _AuthCardState extends State<AuthCard> {
|
||||
Builder(
|
||||
key: const Key('toggleActionButton'),
|
||||
builder: (context) {
|
||||
final String text =
|
||||
_authMode != AuthMode.Register ? i18n.registerInstead : i18n.loginInstead;
|
||||
final String text = _authMode != AuthMode.Register
|
||||
? i18n.registerInstead
|
||||
: i18n.loginInstead;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _switchAuthMode(),
|
||||
|
||||
@@ -40,8 +40,9 @@ class GymModeScreen extends StatelessWidget {
|
||||
|
||||
final routinesProvider = context.read<RoutinesProvider>();
|
||||
final routine = routinesProvider.findById(args.routineId);
|
||||
final dayDataDisplay =
|
||||
routine.dayData.firstWhere((e) => e.iteration == args.iteration && e.day?.id == args.dayId);
|
||||
final dayDataDisplay = routine.dayData.firstWhere(
|
||||
(e) => e.iteration == args.iteration && e.day?.id == args.dayId,
|
||||
);
|
||||
final dayDataGym = routine.dayDataGym
|
||||
.where((e) => e.iteration == args.iteration && e.day?.id == args.dayId)
|
||||
.first;
|
||||
|
||||
@@ -126,8 +126,10 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
);
|
||||
break;
|
||||
case NutritionalPlanOptions.delete:
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.deletePlan(nutritionalPlan.id!);
|
||||
Provider.of<NutritionPlansProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).deletePlan(nutritionalPlan.id!);
|
||||
Navigator.of(context).pop();
|
||||
break;
|
||||
}
|
||||
@@ -165,22 +167,22 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
future: _loadFullPlan(context, nutritionalPlan.id!),
|
||||
builder: (context, AsyncSnapshot<NutritionalPlan> snapshot) =>
|
||||
snapshot.connectionState == ConnectionState.waiting
|
||||
? SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
const SizedBox(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
],
|
||||
? SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
const SizedBox(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Consumer<NutritionPlansProvider>(
|
||||
builder: (context, value, child) =>
|
||||
NutritionalPlanDetailWidget(nutritionalPlan),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Consumer<NutritionPlansProvider>(
|
||||
builder: (context, value, child) =>
|
||||
NutritionalPlanDetailWidget(nutritionalPlan),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -33,8 +33,9 @@ class _AddExerciseMultiselectButtonState<T> extends State<AddExerciseMultiselect
|
||||
child: MultiSelectDialogField(
|
||||
initialValue: widget.initialItems,
|
||||
onSaved: widget.onSaved,
|
||||
items:
|
||||
widget.items.map((item) => MultiSelectItem<T>(item, widget.displayName(item))).toList(),
|
||||
items: widget.items
|
||||
.map((item) => MultiSelectItem<T>(item, widget.displayName(item)))
|
||||
.toList(),
|
||||
onConfirm: (value) {
|
||||
setState(() {
|
||||
_selectedItems = value.cast<T>();
|
||||
|
||||
@@ -195,7 +195,8 @@ class AboutPage extends StatelessWidget {
|
||||
showLicensePage(
|
||||
context: context,
|
||||
applicationName: 'wger',
|
||||
applicationVersion: 'App: ${authProvider.applicationVersion?.version ?? 'N/A'} '
|
||||
applicationVersion:
|
||||
'App: ${authProvider.applicationVersion?.version ?? 'N/A'} '
|
||||
'Server: ${authProvider.serverVersion ?? 'N/A'}',
|
||||
applicationLegalese: '\u{a9} ${today.year} wger contributors',
|
||||
applicationIcon: Padding(
|
||||
|
||||
@@ -42,8 +42,9 @@ class _DashboardMeasurementWidgetState extends State<DashboardMeasurementWidget>
|
||||
Widget build(BuildContext context) {
|
||||
final provider = Provider.of<MeasurementProvider>(context, listen: false);
|
||||
|
||||
final items =
|
||||
provider.categories.map<Widget>((item) => CategoriesCard(item, elevation: 0)).toList();
|
||||
final items = provider.categories
|
||||
.map<Widget>((item) => CategoriesCard(item, elevation: 0))
|
||||
.toList();
|
||||
if (items.isNotEmpty) {
|
||||
items.add(
|
||||
NothingFound(
|
||||
@@ -115,10 +116,10 @@ class _DashboardMeasurementWidgetState extends State<DashboardMeasurementWidget>
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color:
|
||||
Theme.of(context).textTheme.headlineSmall!.color!.withOpacity(
|
||||
_current == entry.key ? 0.9 : 0.4,
|
||||
),
|
||||
color: Theme.of(context).textTheme.headlineSmall!.color!
|
||||
.withOpacity(
|
||||
_current == entry.key ? 0.9 : 0.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -60,8 +60,9 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
),
|
||||
subtitle: Text(
|
||||
_hasContent
|
||||
? DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(_plan!.creationDate)
|
||||
? DateFormat.yMd(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).format(_plan!.creationDate)
|
||||
: '',
|
||||
),
|
||||
leading: Icon(
|
||||
|
||||
@@ -175,14 +175,19 @@ class DetailContentWidget extends StatelessWidget {
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(s.exercise
|
||||
.getTranslation(
|
||||
Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
Text(
|
||||
s.exercise
|
||||
.getTranslation(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
)
|
||||
.name,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child:
|
||||
MutedText(s.textRepr, overflow: TextOverflow.ellipsis),
|
||||
child: MutedText(
|
||||
s.textRepr,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -94,9 +94,12 @@ class DashboardWeightWidget extends StatelessWidget {
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).newEntry,
|
||||
WeightForm(weightProvider
|
||||
.getNewestEntry()
|
||||
?.copyWith(id: null, date: DateTime.now())),
|
||||
WeightForm(
|
||||
weightProvider.getNewestEntry()?.copyWith(
|
||||
id: null,
|
||||
date: DateTime.now(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -85,30 +85,32 @@ class _ExerciseAutocompleterState extends State<ExerciseAutocompleter> {
|
||||
return null;
|
||||
}
|
||||
return context.read<ExercisesProvider>().searchExercise(
|
||||
pattern,
|
||||
languageCode: Localizations.localeOf(context).languageCode,
|
||||
searchEnglish: _searchEnglish,
|
||||
);
|
||||
pattern,
|
||||
languageCode: Localizations.localeOf(context).languageCode,
|
||||
searchEnglish: _searchEnglish,
|
||||
);
|
||||
},
|
||||
itemBuilder: (
|
||||
BuildContext context,
|
||||
Exercise exerciseSuggestion,
|
||||
) =>
|
||||
ListTile(
|
||||
key: Key('exercise-${exerciseSuggestion.id}'),
|
||||
leading: SizedBox(
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(
|
||||
image: exerciseSuggestion.getMainImage,
|
||||
itemBuilder:
|
||||
(
|
||||
BuildContext context,
|
||||
Exercise exerciseSuggestion,
|
||||
) => ListTile(
|
||||
key: Key('exercise-${exerciseSuggestion.id}'),
|
||||
leading: SizedBox(
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(
|
||||
image: exerciseSuggestion.getMainImage,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
exerciseSuggestion
|
||||
.getTranslation(Localizations.localeOf(context).languageCode)
|
||||
.name,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${exerciseSuggestion.category!.name} / ${exerciseSuggestion.equipment.map((e) => e.name).join(', ')}',
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
exerciseSuggestion.getTranslation(Localizations.localeOf(context).languageCode).name,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${exerciseSuggestion.category!.name} / ${exerciseSuggestion.equipment.map((e) => e.name).join(', ')}',
|
||||
),
|
||||
),
|
||||
emptyBuilder: (context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -149,7 +151,7 @@ class _ExerciseAutocompleterState extends State<ExerciseAutocompleter> {
|
||||
});
|
||||
},
|
||||
dense: true,
|
||||
)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,21 +81,23 @@ class ExerciseDetail extends StatelessWidget {
|
||||
}
|
||||
|
||||
List<Widget> getVariations(BuildContext context) {
|
||||
final variations =
|
||||
Provider.of<ExercisesProvider>(context, listen: false).findExercisesByVariationId(
|
||||
_exercise.variationId,
|
||||
exerciseIdToExclude: _exercise.id,
|
||||
);
|
||||
final variations = Provider.of<ExercisesProvider>(context, listen: false)
|
||||
.findExercisesByVariationId(
|
||||
_exercise.variationId,
|
||||
exerciseIdToExclude: _exercise.id,
|
||||
);
|
||||
|
||||
final List<Widget> out = [];
|
||||
if (_exercise.variationId == null) {
|
||||
return out;
|
||||
}
|
||||
|
||||
out.add(Text(
|
||||
AppLocalizations.of(context).variations,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
));
|
||||
out.add(
|
||||
Text(
|
||||
AppLocalizations.of(context).variations,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
);
|
||||
for (final element in variations) {
|
||||
out.add(ExerciseListTile(exercise: element));
|
||||
}
|
||||
@@ -110,10 +112,12 @@ class ExerciseDetail extends StatelessWidget {
|
||||
List<Widget> getNotes(BuildContext context) {
|
||||
final List<Widget> out = [];
|
||||
if (_translation.notes.isNotEmpty) {
|
||||
out.add(Text(
|
||||
AppLocalizations.of(context).notes,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
));
|
||||
out.add(
|
||||
Text(
|
||||
AppLocalizations.of(context).notes,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
);
|
||||
for (final e in _translation.notes) {
|
||||
out.add(Text(e.comment));
|
||||
}
|
||||
@@ -125,36 +129,40 @@ class ExerciseDetail extends StatelessWidget {
|
||||
|
||||
List<Widget> getMuscles(BuildContext context) {
|
||||
final List<Widget> out = [];
|
||||
out.add(Text(
|
||||
AppLocalizations.of(context).muscles,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
));
|
||||
out.add(Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: PADDING),
|
||||
child: MuscleWidget(
|
||||
muscles: _exercise.muscles,
|
||||
musclesSecondary: _exercise.musclesSecondary,
|
||||
isFront: true,
|
||||
out.add(
|
||||
Text(
|
||||
AppLocalizations.of(context).muscles,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
);
|
||||
out.add(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: PADDING),
|
||||
child: MuscleWidget(
|
||||
muscles: _exercise.muscles,
|
||||
musclesSecondary: _exercise.musclesSecondary,
|
||||
isFront: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: PADDING),
|
||||
child: MuscleWidget(
|
||||
muscles: _exercise.muscles,
|
||||
musclesSecondary: _exercise.musclesSecondary,
|
||||
isFront: false,
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: PADDING),
|
||||
child: MuscleWidget(
|
||||
muscles: _exercise.muscles,
|
||||
musclesSecondary: _exercise.musclesSecondary,
|
||||
isFront: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
out.add(
|
||||
Column(
|
||||
@@ -183,10 +191,12 @@ class ExerciseDetail extends StatelessWidget {
|
||||
|
||||
List<Widget> getDescription(BuildContext context) {
|
||||
final List<Widget> out = [];
|
||||
out.add(Text(
|
||||
AppLocalizations.of(context).description,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
));
|
||||
out.add(
|
||||
Text(
|
||||
AppLocalizations.of(context).description,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
);
|
||||
out.add(Html(data: _translation.description));
|
||||
|
||||
return out;
|
||||
@@ -195,9 +205,11 @@ class ExerciseDetail extends StatelessWidget {
|
||||
List<Widget> getImages() {
|
||||
final List<Widget> out = [];
|
||||
if (_exercise.images.isNotEmpty) {
|
||||
out.add(CarouselImages(
|
||||
images: _exercise.images,
|
||||
));
|
||||
out.add(
|
||||
CarouselImages(
|
||||
images: _exercise.images,
|
||||
),
|
||||
);
|
||||
|
||||
// out.add(ExerciseImageWidget(
|
||||
// image: _exercise.getMainImage,
|
||||
@@ -225,14 +237,16 @@ class ExerciseDetail extends StatelessWidget {
|
||||
);
|
||||
if (_exercise.equipment.isNotEmpty) {
|
||||
_exercise.equipment
|
||||
.map((e) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Chip(
|
||||
label: Text(getTranslation(e.name, context)),
|
||||
padding: EdgeInsets.zero,
|
||||
backgroundColor: theme.splashColor,
|
||||
),
|
||||
))
|
||||
.map(
|
||||
(e) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Chip(
|
||||
label: Text(getTranslation(e.name, context)),
|
||||
padding: EdgeInsets.zero,
|
||||
backgroundColor: theme.splashColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
.forEach((element) => out.add(element));
|
||||
}
|
||||
out.add(const SizedBox(height: PADDING));
|
||||
@@ -255,11 +269,13 @@ class ExerciseDetail extends StatelessWidget {
|
||||
List<Widget> getAliases(BuildContext context) {
|
||||
final List<Widget> out = [];
|
||||
if (_translation.aliases.isNotEmpty) {
|
||||
out.add(MutedText(
|
||||
AppLocalizations.of(context).alsoKnownAs(
|
||||
_translation.aliases.map((e) => e.alias).toList().join(', '),
|
||||
out.add(
|
||||
MutedText(
|
||||
AppLocalizations.of(context).alsoKnownAs(
|
||||
_translation.aliases.map((e) => e.alias).toList().join(', '),
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
out.add(const SizedBox(height: PADDING));
|
||||
}
|
||||
|
||||
@@ -355,9 +371,13 @@ class MuscleWidget extends StatelessWidget {
|
||||
children: [
|
||||
SvgPicture.asset('assets/images/muscles/$background.svg'),
|
||||
...muscles.map((m) => SvgPicture.asset('assets/images/muscles/main/muscle-${m.id}.svg')),
|
||||
...musclesSecondary.where((m) => !muscles.contains(m)).map((m) => SvgPicture.asset(
|
||||
'assets/images/muscles/secondary/muscle-${m.id}.svg',
|
||||
)),
|
||||
...musclesSecondary
|
||||
.where((m) => !muscles.contains(m))
|
||||
.map(
|
||||
(m) => SvgPicture.asset(
|
||||
'assets/images/muscles/secondary/muscle-${m.id}.svg',
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,22 +68,22 @@ class _ExerciseVideoWidgetState extends State<ExerciseVideoWidget> {
|
||||
return hasError
|
||||
? const GeneralErrorsWidget(
|
||||
[
|
||||
'An error happened while loading the video. If you can, please check the application logs.'
|
||||
'An error happened while loading the video. If you can, please check the application logs.',
|
||||
],
|
||||
)
|
||||
: _controller.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
VideoPlayer(_controller),
|
||||
_ControlsOverlay(controller: _controller),
|
||||
VideoProgressIndicator(_controller, allowScrubbing: true),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container();
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
VideoPlayer(_controller),
|
||||
_ControlsOverlay(controller: _controller),
|
||||
VideoProgressIndicator(_controller, allowScrubbing: true),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,12 +197,16 @@ class _ImageFormState extends State<ImageForm> {
|
||||
_form.currentState!.save();
|
||||
|
||||
if (widget._image.id == null) {
|
||||
Provider.of<GalleryProvider>(context, listen: false)
|
||||
.addImage(widget._image, _file!);
|
||||
Provider.of<GalleryProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).addImage(widget._image, _file!);
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
Provider.of<GalleryProvider>(context, listen: false)
|
||||
.editImage(widget._image, _file);
|
||||
Provider.of<GalleryProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).editImage(widget._image, _file);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -41,8 +41,10 @@ class MeasurementOverallChangeWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
// ignore: prefer_interpolation_to_compose_strings
|
||||
return Text(AppLocalizations.of(context).overallChangeWeight +
|
||||
' $prefix${delta.abs().toStringAsFixed(1)} $_unit');
|
||||
return Text(
|
||||
AppLocalizations.of(context).overallChangeWeight +
|
||||
' $prefix${delta.abs().toStringAsFixed(1)} $_unit',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,14 +80,16 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
getTooltipColor: (touchedSpot) => Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
final numberFormat =
|
||||
NumberFormat.decimalPattern(Localizations.localeOf(context).toString());
|
||||
final numberFormat = NumberFormat.decimalPattern(
|
||||
Localizations.localeOf(context).toString(),
|
||||
);
|
||||
|
||||
return touchedSpots.map((touchedSpot) {
|
||||
final msSinceEpoch = touchedSpot.x.toInt();
|
||||
final DateTime date = DateTime.fromMillisecondsSinceEpoch(touchedSpot.x.toInt());
|
||||
final dateStr =
|
||||
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date);
|
||||
final dateStr = DateFormat.Md(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).format(date);
|
||||
|
||||
// Check if this is an interpolated point (milliseconds ending with 123)
|
||||
final bool isInterpolated = msSinceEpoch % 1000 == INTERPOLATION_MARKER;
|
||||
@@ -180,10 +184,12 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: widget._entries
|
||||
.map((e) => FlSpot(
|
||||
e.date.millisecondsSinceEpoch.toDouble(),
|
||||
e.value.toDouble(),
|
||||
))
|
||||
.map(
|
||||
(e) => FlSpot(
|
||||
e.date.millisecondsSinceEpoch.toDouble(),
|
||||
e.value.toDouble(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isCurved: false,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
@@ -194,10 +200,12 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
|
||||
if (widget.avgs != null)
|
||||
LineChartBarData(
|
||||
spots: widget.avgs!
|
||||
.map((e) => FlSpot(
|
||||
e.date.millisecondsSinceEpoch.toDouble(),
|
||||
e.value.toDouble(),
|
||||
))
|
||||
.map(
|
||||
(e) => FlSpot(
|
||||
e.date.millisecondsSinceEpoch.toDouble(),
|
||||
e.value.toDouble(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isCurved: false,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
|
||||
@@ -40,81 +40,85 @@ class EntriesList extends StatelessWidget {
|
||||
final numberFormat = NumberFormat.decimalPattern(Localizations.localeOf(context).toString());
|
||||
final provider = Provider.of<MeasurementProvider>(context, listen: false);
|
||||
|
||||
final entriesAll =
|
||||
_category.entries.map((e) => MeasurementChartEntry(e.value, e.date)).toList();
|
||||
final entriesAll = _category.entries
|
||||
.map((e) => MeasurementChartEntry(e.value, e.date))
|
||||
.toList();
|
||||
final entries7dAvg = moving7dAverage(entriesAll);
|
||||
|
||||
return Column(children: [
|
||||
...getOverviewWidgetsSeries(
|
||||
_category.name,
|
||||
entriesAll,
|
||||
entries7dAvg,
|
||||
plans,
|
||||
_category.unit,
|
||||
context,
|
||||
),
|
||||
SizedBox(
|
||||
height: 300,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: _category.entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentEntry = _category.entries[index];
|
||||
return Column(
|
||||
children: [
|
||||
...getOverviewWidgetsSeries(
|
||||
_category.name,
|
||||
entriesAll,
|
||||
entries7dAvg,
|
||||
plans,
|
||||
_category.unit,
|
||||
context,
|
||||
),
|
||||
SizedBox(
|
||||
height: 300,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: _category.entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentEntry = _category.entries[index];
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text('${numberFormat.format(currentEntry.value)} ${_category.unit}'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(currentEntry.date),
|
||||
),
|
||||
trailing: PopupMenuButton(
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
MeasurementEntryForm(
|
||||
currentEntry.category,
|
||||
currentEntry,
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text('${numberFormat.format(currentEntry.value)} ${_category.unit}'),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).format(currentEntry.date),
|
||||
),
|
||||
trailing: PopupMenuButton(
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).edit,
|
||||
MeasurementEntryForm(
|
||||
currentEntry.category,
|
||||
currentEntry,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
onTap: () async {
|
||||
// Delete entry from DB
|
||||
await provider.deleteEntry(
|
||||
currentEntry.id!,
|
||||
currentEntry.category,
|
||||
);
|
||||
|
||||
// and inform the user
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
onTap: () async {
|
||||
// Delete entry from DB
|
||||
await provider.deleteEntry(
|
||||
currentEntry.id!,
|
||||
currentEntry.category,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
// and inform the user
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
]);
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -284,13 +284,15 @@ class MeasurementEntryForm extends StatelessWidget {
|
||||
? await Provider.of<MeasurementProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).addEntry(MeasurementEntry(
|
||||
id: _entryData['id'],
|
||||
category: _entryData['category'],
|
||||
date: _entryData['date'],
|
||||
value: _entryData['value'],
|
||||
notes: _entryData['notes'],
|
||||
))
|
||||
).addEntry(
|
||||
MeasurementEntry(
|
||||
id: _entryData['id'],
|
||||
category: _entryData['category'],
|
||||
date: _entryData['date'],
|
||||
value: _entryData['value'],
|
||||
notes: _entryData['notes'],
|
||||
),
|
||||
)
|
||||
: await Provider.of<MeasurementProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
|
||||
@@ -25,8 +25,8 @@ List<Widget> getOverviewWidgets(
|
||||
child: Text(
|
||||
'No data available',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.secondary.withValues(alpha: 0.7),
|
||||
),
|
||||
color: Theme.of(context).colorScheme.secondary.withValues(alpha: 0.7),
|
||||
),
|
||||
),
|
||||
)
|
||||
: MeasurementChartWidgetFl(raw, unit, avgs: avg),
|
||||
|
||||
+141
-118
@@ -71,17 +71,21 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
|
||||
// paint a surplus
|
||||
if (val > plan) {
|
||||
return Stack(children: [
|
||||
segment(normWidth * val / plan, COLOR_SURPLUS),
|
||||
segment(normWidth, LIST_OF_COLORS8[0]),
|
||||
]);
|
||||
return Stack(
|
||||
children: [
|
||||
segment(normWidth * val / plan, COLOR_SURPLUS),
|
||||
segment(normWidth, LIST_OF_COLORS8[0]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// paint a deficit
|
||||
return Stack(children: [
|
||||
segment(normWidth, Theme.of(context).colorScheme.surface),
|
||||
segment(normWidth * val / plan, LIST_OF_COLORS8[0]),
|
||||
]);
|
||||
return Stack(
|
||||
children: [
|
||||
segment(normWidth, Theme.of(context).colorScheme.surface),
|
||||
segment(normWidth * val / plan, LIST_OF_COLORS8[0]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -90,87 +94,102 @@ class FlNutritionalPlanGoalWidget extends StatelessWidget {
|
||||
final goals = plan.nutritionalGoals;
|
||||
final today = plan.loggedNutritionalValuesToday;
|
||||
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
// if any of the bars goes over 100%, find the one that goes over the most
|
||||
// that one needs the most horizontal space to show how much it goes over,
|
||||
// and therefore reduces the width of "100%" the most, and this width we want
|
||||
// to be consistent for all other bars.
|
||||
// if none goes over, 100% means fill all available space
|
||||
final maxVal = [
|
||||
1.0,
|
||||
if (goals.energy != null && goals.energy! > 0) today.energy / goals.energy!,
|
||||
if (goals.protein != null && goals.protein! > 0) today.protein / goals.protein!,
|
||||
if (goals.carbohydrates != null && goals.carbohydrates! > 0)
|
||||
today.carbohydrates / goals.carbohydrates!,
|
||||
if (goals.fat != null && goals.fat! > 0) today.fat / goals.fat!,
|
||||
if (goals.fiber != null && goals.fiber! > 0) today.fiber / goals.fiber!,
|
||||
].reduce(max);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// if any of the bars goes over 100%, find the one that goes over the most
|
||||
// that one needs the most horizontal space to show how much it goes over,
|
||||
// and therefore reduces the width of "100%" the most, and this width we want
|
||||
// to be consistent for all other bars.
|
||||
// if none goes over, 100% means fill all available space
|
||||
final maxVal = [
|
||||
1.0,
|
||||
if (goals.energy != null && goals.energy! > 0) today.energy / goals.energy!,
|
||||
if (goals.protein != null && goals.protein! > 0) today.protein / goals.protein!,
|
||||
if (goals.carbohydrates != null && goals.carbohydrates! > 0)
|
||||
today.carbohydrates / goals.carbohydrates!,
|
||||
if (goals.fat != null && goals.fat! > 0) today.fat / goals.fat!,
|
||||
if (goals.fiber != null && goals.fiber! > 0) today.fiber / goals.fiber!,
|
||||
].reduce(max);
|
||||
|
||||
final normWidth = constraints.maxWidth / maxVal;
|
||||
final normWidth = constraints.maxWidth / maxVal;
|
||||
|
||||
String fmtMacro(String name, double today, double? goal, String unit) {
|
||||
return '$name: ${today.toStringAsFixed(0)}${goal == null ? '' : ' / ${goal.toStringAsFixed(0)}'} $unit';
|
||||
}
|
||||
String fmtMacro(String name, double today, double? goal, String unit) {
|
||||
return '$name: ${today.toStringAsFixed(0)}${goal == null ? '' : ' / ${goal.toStringAsFixed(0)}'} $unit';
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(fmtMacro(
|
||||
AppLocalizations.of(context).energy,
|
||||
today.energy,
|
||||
goals.energy,
|
||||
AppLocalizations.of(context).kcal,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.energy, today.energy),
|
||||
const SizedBox(height: 8),
|
||||
Text(fmtMacro(
|
||||
AppLocalizations.of(context).protein,
|
||||
today.protein,
|
||||
goals.protein,
|
||||
AppLocalizations.of(context).g,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.protein, today.protein),
|
||||
const SizedBox(height: 8),
|
||||
Text(fmtMacro(
|
||||
AppLocalizations.of(context).carbohydrates,
|
||||
today.carbohydrates,
|
||||
goals.carbohydrates,
|
||||
AppLocalizations.of(context).g,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(
|
||||
context,
|
||||
normWidth,
|
||||
goals.carbohydrates,
|
||||
today.carbohydrates,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(fmtMacro(
|
||||
AppLocalizations.of(context).fat,
|
||||
today.fat,
|
||||
goals.fat,
|
||||
AppLocalizations.of(context).g,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.fat, today.fat),
|
||||
// optionally display the advanced macro goals:
|
||||
if (goals.fiber != null)
|
||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
const SizedBox(height: 8),
|
||||
Text(fmtMacro(
|
||||
AppLocalizations.of(context).fiber,
|
||||
today.fiber,
|
||||
goals.fiber,
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
fmtMacro(
|
||||
AppLocalizations.of(context).energy,
|
||||
today.energy,
|
||||
goals.energy,
|
||||
AppLocalizations.of(context).kcal,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.energy, today.energy),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
fmtMacro(
|
||||
AppLocalizations.of(context).protein,
|
||||
today.protein,
|
||||
goals.protein,
|
||||
AppLocalizations.of(context).g,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.fiber, today.fiber),
|
||||
]),
|
||||
],
|
||||
);
|
||||
});
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.protein, today.protein),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
fmtMacro(
|
||||
AppLocalizations.of(context).carbohydrates,
|
||||
today.carbohydrates,
|
||||
goals.carbohydrates,
|
||||
AppLocalizations.of(context).g,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(
|
||||
context,
|
||||
normWidth,
|
||||
goals.carbohydrates,
|
||||
today.carbohydrates,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
fmtMacro(
|
||||
AppLocalizations.of(context).fat,
|
||||
today.fat,
|
||||
goals.fat,
|
||||
AppLocalizations.of(context).g,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.fat, today.fat),
|
||||
// optionally display the advanced macro goals:
|
||||
if (goals.fiber != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
fmtMacro(
|
||||
AppLocalizations.of(context).fiber,
|
||||
today.fiber,
|
||||
goals.fiber,
|
||||
AppLocalizations.of(context).g,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
_diyGauge(context, normWidth, goals.fiber, today.fiber),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,16 +246,19 @@ class FlNutritionalPlanPieChartState extends State<FlNutritionalPlanPieChartWidg
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
(AppLocalizations.of(context).protein, LIST_OF_COLORS3[1]),
|
||||
(AppLocalizations.of(context).carbohydrates, LIST_OF_COLORS3[0]),
|
||||
(AppLocalizations.of(context).fat, LIST_OF_COLORS3[2]),
|
||||
]
|
||||
.map((e) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Indicator(color: e.$2, text: e.$1, isSquare: true),
|
||||
))
|
||||
.toList(),
|
||||
children:
|
||||
[
|
||||
(AppLocalizations.of(context).protein, LIST_OF_COLORS3[1]),
|
||||
(AppLocalizations.of(context).carbohydrates, LIST_OF_COLORS3[0]),
|
||||
(AppLocalizations.of(context).fat, LIST_OF_COLORS3[2]),
|
||||
]
|
||||
.map(
|
||||
(e) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Indicator(color: e.$2, text: e.$1, isSquare: true),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(width: 28),
|
||||
],
|
||||
@@ -433,21 +455,22 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
|
||||
spacing: 10.0,
|
||||
runSpacing: 10.0,
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
(AppLocalizations.of(context).deficit, colorPlanned),
|
||||
(AppLocalizations.of(context).surplus, COLOR_SURPLUS),
|
||||
(AppLocalizations.of(context).today, colorLoggedToday),
|
||||
(AppLocalizations.of(context).weekAverage, colorLogged7Day),
|
||||
]
|
||||
.map(
|
||||
(e) => Indicator(
|
||||
text: e.$1,
|
||||
color: e.$2,
|
||||
isSquare: true,
|
||||
marginRight: 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
children:
|
||||
[
|
||||
(AppLocalizations.of(context).deficit, colorPlanned),
|
||||
(AppLocalizations.of(context).surplus, COLOR_SURPLUS),
|
||||
(AppLocalizations.of(context).today, colorLoggedToday),
|
||||
(AppLocalizations.of(context).weekAverage, colorLogged7Day),
|
||||
]
|
||||
.map(
|
||||
(e) => Indicator(
|
||||
text: e.$1,
|
||||
color: e.$2,
|
||||
isSquare: true,
|
||||
marginRight: 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -463,8 +486,8 @@ class MealDiaryBarChartWidget extends StatefulWidget {
|
||||
super.key,
|
||||
required NutritionalValues logged,
|
||||
required NutritionalValues planned,
|
||||
}) : _logged = logged,
|
||||
_planned = planned;
|
||||
}) : _logged = logged,
|
||||
_planned = planned;
|
||||
|
||||
final NutritionalValues _logged;
|
||||
final NutritionalValues _planned;
|
||||
@@ -489,12 +512,12 @@ class MealDiaryBarChartWidgetState extends State<MealDiaryBarChartWidget> {
|
||||
}
|
||||
|
||||
Widget leftTitles(double value, TitleMeta meta) => SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(
|
||||
AppLocalizations.of(context).percentValue(value.toStringAsFixed(0)),
|
||||
style: const TextStyle(fontSize: 10),
|
||||
),
|
||||
);
|
||||
meta: meta,
|
||||
child: Text(
|
||||
AppLocalizations.of(context).percentValue(value.toStringAsFixed(0)),
|
||||
style: const TextStyle(fontSize: 10),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -138,8 +138,10 @@ Widget getIngredientLogForm(NutritionalPlan plan) {
|
||||
return IngredientForm(
|
||||
recent: plan.dedupDiaryEntries,
|
||||
onSave: (BuildContext context, MealItem mealItem, DateTime? dt) {
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.logIngredientToDiary(mealItem, plan.id!, dt);
|
||||
Provider.of<NutritionPlansProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).logIngredientToDiary(mealItem, plan.id!, dt);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -236,8 +238,9 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
Widget build(BuildContext context) {
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
final queryLower = _searchQuery.toLowerCase();
|
||||
final suggestions =
|
||||
widget.recent.where((e) => e.ingredient.name.toLowerCase().contains(queryLower)).toList();
|
||||
final suggestions = widget.recent
|
||||
.where((e) => e.ingredient.name.toLowerCase().contains(queryLower))
|
||||
.toList();
|
||||
final numberFormat = NumberFormat.decimalPattern(Localizations.localeOf(context).toString());
|
||||
|
||||
return Container(
|
||||
@@ -359,31 +362,32 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
context,
|
||||
listen: false,
|
||||
).fetchIngredient(_mealItem.ingredientId),
|
||||
builder: (
|
||||
BuildContext context,
|
||||
AsyncSnapshot<Ingredient> snapshot,
|
||||
) {
|
||||
if (snapshot.hasData) {
|
||||
_mealItem.ingredient = snapshot.data!;
|
||||
return MealItemValuesTile(
|
||||
ingredient: _mealItem.ingredient,
|
||||
nutritionalValues: _mealItem.nutritionalValues,
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Text(
|
||||
'Ingredient lookup error: ${snapshot.error}',
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
builder:
|
||||
(
|
||||
BuildContext context,
|
||||
AsyncSnapshot<Ingredient> snapshot,
|
||||
) {
|
||||
if (snapshot.hasData) {
|
||||
_mealItem.ingredient = snapshot.data!;
|
||||
return MealItemValuesTile(
|
||||
ingredient: _mealItem.ingredient,
|
||||
nutritionalValues: _mealItem.nutritionalValues,
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Text(
|
||||
'Ingredient lookup error: ${snapshot.error}',
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -432,10 +436,12 @@ class IngredientFormState extends State<IngredientForm> {
|
||||
title: Text(
|
||||
'${suggestions[index].ingredient.name} (${suggestions[index].amount.toStringAsFixed(0)}$unit)',
|
||||
),
|
||||
subtitle: Text(getShortNutritionValues(
|
||||
suggestions[index].ingredient.nutritionalValues,
|
||||
context,
|
||||
)),
|
||||
subtitle: Text(
|
||||
getShortNutritionValues(
|
||||
suggestions[index].ingredient.nutritionalValues,
|
||||
context,
|
||||
),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
@@ -27,18 +27,18 @@ import 'package:wger/widgets/core/core.dart';
|
||||
import 'package:wger/widgets/nutrition/ingredient_dialogs.dart';
|
||||
|
||||
List<String> getNutritionColumnNames(BuildContext context) => [
|
||||
AppLocalizations.of(context).energy,
|
||||
AppLocalizations.of(context).protein,
|
||||
AppLocalizations.of(context).carbohydrates,
|
||||
AppLocalizations.of(context).fat,
|
||||
];
|
||||
AppLocalizations.of(context).energy,
|
||||
AppLocalizations.of(context).protein,
|
||||
AppLocalizations.of(context).carbohydrates,
|
||||
AppLocalizations.of(context).fat,
|
||||
];
|
||||
|
||||
List<String> getNutritionalValues(NutritionalValues values, BuildContext context) => [
|
||||
AppLocalizations.of(context).kcalValue(values.energy.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.protein.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.carbohydrates.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.fat.toStringAsFixed(0)),
|
||||
];
|
||||
AppLocalizations.of(context).kcalValue(values.energy.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.protein.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.carbohydrates.toStringAsFixed(0)),
|
||||
AppLocalizations.of(context).gValue(values.fat.toStringAsFixed(0)),
|
||||
];
|
||||
|
||||
List<int> getNutritionColumnFlexes(BuildContext context) {
|
||||
return getNutritionColumnNames(context).map((e) {
|
||||
@@ -51,11 +51,13 @@ List<int> getNutritionColumnFlexes(BuildContext context) {
|
||||
}
|
||||
|
||||
List<Widget> muted(List<String> children) => children
|
||||
.map((e) => MutedText(
|
||||
e,
|
||||
textAlign: TextAlign.right,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))
|
||||
.map(
|
||||
(e) => MutedText(
|
||||
e,
|
||||
textAlign: TextAlign.right,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
// return a row of elements in the standard macros spacing
|
||||
@@ -85,15 +87,17 @@ String getShortNutritionValues(NutritionalValues values, BuildContext context) {
|
||||
}
|
||||
|
||||
String getKcalConsumed(Meal meal, BuildContext context) {
|
||||
final consumed =
|
||||
meal.diaryEntriesToday.map((e) => e.nutritionalValues.energy).fold(0.0, (a, b) => a + b);
|
||||
final consumed = meal.diaryEntriesToday
|
||||
.map((e) => e.nutritionalValues.energy)
|
||||
.fold(0.0, (a, b) => a + b);
|
||||
return AppLocalizations.of(context).kcalValue(consumed.toStringAsFixed(0));
|
||||
}
|
||||
|
||||
String getKcalConsumedVsPlanned(Meal meal, BuildContext context) {
|
||||
final planned = meal.plannedNutritionalValues.energy;
|
||||
final consumed =
|
||||
meal.diaryEntriesToday.map((e) => e.nutritionalValues.energy).fold(0.0, (a, b) => a + b);
|
||||
final consumed = meal.diaryEntriesToday
|
||||
.map((e) => e.nutritionalValues.energy)
|
||||
.fold(0.0, (a, b) => a + b);
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
return '${consumed.toStringAsFixed(0)} / ${planned.toStringAsFixed(0)} ${loc.kcal}';
|
||||
|
||||
@@ -61,7 +61,7 @@ Widget ingredientImage(String url, BuildContext context) {
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -201,8 +201,9 @@ class IngredientScanResultDialog extends StatelessWidget {
|
||||
if (ingredient != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child:
|
||||
Text(AppLocalizations.of(context).productFoundDescription(ingredient.name)),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).productFoundDescription(ingredient.name),
|
||||
),
|
||||
),
|
||||
if (ingredient?.image?.url != null) ingredientImage(ingredient!.image!.url, context),
|
||||
if (snapshot.connectionState != ConnectionState.done && !snapshot.hasError)
|
||||
|
||||
@@ -22,13 +22,13 @@ class MacronutrientsTable extends StatelessWidget {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
Widget columnHeader(bool left, String title) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: left ? TextAlign.left : TextAlign.right,
|
||||
),
|
||||
);
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: left ? TextAlign.left : TextAlign.right,
|
||||
),
|
||||
);
|
||||
|
||||
TableRow macroRow(int indent, bool g, String title, double? Function(NutritionalGoals ng) get) {
|
||||
final goal = get(nutritionalGoals);
|
||||
|
||||
@@ -36,7 +36,7 @@ import 'package:wger/widgets/nutrition/widgets.dart';
|
||||
enum viewMode {
|
||||
base, // just highlevel meal info (name, time)
|
||||
withIngredients, // + ingredients
|
||||
withAllDetails // + nutritional breakdown of ingredients, + logged today
|
||||
withAllDetails, // + nutritional breakdown of ingredients, + logged today
|
||||
}
|
||||
|
||||
class MealWidget extends StatefulWidget {
|
||||
@@ -173,8 +173,9 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
),
|
||||
)
|
||||
else
|
||||
...widget._meal.mealItems
|
||||
.map((item) => MealItemEditableFullTile(item, _viewMode, _editing)),
|
||||
...widget._meal.mealItems.map(
|
||||
(item) => MealItemEditableFullTile(item, _viewMode, _editing),
|
||||
),
|
||||
if (_viewMode == viewMode.withIngredients || _viewMode == viewMode.withAllDetails)
|
||||
const Divider(),
|
||||
if (_viewMode == viewMode.withIngredients || _viewMode == viewMode.withAllDetails)
|
||||
@@ -201,12 +202,14 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
planned: widget._meal.plannedNutritionalValues,
|
||||
logged: widget._meal.loggedNutritionalValuesToday,
|
||||
),
|
||||
...widget._meal.diaryEntriesToday.map((item) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [DiaryEntryTile(diaryEntry: item)],
|
||||
),
|
||||
)),
|
||||
...widget._meal.diaryEntriesToday.map(
|
||||
(item) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [DiaryEntryTile(diaryEntry: item)],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -288,11 +291,11 @@ class MealHeader extends StatelessWidget {
|
||||
required viewMode viewMode,
|
||||
required Function() toggleEditing,
|
||||
required Function() toggleViewMode,
|
||||
}) : _meal = meal,
|
||||
_editing = editing,
|
||||
_viewMode = viewMode,
|
||||
_toggleViewMode = toggleViewMode,
|
||||
_toggleEditing = toggleEditing;
|
||||
}) : _meal = meal,
|
||||
_editing = editing,
|
||||
_viewMode = viewMode,
|
||||
_toggleViewMode = toggleViewMode,
|
||||
_toggleEditing = toggleEditing;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -82,8 +82,10 @@ class DiaryEntryTile extends StatelessWidget {
|
||||
: IconButton(
|
||||
tooltip: AppLocalizations.of(context).delete,
|
||||
onPressed: () {
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.deleteLog(diaryEntry.id!, nutritionalPlan!.id!);
|
||||
Provider.of<NutritionPlansProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).deleteLog(diaryEntry.id!, nutritionalPlan!.id!);
|
||||
},
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
iconSize: ICON_SIZE_SMALL,
|
||||
|
||||
@@ -85,13 +85,13 @@ class NutritionDiaryTable extends StatelessWidget {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
Widget columnHeader(bool left, String title) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: left ? TextAlign.left : TextAlign.right,
|
||||
),
|
||||
);
|
||||
padding: const EdgeInsets.symmetric(vertical: tablePadding),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: left ? TextAlign.left : TextAlign.right,
|
||||
),
|
||||
);
|
||||
|
||||
TableRow macroRow(int indent, bool g, String title, double Function(NutritionalValues nv) get) {
|
||||
final valFn = g ? loc.gValue : loc.kcalValue;
|
||||
@@ -115,12 +115,14 @@ class NutritionDiaryTable extends StatelessWidget {
|
||||
),
|
||||
columnWidths: const {0: FractionColumnWidth(0.4)},
|
||||
children: [
|
||||
TableRow(children: [
|
||||
columnHeader(true, loc.macronutrients),
|
||||
columnHeader(false, loc.planned),
|
||||
columnHeader(false, loc.logged),
|
||||
columnHeader(false, loc.difference),
|
||||
]),
|
||||
TableRow(
|
||||
children: [
|
||||
columnHeader(true, loc.macronutrients),
|
||||
columnHeader(false, loc.planned),
|
||||
columnHeader(false, loc.logged),
|
||||
columnHeader(false, loc.difference),
|
||||
],
|
||||
),
|
||||
macroRow(0, false, loc.energy, (NutritionalValues nv) => nv.energy),
|
||||
macroRow(0, true, loc.protein, (NutritionalValues nv) => nv.protein),
|
||||
macroRow(0, true, loc.carbohydrates, (NutritionalValues nv) => nv.carbohydrates),
|
||||
|
||||
@@ -82,41 +82,44 @@ class NutritionalDiaryTable extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
border: Border(top: BorderSide(color: Colors.grey[300]!)),
|
||||
),
|
||||
children: [
|
||||
Text(
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: LIST_OF_COLORS3.first),
|
||||
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.energy.toStringAsFixed(0),
|
||||
),
|
||||
if (goals.energy != null)
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
(values.energy - goals.energy!).toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.protein.toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.carbohydrates.toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.fat.toStringAsFixed(0),
|
||||
),
|
||||
].map((element) {
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.of(context).pushNamed(
|
||||
NutritionalDiaryScreen.routeName,
|
||||
arguments: NutritionalDiaryArguments(plan, date),
|
||||
),
|
||||
child: element,
|
||||
);
|
||||
}).toList(),
|
||||
children:
|
||||
[
|
||||
Text(
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(color: LIST_OF_COLORS3.first),
|
||||
DateFormat.Md(Localizations.localeOf(context).languageCode).format(date),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.energy.toStringAsFixed(0),
|
||||
),
|
||||
if (goals.energy != null)
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
(values.energy - goals.energy!).toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.protein.toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.carbohydrates.toStringAsFixed(0),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.end,
|
||||
values.fat.toStringAsFixed(0),
|
||||
),
|
||||
].map((element) {
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.of(context).pushNamed(
|
||||
NutritionalDiaryScreen.routeName,
|
||||
arguments: NutritionalDiaryArguments(plan, date),
|
||||
),
|
||||
child: element,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,13 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nutritionalGoals = _nutritionalPlan.nutritionalGoals;
|
||||
final lastWeightEntry =
|
||||
Provider.of<BodyWeightProvider>(context, listen: false).getNewestEntry();
|
||||
final nutritionalGoalsGperKg =
|
||||
lastWeightEntry != null ? nutritionalGoals / lastWeightEntry.weight.toDouble() : null;
|
||||
final lastWeightEntry = Provider.of<BodyWeightProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).getNewestEntry();
|
||||
final nutritionalGoalsGperKg = lastWeightEntry != null
|
||||
? nutritionalGoals / lastWeightEntry.weight.toDouble()
|
||||
: null;
|
||||
|
||||
return SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
@@ -57,8 +60,8 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).format(_nutritionalPlan.startDate)} (${AppLocalizations.of(context).openEnded})',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -73,12 +76,14 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
..._nutritionalPlan.meals.map((meal) => MealWidget(
|
||||
meal,
|
||||
_nutritionalPlan.dedupMealItems,
|
||||
false,
|
||||
false,
|
||||
)),
|
||||
..._nutritionalPlan.meals.map(
|
||||
(meal) => MealWidget(
|
||||
meal,
|
||||
_nutritionalPlan.dedupMealItems,
|
||||
false,
|
||||
false,
|
||||
),
|
||||
),
|
||||
MealWidget(
|
||||
_nutritionalPlan.pseudoMealOthers('Other logs'),
|
||||
_nutritionalPlan.dedupMealItems,
|
||||
|
||||
@@ -77,9 +77,9 @@ class NutritionalPlansList extends StatelessWidget {
|
||||
Text(
|
||||
weightChangeText,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: weightChangeColor,
|
||||
),
|
||||
fontWeight: FontWeight.bold,
|
||||
color: weightChangeColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -123,60 +123,64 @@ class NutritionalPlansList extends StatelessWidget {
|
||||
_buildWeightChangeInfo(context, currentPlan.startDate, currentPlan.endDate),
|
||||
],
|
||||
),
|
||||
trailing: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
const VerticalDivider(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
tooltip: AppLocalizations.of(context).delete,
|
||||
onPressed: () async {
|
||||
// Delete the plan from DB
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.confirmDelete(currentPlan.description),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).cancelButtonLabel,
|
||||
),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const VerticalDivider(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
tooltip: AppLocalizations.of(context).delete,
|
||||
onPressed: () async {
|
||||
// Delete the plan from DB
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).confirmDelete(currentPlan.description),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).cancelButtonLabel,
|
||||
),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the plan
|
||||
_nutritionProvider.deletePlan(currentPlan.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the plan
|
||||
_nutritionProvider.deletePlan(currentPlan.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
|
||||
// and inform the user
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -38,19 +38,19 @@ class ScanReader extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
body: ReaderWidget(
|
||||
onScan: (result) {
|
||||
// notes:
|
||||
// 1. even if result.isValid, result.error is always non-null (and set to "")
|
||||
// 2. i've never encountered scan errors to see when they occur, and
|
||||
// i wouldn't know what to do about them anyway, so we simply return
|
||||
// result.text in such case (which presumably will be null, or "")
|
||||
// 3. when user cancels (swipe left / back button) this code is no longer
|
||||
// run and the caller receives null
|
||||
Navigator.pop(context, result.text);
|
||||
},
|
||||
),
|
||||
);
|
||||
body: ReaderWidget(
|
||||
onScan: (result) {
|
||||
// notes:
|
||||
// 1. even if result.isValid, result.error is always non-null (and set to "")
|
||||
// 2. i've never encountered scan errors to see when they occur, and
|
||||
// i wouldn't know what to do about them anyway, so we simply return
|
||||
// result.text in such case (which presumably will be null, or "")
|
||||
// 3. when user cancels (swipe left / back button) this code is no longer
|
||||
// run and the caller receives null
|
||||
Navigator.pop(context, result.text);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class IngredientTypeahead extends StatefulWidget {
|
||||
@@ -94,8 +94,9 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
|
||||
Future<String> openBarcodeScan(BuildContext context) async {
|
||||
try {
|
||||
final code = await Navigator.of(context)
|
||||
.push<String?>(MaterialPageRoute(builder: (context) => const ScanReader()));
|
||||
final code = await Navigator.of(
|
||||
context,
|
||||
).push<String?>(MaterialPageRoute(builder: (context) => const ScanReader()));
|
||||
|
||||
if (code == null) {
|
||||
return '';
|
||||
@@ -217,8 +218,10 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => FutureBuilder<Ingredient?>(
|
||||
future: Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.searchIngredientWithBarcode(barcode),
|
||||
future: Provider.of<NutritionPlansProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).searchIngredientWithBarcode(barcode),
|
||||
builder: (BuildContext context, AsyncSnapshot<Ingredient?> snapshot) {
|
||||
return IngredientScanResultDialog(snapshot, barcode, widget.selectIngredient);
|
||||
},
|
||||
|
||||
@@ -128,9 +128,9 @@ class DayHeader extends StatelessWidget {
|
||||
final bool _viewMode;
|
||||
|
||||
const DayHeader({required DayData day, required int routineId, bool viewMode = false})
|
||||
: _dayData = day,
|
||||
_viewMode = viewMode,
|
||||
_routineId = routineId;
|
||||
: _dayData = day,
|
||||
_viewMode = viewMode,
|
||||
_routineId = routineId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -309,8 +309,10 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
setState(() => isSaving = true);
|
||||
|
||||
try {
|
||||
await Provider.of<RoutinesProvider>(context, listen: false)
|
||||
.editDay(widget.day);
|
||||
await Provider.of<RoutinesProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).editDay(widget.day);
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
errorMessage = const SizedBox.shrink();
|
||||
@@ -330,8 +332,9 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
}
|
||||
}
|
||||
},
|
||||
child:
|
||||
isSaving ? const FormProgressIndicator() : Text(AppLocalizations.of(context).save),
|
||||
child: isSaving
|
||||
? const FormProgressIndicator()
|
||||
: Text(AppLocalizations.of(context).save),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
ReorderableSlotList(widget.day.slots, widget.day),
|
||||
|
||||
@@ -59,15 +59,15 @@ class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
|
||||
widget.onChanged(newValue.id);
|
||||
});
|
||||
},
|
||||
items: Provider.of<RoutinesProvider>(context, listen: false)
|
||||
.repetitionUnits
|
||||
items: Provider.of<RoutinesProvider>(context, listen: false).repetitionUnits
|
||||
.map<DropdownMenuItem<RepetitionUnit>>((RepetitionUnit value) {
|
||||
return DropdownMenuItem<RepetitionUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
child: Text(value.name),
|
||||
);
|
||||
}).toList(),
|
||||
return DropdownMenuItem<RepetitionUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
child: Text(value.name),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -37,16 +37,17 @@ class SessionForm extends StatefulWidget {
|
||||
static const SLIDER_START = -0.5;
|
||||
|
||||
SessionForm(this._routineId, {Function()? onSaved, WorkoutSession? session, int? dayId})
|
||||
: _onSaved = onSaved,
|
||||
_session = session ??
|
||||
WorkoutSession(
|
||||
routineId: _routineId,
|
||||
dayId: dayId,
|
||||
impression: DEFAULT_IMPRESSION,
|
||||
date: clock.now(),
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
timeStart: null,
|
||||
);
|
||||
: _onSaved = onSaved,
|
||||
_session =
|
||||
session ??
|
||||
WorkoutSession(
|
||||
routineId: _routineId,
|
||||
dayId: dayId,
|
||||
impression: DEFAULT_IMPRESSION,
|
||||
date: clock.now(),
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
timeStart: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_SessionFormState createState() => _SessionFormState();
|
||||
@@ -68,10 +69,12 @@ class _SessionFormState extends State<SessionForm> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
timeStartController.text =
|
||||
widget._session.timeStart == null ? '' : timeToString(widget._session.timeStart)!;
|
||||
timeEndController.text =
|
||||
widget._session.timeEnd == null ? '' : timeToString(widget._session.timeEnd)!;
|
||||
timeStartController.text = widget._session.timeStart == null
|
||||
? ''
|
||||
: timeToString(widget._session.timeStart)!;
|
||||
timeEndController.text = widget._session.timeEnd == null
|
||||
? ''
|
||||
: timeToString(widget._session.timeEnd)!;
|
||||
notesController.text = widget._session.notes;
|
||||
|
||||
selectedImpression[widget._session.impression - 1] = true;
|
||||
|
||||
@@ -53,9 +53,11 @@ class _SlotDetailWidgetState extends State<SlotDetailWidget> {
|
||||
return Column(
|
||||
children: [
|
||||
errorMessage,
|
||||
...widget.slot.entries.map((entry) => entry.hasProgressionRules
|
||||
? ProgressionRulesInfoBox(entry.exerciseObj)
|
||||
: SlotEntryForm(entry, widget.routineId, simpleMode: widget.simpleMode)),
|
||||
...widget.slot.entries.map(
|
||||
(entry) => entry.hasProgressionRules
|
||||
? ProgressionRulesInfoBox(entry.exerciseObj)
|
||||
: SlotEntryForm(entry, widget.routineId, simpleMode: widget.simpleMode),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (_showExerciseSearchBox || widget.slot.entries.isEmpty)
|
||||
ExerciseAutocompleter(
|
||||
|
||||
@@ -85,8 +85,9 @@ class _SlotEntryFormState extends State<SlotEntryForm> {
|
||||
repetitionsController.text = widget.entry.repetitionsConfigs.first.value.round().toString();
|
||||
}
|
||||
if (widget.entry.maxRepetitionsConfigs.isNotEmpty) {
|
||||
maxRepetitionsController.text =
|
||||
widget.entry.maxRepetitionsConfigs.first.value.round().toString();
|
||||
maxRepetitionsController.text = widget.entry.maxRepetitionsConfigs.first.value
|
||||
.round()
|
||||
.toString();
|
||||
}
|
||||
|
||||
if (widget.entry.restTimeConfigs.isNotEmpty) {
|
||||
@@ -384,8 +385,9 @@ class _SlotEntryFormState extends State<SlotEntryForm> {
|
||||
}
|
||||
}
|
||||
},
|
||||
child:
|
||||
isSaving ? const FormProgressIndicator() : Text(AppLocalizations.of(context).save),
|
||||
child: isSaving
|
||||
? const FormProgressIndicator()
|
||||
: Text(AppLocalizations.of(context).save),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
@@ -417,9 +419,11 @@ class _SlotDetailWidgetState extends State<SlotDetailWidget> {
|
||||
return Column(
|
||||
children: [
|
||||
errorMessage,
|
||||
...widget.slot.entries.map((entry) => entry.hasProgressionRules
|
||||
? ProgressionRulesInfoBox(entry.exerciseObj)
|
||||
: SlotEntryForm(entry, widget.routineId, simpleMode: widget.simpleMode)),
|
||||
...widget.slot.entries.map(
|
||||
(entry) => entry.hasProgressionRules
|
||||
? ProgressionRulesInfoBox(entry.exerciseObj)
|
||||
: SlotEntryForm(entry, widget.routineId, simpleMode: widget.simpleMode),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (_showExerciseSearchBox || widget.slot.entries.isEmpty)
|
||||
ExerciseAutocompleter(
|
||||
|
||||
@@ -56,15 +56,15 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
widget.onChanged(newValue.id);
|
||||
});
|
||||
},
|
||||
items: Provider.of<RoutinesProvider>(context, listen: false)
|
||||
.weightUnits
|
||||
items: Provider.of<RoutinesProvider>(context, listen: false).weightUnits
|
||||
.map<DropdownMenuItem<WeightUnit>>((WeightUnit value) {
|
||||
return DropdownMenuItem<WeightUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
child: Text(value.name),
|
||||
);
|
||||
}).toList(),
|
||||
return DropdownMenuItem<WeightUnit>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
child: Text(value.name),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,9 @@ class _GymModeState extends ConsumerState<GymMode> {
|
||||
// Re-fetch the current routine data to ensure we have the latest session
|
||||
// data since it is possible that the user created or deleted it from the
|
||||
// web interface.
|
||||
await context
|
||||
.read<RoutinesProvider>()
|
||||
.fetchAndSetRoutineFull(widget._dayDataGym.day!.routineId);
|
||||
await context.read<RoutinesProvider>().fetchAndSetRoutineFull(
|
||||
widget._dayDataGym.day!.routineId,
|
||||
);
|
||||
widget._logger.fine('Refreshed routine data');
|
||||
|
||||
final validUntil = ref.read(gymStateProvider).validUntil;
|
||||
@@ -137,33 +137,39 @@ class _GymModeState extends ConsumerState<GymMode> {
|
||||
currentElement++;
|
||||
|
||||
if (firstPage && state.showExercisePages) {
|
||||
out.add(ExerciseOverview(
|
||||
_controller,
|
||||
exercise,
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
));
|
||||
out.add(
|
||||
ExerciseOverview(
|
||||
_controller,
|
||||
exercise,
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
out.add(LogPage(
|
||||
_controller,
|
||||
config,
|
||||
slotData,
|
||||
exercise,
|
||||
routinesProvider.findById(widget._dayDataGym.day!.routineId),
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
widget._iteration,
|
||||
));
|
||||
out.add(
|
||||
LogPage(
|
||||
_controller,
|
||||
config,
|
||||
slotData,
|
||||
exercise,
|
||||
routinesProvider.findById(widget._dayDataGym.day!.routineId),
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
widget._iteration,
|
||||
),
|
||||
);
|
||||
|
||||
// If there is a rest time, add a countdown timer
|
||||
if (config.restTime != null) {
|
||||
out.add(TimerCountdownWidget(
|
||||
_controller,
|
||||
config.restTime!.toInt(),
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
));
|
||||
out.add(
|
||||
TimerCountdownWidget(
|
||||
_controller,
|
||||
config.restTime!.toInt(),
|
||||
ratioCompleted,
|
||||
state.exercisePages,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
out.add(TimerWidget(_controller, ratioCompleted, state.exercisePages));
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ class LogPage extends ConsumerStatefulWidget {
|
||||
this._exercisePages,
|
||||
int? iteration,
|
||||
) : _log = Log.fromSetConfigData(_configData)
|
||||
..routineId = _workoutPlan.id!
|
||||
..iteration = iteration;
|
||||
..routineId = _workoutPlan.id!
|
||||
..iteration = iteration;
|
||||
|
||||
@override
|
||||
_LogPageState createState() => _LogPageState();
|
||||
@@ -250,8 +250,9 @@ class _LogPageState extends ConsumerState<LogPage> {
|
||||
rethrow;
|
||||
}
|
||||
},
|
||||
child:
|
||||
_isSaving ? const FormProgressIndicator() : Text(AppLocalizations.of(context).save),
|
||||
child: _isSaving
|
||||
? const FormProgressIndicator()
|
||||
: Text(AppLocalizations.of(context).save),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -274,10 +275,9 @@ class _LogPageState extends ConsumerState<LogPage> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
widget._configData.textRepr,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headlineMedium
|
||||
?.copyWith(color: Theme.of(context).colorScheme.primary),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.headlineMedium?.copyWith(color: Theme.of(context).colorScheme.primary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -499,7 +499,9 @@ class LogsWeightWidget extends ConsumerWidget {
|
||||
setStateCallback(() {
|
||||
log.weight = newValue;
|
||||
controller.text = numberFormat.format(newValue);
|
||||
ref.read(plateCalculatorProvider.notifier).setWeight(
|
||||
ref
|
||||
.read(plateCalculatorProvider.notifier)
|
||||
.setWeight(
|
||||
controller.text == '' ? 0 : newValue,
|
||||
);
|
||||
});
|
||||
@@ -519,7 +521,9 @@ class LogsWeightWidget extends ConsumerWidget {
|
||||
final newValue = numberFormat.parse(value);
|
||||
setStateCallback(() {
|
||||
log.weight = newValue;
|
||||
ref.read(plateCalculatorProvider.notifier).setWeight(
|
||||
ref
|
||||
.read(plateCalculatorProvider.notifier)
|
||||
.setWeight(
|
||||
controller.text == '' ? 0 : numberFormat.parse(controller.text),
|
||||
);
|
||||
});
|
||||
@@ -548,7 +552,9 @@ class LogsWeightWidget extends ConsumerWidget {
|
||||
setStateCallback(() {
|
||||
log.weight = newValue;
|
||||
controller.text = numberFormat.format(newValue);
|
||||
ref.read(plateCalculatorProvider.notifier).setWeight(
|
||||
ref
|
||||
.read(plateCalculatorProvider.notifier)
|
||||
.setWeight(
|
||||
controller.text == '' ? 0 : newValue,
|
||||
);
|
||||
});
|
||||
@@ -601,10 +607,12 @@ class LogsPastLogsWidget extends StatelessWidget {
|
||||
onTap: () {
|
||||
setStateCallback(() {
|
||||
// Text field
|
||||
repetitionsController.text =
|
||||
pastLog.repetitions != null ? numberFormat.format(pastLog.repetitions) : '';
|
||||
weightController.text =
|
||||
pastLog.weight != null ? numberFormat.format(pastLog.weight) : '';
|
||||
repetitionsController.text = pastLog.repetitions != null
|
||||
? numberFormat.format(pastLog.repetitions)
|
||||
: '';
|
||||
weightController.text = pastLog.weight != null
|
||||
? numberFormat.format(pastLog.weight)
|
||||
: '';
|
||||
|
||||
// Drop downs
|
||||
log.rir = pastLog.rir;
|
||||
@@ -612,9 +620,11 @@ class LogsPastLogsWidget extends StatelessWidget {
|
||||
log.weightUnit = pastLog.weightUnitObj;
|
||||
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(AppLocalizations.of(context).dataCopied),
|
||||
));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context).dataCopied),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 40),
|
||||
|
||||
@@ -38,17 +38,19 @@ class SessionPage extends StatelessWidget {
|
||||
TimeOfDay start,
|
||||
this._exercisePages, {
|
||||
int? dayId,
|
||||
}) : _session = _routine.sessions.map((sessionApi) => sessionApi.session).firstWhere(
|
||||
(session) => session.date.isSameDayAs(clock.now()),
|
||||
orElse: () => WorkoutSession(
|
||||
dayId: dayId,
|
||||
routineId: _routine.id!,
|
||||
impression: DEFAULT_IMPRESSION,
|
||||
date: clock.now(),
|
||||
timeStart: start,
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
),
|
||||
);
|
||||
}) : _session = _routine.sessions
|
||||
.map((sessionApi) => sessionApi.session)
|
||||
.firstWhere(
|
||||
(session) => session.date.isSameDayAs(clock.now()),
|
||||
orElse: () => WorkoutSession(
|
||||
dayId: dayId,
|
||||
routineId: _routine.id!,
|
||||
impression: DEFAULT_IMPRESSION,
|
||||
date: clock.now(),
|
||||
timeStart: start,
|
||||
timeEnd: TimeOfDay.fromDateTime(clock.now()),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -42,9 +42,11 @@ class StartPage extends StatelessWidget {
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(image: exercise.getMainImage),
|
||||
),
|
||||
title: Text(exercise
|
||||
.getTranslation(Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
title: Text(
|
||||
exercise
|
||||
.getTranslation(Localizations.localeOf(context).languageCode)
|
||||
.name,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: entry.value.map((text) => Text(text)).toList(),
|
||||
|
||||
@@ -56,8 +56,9 @@ class _SessionInfoState extends State<SessionInfo> {
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(widget._session.date),
|
||||
DateFormat.yMd(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
).format(widget._session.date),
|
||||
),
|
||||
onTap: () => setState(() => editMode = !editMode),
|
||||
trailing: Icon(editMode ? Icons.edit_off : Icons.edit),
|
||||
@@ -76,8 +77,9 @@ class _SessionInfoState extends State<SessionInfo> {
|
||||
context,
|
||||
i18n.timeStart,
|
||||
widget._session.timeStart != null
|
||||
? MaterialLocalizations.of(context)
|
||||
.formatTimeOfDay(widget._session.timeStart!)
|
||||
? MaterialLocalizations.of(
|
||||
context,
|
||||
).formatTimeOfDay(widget._session.timeStart!)
|
||||
: '-/-',
|
||||
),
|
||||
_buildInfoRow(
|
||||
@@ -166,8 +168,9 @@ class DayLogWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sessionApi =
|
||||
_routine.sessions.firstWhere((sessionApi) => sessionApi.session.date.isSameDayAs(_date));
|
||||
final sessionApi = _routine.sessions.firstWhere(
|
||||
(sessionApi) => sessionApi.session.date.isSameDayAs(_date),
|
||||
);
|
||||
final exercises = sessionApi.exercises;
|
||||
|
||||
return Card(
|
||||
@@ -175,15 +178,18 @@ class DayLogWidget extends StatelessWidget {
|
||||
children: [
|
||||
SessionInfo(sessionApi.session),
|
||||
...exercises.map((exercise) {
|
||||
final translation =
|
||||
exercise.getTranslation(Localizations.localeOf(context).languageCode);
|
||||
final translation = exercise.getTranslation(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
translation.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
...sessionApi.logs.where((l) => l.exerciseId == exercise.id).map(
|
||||
...sessionApi.logs
|
||||
.where((l) => l.exerciseId == exercise.id)
|
||||
.map(
|
||||
(log) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
||||
@@ -96,8 +96,9 @@ class _RoutinesListState extends State<RoutinesList> {
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.confirmDelete(currentRoutine.name),
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).confirmDelete(currentRoutine.name),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -34,7 +34,7 @@ class WeightForm extends StatelessWidget {
|
||||
final WeightEntry _weightEntry;
|
||||
|
||||
WeightForm([WeightEntry? weightEntry])
|
||||
: _weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
|
||||
: _weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -80,7 +80,8 @@ class WeightOverview extends StatelessWidget {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
'${numberFormat.format(currentEntry.weight)} ${weightUnit(profile.isMetric, context)}'),
|
||||
'${numberFormat.format(currentEntry.weight)} ${weightUnit(profile.isMetric, context)}',
|
||||
),
|
||||
subtitle: Text(
|
||||
DateFormat.yMd(
|
||||
Localizations.localeOf(context).languageCode,
|
||||
|
||||
+100
-70
@@ -94,21 +94,26 @@ void main() {
|
||||
buildSignature: 'buildSignature',
|
||||
);
|
||||
|
||||
when(mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) => Future(() => Response(json.encode(responseLoginOk), 200)));
|
||||
when(
|
||||
mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
).thenAnswer((_) => Future(() => Response(json.encode(responseLoginOk), 200)));
|
||||
|
||||
when(mockClient.get(any)).thenAnswer((_) => Future(() => Response('"1.2.3.4"', 200)));
|
||||
when(mockClient.get(any, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) => Future(() => Response('"1.2.3.4"', 200)));
|
||||
when(
|
||||
mockClient.get(any, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) => Future(() => Response('"1.2.3.4"', 200)));
|
||||
|
||||
when(mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) => Future(() => Response(json.encode(responseRegistrationOk), 201)));
|
||||
when(
|
||||
mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
).thenAnswer((_) => Future(() => Response(json.encode(responseRegistrationOk), 201)));
|
||||
});
|
||||
|
||||
group('Login mode', () {
|
||||
@@ -147,11 +152,13 @@ void main() {
|
||||
expect(find.byKey(const ValueKey('inputApiToken')), findsNothing);
|
||||
expect(find.textContaining('An Error Occurred'), findsNothing);
|
||||
verify(mockClient.get(any));
|
||||
verify(mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
));
|
||||
verify(
|
||||
mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Login - wrong username & password', (WidgetTester tester) async {
|
||||
@@ -161,11 +168,13 @@ void main() {
|
||||
final response = {
|
||||
'non_field_errors': ['Username or password unknown'],
|
||||
};
|
||||
when(mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
when(
|
||||
mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
|
||||
await tester.pumpWidget(getWidget());
|
||||
|
||||
@@ -178,11 +187,13 @@ void main() {
|
||||
// Assert
|
||||
expect(find.textContaining('Non field errors'), findsOne);
|
||||
expect(find.textContaining('Username or password unknown'), findsOne);
|
||||
verify(mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
));
|
||||
verify(
|
||||
mockClient.post(
|
||||
tLogin,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Login - with API token - happy path', (WidgetTester tester) async {
|
||||
@@ -207,20 +218,26 @@ void main() {
|
||||
expect(find.byKey(const Key('inputPassword')), findsNothing);
|
||||
expect(find.textContaining('An Error Occurred'), findsNothing);
|
||||
|
||||
verify(mockClient.get(
|
||||
tProfileCheck,
|
||||
headers: argThat(
|
||||
predicate((headers) =>
|
||||
headers is Map<String, String> &&
|
||||
headers['authorization'] == 'Token 1234567890abcdef1234567890abcdef12345678'),
|
||||
named: 'headers',
|
||||
verify(
|
||||
mockClient.get(
|
||||
tProfileCheck,
|
||||
headers: argThat(
|
||||
predicate(
|
||||
(headers) =>
|
||||
headers is Map<String, String> &&
|
||||
headers['authorization'] == 'Token 1234567890abcdef1234567890abcdef12345678',
|
||||
),
|
||||
named: 'headers',
|
||||
),
|
||||
),
|
||||
));
|
||||
verifyNever(mockClient.post(
|
||||
any,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
));
|
||||
);
|
||||
verifyNever(
|
||||
mockClient.post(
|
||||
any,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Login - with API token - wrong key', (WidgetTester tester) async {
|
||||
@@ -228,8 +245,9 @@ void main() {
|
||||
final response = {
|
||||
'detail': ['Invalid token'],
|
||||
};
|
||||
when(mockClient.get(tProfileCheck, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
when(
|
||||
mockClient.get(tProfileCheck, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
await tester.pumpWidget(getWidget());
|
||||
|
||||
// Act
|
||||
@@ -247,20 +265,26 @@ void main() {
|
||||
// Assert
|
||||
expect(find.textContaining('Detail'), findsOne);
|
||||
expect(find.textContaining('Invalid token'), findsOne);
|
||||
verify(mockClient.get(
|
||||
tProfileCheck,
|
||||
headers: argThat(
|
||||
predicate((headers) =>
|
||||
headers is Map<String, String> &&
|
||||
headers['authorization'] == 'Token 31e2ea0322c07b9df583a9b6d1e794f7139e78d4'),
|
||||
named: 'headers',
|
||||
verify(
|
||||
mockClient.get(
|
||||
tProfileCheck,
|
||||
headers: argThat(
|
||||
predicate(
|
||||
(headers) =>
|
||||
headers is Map<String, String> &&
|
||||
headers['authorization'] == 'Token 31e2ea0322c07b9df583a9b6d1e794f7139e78d4',
|
||||
),
|
||||
named: 'headers',
|
||||
),
|
||||
),
|
||||
));
|
||||
verifyNever(mockClient.post(
|
||||
any,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
));
|
||||
);
|
||||
verifyNever(
|
||||
mockClient.post(
|
||||
any,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -309,11 +333,13 @@ void main() {
|
||||
|
||||
// Assert
|
||||
expect(find.textContaining('An Error Occurred'), findsNothing);
|
||||
verify(mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
));
|
||||
verify(
|
||||
mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Registration - password problems', (WidgetTester tester) async {
|
||||
@@ -328,11 +354,13 @@ void main() {
|
||||
],
|
||||
};
|
||||
|
||||
when(mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
when(
|
||||
mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
),
|
||||
).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
|
||||
await tester.pumpWidget(getWidget());
|
||||
|
||||
// Act
|
||||
@@ -348,11 +376,13 @@ void main() {
|
||||
expect(find.textContaining('This password is entirely numeric'), findsOne);
|
||||
expect(find.textContaining('This field must be unique'), findsOne);
|
||||
|
||||
verify(mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
));
|
||||
verify(
|
||||
mockClient.post(
|
||||
tRegistration,
|
||||
headers: anyNamed('headers'),
|
||||
body: json.encode({'username': 'testuser', 'password': '123456789'}),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -31,9 +31,9 @@ class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeStreamedResponse_1 extends _i1.SmartFake implements _i2.StreamedResponse {
|
||||
@@ -41,9 +41,9 @@ class _FakeStreamedResponse_1 extends _i1.SmartFake implements _i2.StreamedRespo
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [Client].
|
||||
@@ -60,20 +60,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> get(
|
||||
@@ -81,20 +84,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> post(
|
||||
@@ -104,28 +110,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> put(
|
||||
@@ -135,28 +144,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> patch(
|
||||
@@ -166,28 +178,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> delete(
|
||||
@@ -197,28 +212,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<String> read(
|
||||
@@ -226,20 +244,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<String>.value(_i5.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<String>);
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<String>.value(
|
||||
_i5.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<String>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i6.Uint8List> readBytes(
|
||||
@@ -247,35 +268,40 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#readBytes,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i6.Uint8List>.value(_i6.Uint8List(0)),
|
||||
) as _i3.Future<_i6.Uint8List>);
|
||||
Invocation.method(
|
||||
#readBytes,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i6.Uint8List>.value(_i6.Uint8List(0)),
|
||||
)
|
||||
as _i3.Future<_i6.Uint8List>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
returnValue: _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.StreamedResponse>);
|
||||
_i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
returnValue: _i3.Future<_i2.StreamedResponse>.value(
|
||||
_FakeStreamedResponse_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.StreamedResponse>);
|
||||
|
||||
@override
|
||||
void close() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#close,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#close,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
+1219
-1031
File diff suppressed because it is too large.
Load diff
@@ -101,22 +101,26 @@ void main() {
|
||||
|
||||
// Mock categories
|
||||
when(mockBaseProvider.makeUrl(categoryUrl)).thenReturn(tCategoryEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tCategoryEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tCategoryMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tCategoryEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tCategoryMap['results']));
|
||||
|
||||
// Mock muscles
|
||||
when(mockBaseProvider.makeUrl(muscleUrl)).thenReturn(tMuscleEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tMuscleEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tMuscleMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tMuscleEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tMuscleMap['results']));
|
||||
|
||||
// Mock equipment
|
||||
when(mockBaseProvider.makeUrl(equipmentUrl)).thenReturn(tEquipmentEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tEquipmentEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tEquipmentMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tEquipmentEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tEquipmentMap['results']));
|
||||
|
||||
// Mock languages
|
||||
when(mockBaseProvider.makeUrl(languageUrl, query: anyNamed('query')))
|
||||
.thenReturn(tLanguageEntriesUri);
|
||||
when(
|
||||
mockBaseProvider.makeUrl(languageUrl, query: anyNamed('query')),
|
||||
).thenReturn(tLanguageEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tLanguageEntriesUri)).thenAnswer(
|
||||
(_) => Future.value(tLanguageMap['results']),
|
||||
);
|
||||
@@ -394,7 +398,9 @@ void main() {
|
||||
final valid = DateTime.now().add(const Duration(days: 1));
|
||||
prefs.setString(PREFS_LAST_UPDATED_LANGUAGES, valid.toIso8601String());
|
||||
|
||||
await database.into(database.exercises).insert(
|
||||
await database
|
||||
.into(database.exercises)
|
||||
.insert(
|
||||
ExercisesCompanion.insert(
|
||||
id: tExerciseInfoMap['id'],
|
||||
data: json.encode(tExerciseInfoMap),
|
||||
@@ -426,7 +432,9 @@ void main() {
|
||||
test('fetching a known exercise - no API refresh', () async {
|
||||
// Arrange
|
||||
provider.languages = testLanguages;
|
||||
await database.into(database.exercises).insert(
|
||||
await database
|
||||
.into(database.exercises)
|
||||
.insert(
|
||||
ExercisesCompanion.insert(
|
||||
id: tExerciseInfoMap['id'],
|
||||
data: json.encode(tExerciseInfoMap),
|
||||
@@ -451,7 +459,9 @@ void main() {
|
||||
test('fetching a known exercise - needed API refresh - no new data', () async {
|
||||
// Arrange
|
||||
provider.languages = testLanguages;
|
||||
await database.into(database.exercises).insert(
|
||||
await database
|
||||
.into(database.exercises)
|
||||
.insert(
|
||||
ExercisesCompanion.insert(
|
||||
id: tExerciseInfoMap['id'],
|
||||
data: json.encode(tExerciseInfoMap),
|
||||
@@ -465,8 +475,9 @@ void main() {
|
||||
|
||||
// Act
|
||||
await provider.handleUpdateExerciseFromApi(database, 9);
|
||||
final exerciseDb = await (database.select(database.exercises)..where((e) => e.id.equals(9)))
|
||||
.getSingleOrNull();
|
||||
final exerciseDb = await (database.select(
|
||||
database.exercises,
|
||||
)..where((e) => e.id.equals(9))).getSingleOrNull();
|
||||
|
||||
// Assert
|
||||
verify(mockBaseProvider.fetch(any));
|
||||
@@ -482,7 +493,9 @@ void main() {
|
||||
final newData = Map.from(tExerciseInfoMap);
|
||||
newData['uuid'] = 'bf6d5557-1c49-48fd-922e-75d11f81d4eb';
|
||||
|
||||
await database.into(database.exercises).insert(
|
||||
await database
|
||||
.into(database.exercises)
|
||||
.insert(
|
||||
ExercisesCompanion.insert(
|
||||
id: newData['id'],
|
||||
data: json.encode(newData),
|
||||
@@ -496,8 +509,9 @@ void main() {
|
||||
|
||||
// Act
|
||||
await provider.handleUpdateExerciseFromApi(database, 9);
|
||||
final exerciseDb = await (database.select(database.exercises)..where((e) => e.id.equals(9)))
|
||||
.getSingleOrNull();
|
||||
final exerciseDb = await (database.select(
|
||||
database.exercises,
|
||||
)..where((e) => e.id.equals(9))).getSingleOrNull();
|
||||
final exerciseData = ExerciseApiData.fromString(exerciseDb!.data);
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -57,10 +57,12 @@ void main() {
|
||||
when(mockBaseProvider.makeUrl(exerciseInfoUrl, id: 9)).thenReturn(tExerciseInfoUri);
|
||||
when(mockBaseProvider.makeUrl(exerciseInfoUrl, id: 1)).thenReturn(tExerciseInfoUri2);
|
||||
|
||||
when(mockBaseProvider.fetch(tExerciseInfoUri))
|
||||
.thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
when(mockBaseProvider.fetch(tExerciseInfoUri2))
|
||||
.thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
when(
|
||||
mockBaseProvider.fetch(tExerciseInfoUri),
|
||||
).thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
when(
|
||||
mockBaseProvider.fetch(tExerciseInfoUri2),
|
||||
).thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
});
|
||||
|
||||
group('Correctly loads and parses data from the server', () {
|
||||
|
||||
@@ -106,30 +106,36 @@ void main() {
|
||||
|
||||
// Mock categories
|
||||
when(mockBaseProvider.makeUrl(categoryUrl)).thenReturn(tCategoryEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tCategoryEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tCategoryMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tCategoryEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tCategoryMap['results']));
|
||||
|
||||
// Mock muscles
|
||||
when(mockBaseProvider.makeUrl(muscleUrl)).thenReturn(tMuscleEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tMuscleEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tMuscleMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tMuscleEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tMuscleMap['results']));
|
||||
|
||||
// Mock equipment
|
||||
when(mockBaseProvider.makeUrl(equipmentUrl)).thenReturn(tEquipmentEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tEquipmentEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tEquipmentMap['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tEquipmentEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tEquipmentMap['results']));
|
||||
|
||||
// Mock languages
|
||||
when(mockBaseProvider.makeUrl(languageUrl, query: anyNamed('query')))
|
||||
.thenReturn(tLanguageEntriesUri);
|
||||
when(mockBaseProvider.fetchPaginated(tLanguageEntriesUri))
|
||||
.thenAnswer((_) => Future.value(tLanguageMap['results']));
|
||||
when(
|
||||
mockBaseProvider.makeUrl(languageUrl, query: anyNamed('query')),
|
||||
).thenReturn(tLanguageEntriesUri);
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(tLanguageEntriesUri),
|
||||
).thenAnswer((_) => Future.value(tLanguageMap['results']));
|
||||
|
||||
// Mock base info response
|
||||
when(mockBaseProvider.makeUrl(exerciseInfoUrl, id: 1)).thenReturn(tExerciseInfoUri);
|
||||
when(mockBaseProvider.makeUrl(exerciseInfoUrl, id: 2)).thenReturn(tExerciseInfoUri);
|
||||
when(mockBaseProvider.fetch(tExerciseInfoUri))
|
||||
.thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
when(
|
||||
mockBaseProvider.fetch(tExerciseInfoUri),
|
||||
).thenAnswer((_) => Future.value(tExerciseInfoMap));
|
||||
});
|
||||
|
||||
group('findCategoryById()', () {
|
||||
|
||||
@@ -33,9 +33,9 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
@@ -43,9 +43,9 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
@@ -53,9 +53,9 @@ class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
@@ -63,9 +63,9 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [GalleryProvider].
|
||||
@@ -77,80 +77,90 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i5.Image> get images => (super.noSuchMethod(
|
||||
Invocation.getter(#images),
|
||||
returnValue: <_i5.Image>[],
|
||||
) as List<_i5.Image>);
|
||||
List<_i5.Image> get images =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#images),
|
||||
returnValue: <_i5.Image>[],
|
||||
)
|
||||
as List<_i5.Image>);
|
||||
|
||||
@override
|
||||
set images(List<_i5.Image>? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#images,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#images,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
_i2.AuthProvider get auth =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
)
|
||||
as _i2.AuthProvider);
|
||||
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
_i3.Client get client =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
)
|
||||
as _i3.Client);
|
||||
|
||||
@override
|
||||
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set client(_i3.Client? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i6.Future<void> fetchAndSetGallery() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetGallery,
|
||||
[],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
_i6.Future<void> fetchAndSetGallery() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetGallery,
|
||||
[],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> addImage(
|
||||
@@ -158,16 +168,17 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
_i7.XFile? imageFile,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
Invocation.method(
|
||||
#addImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> editImage(
|
||||
@@ -175,36 +186,41 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
_i7.XFile? imageFile,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
Invocation.method(
|
||||
#editImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> deleteImage(_i5.Image? image) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteImage,
|
||||
[image],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
_i6.Future<void> deleteImage(_i5.Image? image) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteImage,
|
||||
[image],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
)
|
||||
as Map<String, String>);
|
||||
|
||||
@override
|
||||
Uri makeUrl(
|
||||
@@ -214,46 +230,51 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
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);
|
||||
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
|
||||
_i6.Future<dynamic> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<dynamic>.value(),
|
||||
) as _i6.Future<dynamic>);
|
||||
_i6.Future<dynamic> fetch(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<dynamic>.value(),
|
||||
)
|
||||
as _i6.Future<dynamic>);
|
||||
|
||||
@override
|
||||
_i6.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i6.Future<List<dynamic>>);
|
||||
_i6.Future<List<dynamic>> fetchPaginated(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
)
|
||||
as _i6.Future<List<dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> post(
|
||||
@@ -261,15 +282,16 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i6.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> patch(
|
||||
@@ -277,15 +299,16 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i6.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<_i3.Response> deleteRequest(
|
||||
@@ -293,58 +316,61 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i6.Future<_i3.Response>);
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<_i3.Response>.value(
|
||||
_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i6.Future<_i3.Response>);
|
||||
|
||||
@override
|
||||
void addListener(_i8.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void removeListener(_i8.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
@@ -30,18 +30,22 @@ void main() {
|
||||
test('Test that fetch and set gallery', () async {
|
||||
final client = MockClient();
|
||||
|
||||
when(client.get(
|
||||
Uri.https('localhost', 'api/v2/gallery/'),
|
||||
headers: anyNamed('headers'),
|
||||
)).thenAnswer((_) async => http.Response(
|
||||
'{"count":1,"next":null,"previous":null,"results":['
|
||||
'{"id":58,'
|
||||
'"date":"2022-01-09",'
|
||||
'"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",'
|
||||
'"description":"eggsaddjujuit\'ddayhadIforcanview",'
|
||||
'"height":1280,"width":960}]}',
|
||||
200,
|
||||
));
|
||||
when(
|
||||
client.get(
|
||||
Uri.https('localhost', 'api/v2/gallery/'),
|
||||
headers: anyNamed('headers'),
|
||||
),
|
||||
).thenAnswer(
|
||||
(_) async => http.Response(
|
||||
'{"count":1,"next":null,"previous":null,"results":['
|
||||
'{"id":58,'
|
||||
'"date":"2022-01-09",'
|
||||
'"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",'
|
||||
'"description":"eggsaddjujuit\'ddayhadIforcanview",'
|
||||
'"height":1280,"width":960}]}',
|
||||
200,
|
||||
),
|
||||
);
|
||||
|
||||
final galleryProvider = GalleryProvider(testAuthProvider, [], client);
|
||||
|
||||
@@ -54,17 +58,21 @@ void main() {
|
||||
test('Test that delete gallery photo', () async {
|
||||
final client = MockClient();
|
||||
|
||||
when(client.delete(
|
||||
Uri.https('localhost', 'api/v2/gallery/58/'),
|
||||
headers: anyNamed('headers'),
|
||||
)).thenAnswer((_) async => http.Response(
|
||||
'{"id":58,'
|
||||
'"date":"2022-01-09",'
|
||||
'"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",'
|
||||
'"description":"eggsaddjujuit\'ddayhadIforcanview",'
|
||||
'"height":1280,"width":960}',
|
||||
200,
|
||||
));
|
||||
when(
|
||||
client.delete(
|
||||
Uri.https('localhost', 'api/v2/gallery/58/'),
|
||||
headers: anyNamed('headers'),
|
||||
),
|
||||
).thenAnswer(
|
||||
(_) async => http.Response(
|
||||
'{"id":58,'
|
||||
'"date":"2022-01-09",'
|
||||
'"image":"https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg",'
|
||||
'"description":"eggsaddjujuit\'ddayhadIforcanview",'
|
||||
'"height":1280,"width":960}',
|
||||
200,
|
||||
),
|
||||
);
|
||||
|
||||
final galleryProvider = GalleryProvider(testAuthProvider, [], client);
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
@@ -43,9 +43,9 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
@@ -53,9 +53,9 @@ class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
@@ -63,9 +63,9 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [GalleryProvider].
|
||||
@@ -77,80 +77,90 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i5.Image> get images => (super.noSuchMethod(
|
||||
Invocation.getter(#images),
|
||||
returnValue: <_i5.Image>[],
|
||||
) as List<_i5.Image>);
|
||||
List<_i5.Image> get images =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#images),
|
||||
returnValue: <_i5.Image>[],
|
||||
)
|
||||
as List<_i5.Image>);
|
||||
|
||||
@override
|
||||
set images(List<_i5.Image>? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#images,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#images,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
_i2.AuthProvider get auth =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
)
|
||||
as _i2.AuthProvider);
|
||||
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
_i3.Client get client =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
)
|
||||
as _i3.Client);
|
||||
|
||||
@override
|
||||
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set client(_i3.Client? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i6.Future<void> fetchAndSetGallery() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetGallery,
|
||||
[],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
_i6.Future<void> fetchAndSetGallery() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetGallery,
|
||||
[],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> addImage(
|
||||
@@ -158,16 +168,17 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
_i7.XFile? imageFile,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
Invocation.method(
|
||||
#addImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> editImage(
|
||||
@@ -175,36 +186,41 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
_i7.XFile? imageFile,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
Invocation.method(
|
||||
#editImage,
|
||||
[
|
||||
image,
|
||||
imageFile,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
_i6.Future<void> deleteImage(_i5.Image? image) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteImage,
|
||||
[image],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
) as _i6.Future<void>);
|
||||
_i6.Future<void> deleteImage(_i5.Image? image) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteImage,
|
||||
[image],
|
||||
),
|
||||
returnValue: _i6.Future<void>.value(),
|
||||
returnValueForMissingStub: _i6.Future<void>.value(),
|
||||
)
|
||||
as _i6.Future<void>);
|
||||
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
)
|
||||
as Map<String, String>);
|
||||
|
||||
@override
|
||||
Uri makeUrl(
|
||||
@@ -214,46 +230,51 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
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);
|
||||
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
|
||||
_i6.Future<dynamic> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<dynamic>.value(),
|
||||
) as _i6.Future<dynamic>);
|
||||
_i6.Future<dynamic> fetch(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<dynamic>.value(),
|
||||
)
|
||||
as _i6.Future<dynamic>);
|
||||
|
||||
@override
|
||||
_i6.Future<List<dynamic>> fetchPaginated(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
) as _i6.Future<List<dynamic>>);
|
||||
_i6.Future<List<dynamic>> fetchPaginated(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchPaginated,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i6.Future<List<dynamic>>.value(<dynamic>[]),
|
||||
)
|
||||
as _i6.Future<List<dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> post(
|
||||
@@ -261,15 +282,16 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i6.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<Map<String, dynamic>> patch(
|
||||
@@ -277,15 +299,16 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i6.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i6.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i6.Future<_i3.Response> deleteRequest(
|
||||
@@ -293,58 +316,61 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i6.Future<_i3.Response>);
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i6.Future<_i3.Response>.value(
|
||||
_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i6.Future<_i3.Response>);
|
||||
|
||||
@override
|
||||
void addListener(_i8.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void removeListener(_i8.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
@@ -37,14 +37,24 @@ void main() {
|
||||
setUp(() {
|
||||
mockMeasurementProvider = MockMeasurementProvider();
|
||||
when(mockMeasurementProvider.categories).thenReturn([
|
||||
MeasurementCategory(id: 1, name: 'body fat', unit: '%', entries: [
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 9, 1), value: 10, notes: ''),
|
||||
MeasurementEntry(id: 2, category: 1, date: DateTime(2021, 9, 5), value: 11, notes: ''),
|
||||
]),
|
||||
MeasurementCategory(id: 2, name: 'biceps', unit: 'cm', entries: [
|
||||
MeasurementEntry(id: 3, category: 2, date: DateTime(2021, 9, 1), value: 30, notes: ''),
|
||||
MeasurementEntry(id: 4, category: 2, date: DateTime(2021, 9, 5), value: 40, notes: ''),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'body fat',
|
||||
unit: '%',
|
||||
entries: [
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 9, 1), value: 10, notes: ''),
|
||||
MeasurementEntry(id: 2, category: 1, date: DateTime(2021, 9, 5), value: 11, notes: ''),
|
||||
],
|
||||
),
|
||||
MeasurementCategory(
|
||||
id: 2,
|
||||
name: 'biceps',
|
||||
unit: 'cm',
|
||||
entries: [
|
||||
MeasurementEntry(id: 3, category: 2, date: DateTime(2021, 9, 1), value: 30, notes: ''),
|
||||
MeasurementEntry(id: 4, category: 2, date: DateTime(2021, 9, 5), value: 40, notes: ''),
|
||||
],
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvi
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMeasurementCategory_1 extends _i1.SmartFake implements _i3.MeasurementCategory {
|
||||
@@ -42,9 +42,9 @@ class _FakeMeasurementCategory_1 extends _i1.SmartFake implements _i3.Measuremen
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [MeasurementProvider].
|
||||
@@ -56,99 +56,117 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
_i2.WgerBaseProvider get baseProvider =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
)
|
||||
as _i2.WgerBaseProvider);
|
||||
|
||||
@override
|
||||
List<_i3.MeasurementCategory> get categories => (super.noSuchMethod(
|
||||
Invocation.getter(#categories),
|
||||
returnValue: <_i3.MeasurementCategory>[],
|
||||
) as List<_i3.MeasurementCategory>);
|
||||
List<_i3.MeasurementCategory> get categories =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#categories),
|
||||
returnValue: <_i3.MeasurementCategory>[],
|
||||
)
|
||||
as List<_i3.MeasurementCategory>);
|
||||
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i3.MeasurementCategory findCategoryById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findCategoryById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeMeasurementCategory_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findCategoryById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i3.MeasurementCategory);
|
||||
_i3.MeasurementCategory findCategoryById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findCategoryById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeMeasurementCategory_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findCategoryById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.MeasurementCategory);
|
||||
|
||||
@override
|
||||
_i5.Future<void> fetchAndSetCategories() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetCategories,
|
||||
[],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> fetchAndSetCategories() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetCategories,
|
||||
[],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> fetchAndSetCategoryEntries(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetCategoryEntries,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> fetchAndSetCategoryEntries(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetCategoryEntries,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> fetchAndSetAllCategoriesAndEntries() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllCategoriesAndEntries,
|
||||
[],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> fetchAndSetAllCategoriesAndEntries() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllCategoriesAndEntries,
|
||||
[],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> addCategory(_i3.MeasurementCategory? category) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addCategory,
|
||||
[category],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> addCategory(_i3.MeasurementCategory? category) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addCategory,
|
||||
[category],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> deleteCategory(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteCategory,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> deleteCategory(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteCategory,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> editCategory(
|
||||
@@ -157,27 +175,30 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide
|
||||
String? newUnit,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editCategory,
|
||||
[
|
||||
id,
|
||||
newName,
|
||||
newUnit,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
Invocation.method(
|
||||
#editCategory,
|
||||
[
|
||||
id,
|
||||
newName,
|
||||
newUnit,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> addEntry(_i6.MeasurementEntry? entry) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addEntry,
|
||||
[entry],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
_i5.Future<void> addEntry(_i6.MeasurementEntry? entry) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addEntry,
|
||||
[entry],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> deleteEntry(
|
||||
@@ -185,16 +206,17 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide
|
||||
int? categoryId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteEntry,
|
||||
[
|
||||
id,
|
||||
categoryId,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
Invocation.method(
|
||||
#deleteEntry,
|
||||
[
|
||||
id,
|
||||
categoryId,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
_i5.Future<void> editEntry(
|
||||
@@ -205,53 +227,54 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide
|
||||
DateTime? newDate,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editEntry,
|
||||
[
|
||||
id,
|
||||
categoryId,
|
||||
newValue,
|
||||
newNotes,
|
||||
newDate,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
) as _i5.Future<void>);
|
||||
Invocation.method(
|
||||
#editEntry,
|
||||
[
|
||||
id,
|
||||
categoryId,
|
||||
newValue,
|
||||
newNotes,
|
||||
newDate,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<void>.value(),
|
||||
returnValueForMissingStub: _i5.Future<void>.value(),
|
||||
)
|
||||
as _i5.Future<void>);
|
||||
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
@@ -37,10 +37,21 @@ void main() {
|
||||
setUp(() {
|
||||
mockMeasurementProvider = MockMeasurementProvider();
|
||||
when(mockMeasurementProvider.findCategoryById(any)).thenReturn(
|
||||
MeasurementCategory(id: 1, name: 'body fat', unit: '%', entries: [
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 8, 1), value: 10.2, notes: ''),
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 8, 10), value: 18.1, notes: 'a'),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'body fat',
|
||||
unit: '%',
|
||||
entries: [
|
||||
MeasurementEntry(id: 1, category: 1, date: DateTime(2021, 8, 1), value: 10.2, notes: ''),
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 8, 10),
|
||||
value: 18.1,
|
||||
notes: 'a',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
mockNutritionPlansProvider = MockNutritionPlansProvider();
|
||||
|
||||
@@ -23,8 +23,9 @@ void main() {
|
||||
const String categoryUrl = 'measurement-category';
|
||||
const String entryUrl = 'measurement';
|
||||
final Uri tCategoryUri = Uri();
|
||||
final Map<String, dynamic> tMeasurementCategoryMap =
|
||||
jsonDecode(fixture('measurement/measurement_category_entries.json'));
|
||||
final Map<String, dynamic> tMeasurementCategoryMap = jsonDecode(
|
||||
fixture('measurement/measurement_category_entries.json'),
|
||||
);
|
||||
final Uri tCategoryEntriesUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'tedmosbyisajerk.com',
|
||||
@@ -33,31 +34,40 @@ void main() {
|
||||
);
|
||||
|
||||
const int tCategoryId = 1;
|
||||
const MeasurementCategory tMeasurementCategory =
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN');
|
||||
const MeasurementCategory tMeasurementCategory = MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
);
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
const MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
final Map<String, dynamic> tMeasurementCategoriesMap =
|
||||
jsonDecode(fixture('measurement/measurement_categories.json'));
|
||||
final Map<String, dynamic> tMeasurementCategoriesMap = jsonDecode(
|
||||
fixture('measurement/measurement_categories.json'),
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
measurementProvider = MeasurementProvider(mockWgerBaseProvider);
|
||||
|
||||
when(mockWgerBaseProvider.makeUrl(any)).thenReturn(tCategoryUri);
|
||||
when(mockWgerBaseProvider.makeUrl(any, id: anyNamed('id'), query: anyNamed('query')))
|
||||
.thenReturn(tCategoryUri);
|
||||
when(mockWgerBaseProvider.fetchPaginated(any))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoriesMap['results']));
|
||||
when(
|
||||
mockWgerBaseProvider.makeUrl(any, id: anyNamed('id'), query: anyNamed('query')),
|
||||
).thenReturn(tCategoryUri);
|
||||
when(
|
||||
mockWgerBaseProvider.fetchPaginated(any),
|
||||
).thenAnswer((realInvocation) => Future.value(tMeasurementCategoriesMap['results']));
|
||||
|
||||
when(mockWgerBaseProvider.makeUrl(entryUrl, query: anyNamed('query')))
|
||||
.thenReturn(tCategoryEntriesUri);
|
||||
when(mockWgerBaseProvider.makeUrl(entryUrl, id: anyNamed('id'), query: anyNamed('query')))
|
||||
.thenReturn(tCategoryEntriesUri);
|
||||
when(mockWgerBaseProvider.fetchPaginated(tCategoryEntriesUri))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap['results']));
|
||||
when(
|
||||
mockWgerBaseProvider.makeUrl(entryUrl, query: anyNamed('query')),
|
||||
).thenReturn(tCategoryEntriesUri);
|
||||
when(
|
||||
mockWgerBaseProvider.makeUrl(entryUrl, id: anyNamed('id'), query: anyNamed('query')),
|
||||
).thenReturn(tCategoryEntriesUri);
|
||||
when(
|
||||
mockWgerBaseProvider.fetchPaginated(tCategoryEntriesUri),
|
||||
).thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap['results']));
|
||||
});
|
||||
|
||||
group('clear()', () {
|
||||
@@ -130,10 +140,12 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategoryEntries(tCategoryId);
|
||||
|
||||
// assert
|
||||
verify(mockWgerBaseProvider.makeUrl(
|
||||
entryUrl,
|
||||
query: {'category': tCategoryId.toString(), 'limit': API_MAX_PAGE_SIZE},
|
||||
));
|
||||
verify(
|
||||
mockWgerBaseProvider.makeUrl(
|
||||
entryUrl,
|
||||
query: {'category': tCategoryId.toString(), 'limit': API_MAX_PAGE_SIZE},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('should fetch categories entries for id', () async {
|
||||
@@ -147,22 +159,27 @@ void main() {
|
||||
test('should add entries to category in list', () async {
|
||||
// arrange
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
],
|
||||
),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
|
||||
@@ -175,20 +192,26 @@ void main() {
|
||||
});
|
||||
|
||||
group('addCategory()', () {
|
||||
const MeasurementCategory tMeasurementCategoryWithoutId =
|
||||
MeasurementCategory(id: null, name: 'Strength', unit: 'kN');
|
||||
final Map<String, dynamic> tMeasurementCategoryMap =
|
||||
jsonDecode(fixture('measurement/measurement_category.json'));
|
||||
final Map<String, dynamic> tMeasurementCategoryMapWithoutId =
|
||||
jsonDecode(fixture('measurement/measurement_category_without_id_to_json.json'));
|
||||
const MeasurementCategory tMeasurementCategoryWithoutId = MeasurementCategory(
|
||||
id: null,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
);
|
||||
final Map<String, dynamic> tMeasurementCategoryMap = jsonDecode(
|
||||
fixture('measurement/measurement_category.json'),
|
||||
);
|
||||
final Map<String, dynamic> tMeasurementCategoryMapWithoutId = jsonDecode(
|
||||
fixture('measurement/measurement_category_without_id_to_json.json'),
|
||||
);
|
||||
final List<MeasurementCategory> tMeasurementCategoriesAdded = [
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
const MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
const MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
];
|
||||
setUp(() {
|
||||
when(mockWgerBaseProvider.post(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap));
|
||||
when(
|
||||
mockWgerBaseProvider.post(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap));
|
||||
});
|
||||
|
||||
test("should post the MeasurementCategorie's Map", () async {
|
||||
@@ -222,8 +245,9 @@ void main() {
|
||||
'should remove a MeasurementCategory from the categories list for an id and call the api to remove the MeasurementCategory',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockWgerBaseProvider.deleteRequest(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
when(
|
||||
mockWgerBaseProvider.deleteRequest(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
|
||||
final List<MeasurementCategory> tMeasurementCategoriesOneDeleted = [
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
@@ -262,13 +286,16 @@ void main() {
|
||||
group('editCategory()', () {
|
||||
const String tCategoryEditedName = 'Triceps';
|
||||
const String tCategoryEditedUnit = 'm';
|
||||
final Map<String, dynamic> tCategoryMapEditedToJson =
|
||||
jsonDecode(fixture('measurement/measurement_category_edited_to_json.json'));
|
||||
final Map<String, dynamic> tCategoryMapEdited =
|
||||
jsonDecode(fixture('measurement/measurement_category_edited.json'));
|
||||
final Map<String, dynamic> tCategoryMapEditedToJson = jsonDecode(
|
||||
fixture('measurement/measurement_category_edited_to_json.json'),
|
||||
);
|
||||
final Map<String, dynamic> tCategoryMapEdited = jsonDecode(
|
||||
fixture('measurement/measurement_category_edited.json'),
|
||||
);
|
||||
setUp(() async {
|
||||
when(mockWgerBaseProvider.patch(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(tCategoryMapEdited));
|
||||
when(
|
||||
mockWgerBaseProvider.patch(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(tCategoryMapEdited));
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
});
|
||||
test('should add the new MeasurementCategory and remove the old one', () async {
|
||||
@@ -336,33 +363,40 @@ void main() {
|
||||
);
|
||||
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
tMeasurementEntry,
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
tMeasurementEntry,
|
||||
],
|
||||
),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
|
||||
setUp(() async {
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
|
||||
final Map<String, dynamic> measurementEntryMap =
|
||||
jsonDecode(fixture('measurement/measurement_entry.json'));
|
||||
when(mockWgerBaseProvider.post(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(measurementEntryMap));
|
||||
final Map<String, dynamic> measurementEntryMap = jsonDecode(
|
||||
fixture('measurement/measurement_entry.json'),
|
||||
);
|
||||
when(
|
||||
mockWgerBaseProvider.post(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(measurementEntryMap));
|
||||
});
|
||||
|
||||
test('should make the post url', () async {
|
||||
@@ -375,8 +409,9 @@ void main() {
|
||||
|
||||
test('should post the MeasurementEntryMap', () async {
|
||||
// arrange
|
||||
final Map<String, dynamic> measurementEntryMapWithoutId =
|
||||
jsonDecode(fixture('measurement/measurement_entry_without_id.json'));
|
||||
final Map<String, dynamic> measurementEntryMapWithoutId = jsonDecode(
|
||||
fixture('measurement/measurement_entry_without_id.json'),
|
||||
);
|
||||
|
||||
// act
|
||||
await measurementProvider.addEntry(tMeasurementEntryWithoutId);
|
||||
@@ -408,10 +443,12 @@ void main() {
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
);
|
||||
final Map<String, dynamic> measurementEntryMapWrongCategory =
|
||||
jsonDecode(fixture('measurement/measurement_entry_wrong_category.json'));
|
||||
when(mockWgerBaseProvider.post(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(measurementEntryMapWrongCategory));
|
||||
final Map<String, dynamic> measurementEntryMapWrongCategory = jsonDecode(
|
||||
fixture('measurement/measurement_entry_wrong_category.json'),
|
||||
);
|
||||
when(
|
||||
mockWgerBaseProvider.post(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(measurementEntryMapWrongCategory));
|
||||
|
||||
// act & assert
|
||||
expect(
|
||||
@@ -424,15 +461,20 @@ void main() {
|
||||
group('deleteEntry()', () {
|
||||
const int tEntryId = 2;
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
],
|
||||
),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
|
||||
@@ -440,8 +482,9 @@ void main() {
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
await measurementProvider.fetchAndSetCategoryEntries(tCategoryId);
|
||||
|
||||
when(mockWgerBaseProvider.deleteRequest(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
when(
|
||||
mockWgerBaseProvider.deleteRequest(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
});
|
||||
|
||||
test("should remove a MeasurementEntry from the category's entries List for an id", () async {
|
||||
@@ -484,22 +527,27 @@ void main() {
|
||||
() {
|
||||
// arrange
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 10,
|
||||
notes: 'Some important notes',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
],
|
||||
),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
when(mockWgerBaseProvider.deleteRequest(any, any)).thenThrow(WgerHttpException('{}'));
|
||||
@@ -525,33 +573,40 @@ void main() {
|
||||
const num tEntryEditedValue = 23;
|
||||
final DateTime tEntryEditedDate = DateTime(2021, 07, 21);
|
||||
const String tEntryEditedNote = 'I just wanted to edit this to see what happens';
|
||||
final Map<String, dynamic> tEntryMapEdited =
|
||||
jsonDecode(fixture('measurement/measurement_entry_edited.json'));
|
||||
final Map<String, dynamic> tEntryMapEdited = jsonDecode(
|
||||
fixture('measurement/measurement_entry_edited.json'),
|
||||
);
|
||||
setUp(() async {
|
||||
when(mockWgerBaseProvider.patch(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(tEntryMapEdited));
|
||||
when(
|
||||
mockWgerBaseProvider.patch(any, any),
|
||||
).thenAnswer((realInvocation) => Future.value(tEntryMapEdited));
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
await measurementProvider.fetchAndSetCategoryEntries(1);
|
||||
});
|
||||
test('should add the new MeasurementEntry and remove the old one', () async {
|
||||
// arrange
|
||||
final List<MeasurementCategory> tMeasurementCategoriesEdited = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 23,
|
||||
notes: 'I just wanted to edit this to see what happens',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
]),
|
||||
MeasurementCategory(
|
||||
id: 1,
|
||||
name: 'Strength',
|
||||
unit: 'kN',
|
||||
entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 21),
|
||||
value: 23,
|
||||
notes: 'I just wanted to edit this to see what happens',
|
||||
),
|
||||
MeasurementEntry(
|
||||
id: 2,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 10),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
),
|
||||
],
|
||||
),
|
||||
const MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
@@ -40,9 +40,9 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
@@ -50,9 +50,9 @@ class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
@@ -60,9 +60,9 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [WgerBaseProvider].
|
||||
@@ -74,50 +74,56 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
_i2.AuthProvider get auth =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
)
|
||||
as _i2.AuthProvider);
|
||||
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
_i3.Client get client =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
)
|
||||
as _i3.Client);
|
||||
|
||||
@override
|
||||
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set client(_i3.Client? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
)
|
||||
as Map<String, String>);
|
||||
|
||||
@override
|
||||
Uri makeUrl(
|
||||
@@ -127,46 +133,51 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
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);
|
||||
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<dynamic> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<dynamic>.value(),
|
||||
) as _i5.Future<dynamic>);
|
||||
_i5.Future<dynamic> fetch(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<dynamic>.value(),
|
||||
)
|
||||
as _i5.Future<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>>);
|
||||
_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(
|
||||
@@ -174,15 +185,16 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
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(
|
||||
@@ -190,15 +202,16 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i5.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i5.Future<_i3.Response> deleteRequest(
|
||||
@@ -206,22 +219,25 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<_i3.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i5.Future<_i3.Response>);
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<_i3.Response>.value(
|
||||
_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i5.Future<_i3.Response>);
|
||||
}
|
||||
@@ -82,8 +82,9 @@ void main() {
|
||||
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.makeUrl(ingredientInfoUrl, id: anyNamed('id')))
|
||||
.thenReturn(ingredientUri);
|
||||
when(
|
||||
mockWgerBaseProvider.makeUrl(ingredientInfoUrl, id: anyNamed('id')),
|
||||
).thenReturn(ingredientUri);
|
||||
when(mockWgerBaseProvider.fetch(planInfoUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(nutritionalPlanInfoResponse),
|
||||
);
|
||||
@@ -140,8 +141,10 @@ void main() {
|
||||
endDate: now.add(const Duration(days: 5)),
|
||||
creationDate: now.subtract(const Duration(days: 2)),
|
||||
);
|
||||
nutritionProvider =
|
||||
NutritionPlansProvider(mockWgerBaseProvider, [olderPlan, newerPlan], database: database);
|
||||
nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, [
|
||||
olderPlan,
|
||||
newerPlan,
|
||||
], database: database);
|
||||
expect(nutritionProvider.currentPlan, equals(newerPlan));
|
||||
});
|
||||
});
|
||||
@@ -192,8 +195,10 @@ void main() {
|
||||
startDate: now.subtract(const Duration(days: 10)),
|
||||
endDate: now.add(const Duration(days: 10)),
|
||||
);
|
||||
nutritionProvider =
|
||||
NutritionPlansProvider(mockWgerBaseProvider, [plan, inactivePlan], database: database);
|
||||
nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, [
|
||||
plan,
|
||||
inactivePlan,
|
||||
], database: database);
|
||||
expect(nutritionProvider.currentPlan, equals(plan));
|
||||
});
|
||||
|
||||
@@ -208,8 +213,10 @@ void main() {
|
||||
startDate: now.subtract(const Duration(days: 5)),
|
||||
endDate: now.add(const Duration(days: 5)),
|
||||
);
|
||||
nutritionProvider =
|
||||
NutritionPlansProvider(mockWgerBaseProvider, [olderPlan, newerPlan], database: database);
|
||||
nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, [
|
||||
olderPlan,
|
||||
newerPlan,
|
||||
], database: database);
|
||||
expect(nutritionProvider.currentPlan, equals(newerPlan));
|
||||
});
|
||||
});
|
||||
@@ -218,7 +225,9 @@ void main() {
|
||||
test('that if there is already valid data in the DB, the API is not hit', () async {
|
||||
// Arrange
|
||||
nutritionProvider.ingredients = [];
|
||||
await database.into(database.ingredients).insert(
|
||||
await database
|
||||
.into(database.ingredients)
|
||||
.insert(
|
||||
IngredientsCompanion.insert(
|
||||
id: ingredient59887Response['id'],
|
||||
data: json.encode(ingredient59887Response),
|
||||
@@ -239,7 +248,9 @@ void main() {
|
||||
test('fetching an ingredient not present in the DB, the API is hit', () async {
|
||||
// Arrange
|
||||
nutritionProvider.ingredients = [];
|
||||
await database.into(database.ingredients).insert(
|
||||
await database
|
||||
.into(database.ingredients)
|
||||
.insert(
|
||||
IngredientsCompanion.insert(
|
||||
id: ingredient59887Response['id'],
|
||||
data: json.encode(ingredient59887Response),
|
||||
|
||||
@@ -35,9 +35,9 @@ class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvi
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredientDatabase_1 extends _i1.SmartFake implements _i3.IngredientDatabase {
|
||||
@@ -45,9 +45,9 @@ class _FakeIngredientDatabase_1 extends _i1.SmartFake implements _i3.IngredientD
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan {
|
||||
@@ -55,9 +55,9 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
@@ -65,9 +65,9 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
@@ -75,9 +75,9 @@ class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
@@ -85,9 +85,9 @@ class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [NutritionPlansProvider].
|
||||
@@ -99,173 +99,209 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
_i2.WgerBaseProvider get baseProvider =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
)
|
||||
as _i2.WgerBaseProvider);
|
||||
|
||||
@override
|
||||
_i3.IngredientDatabase get database => (super.noSuchMethod(
|
||||
Invocation.getter(#database),
|
||||
returnValue: _FakeIngredientDatabase_1(
|
||||
this,
|
||||
Invocation.getter(#database),
|
||||
),
|
||||
) as _i3.IngredientDatabase);
|
||||
_i3.IngredientDatabase get database =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#database),
|
||||
returnValue: _FakeIngredientDatabase_1(
|
||||
this,
|
||||
Invocation.getter(#database),
|
||||
),
|
||||
)
|
||||
as _i3.IngredientDatabase);
|
||||
|
||||
@override
|
||||
List<_i7.Ingredient> get ingredients => (super.noSuchMethod(
|
||||
Invocation.getter(#ingredients),
|
||||
returnValue: <_i7.Ingredient>[],
|
||||
) as List<_i7.Ingredient>);
|
||||
List<_i7.Ingredient> get ingredients =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#ingredients),
|
||||
returnValue: <_i7.Ingredient>[],
|
||||
)
|
||||
as List<_i7.Ingredient>);
|
||||
|
||||
@override
|
||||
List<_i4.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
) as List<_i4.NutritionalPlan>);
|
||||
List<_i4.NutritionalPlan> get items =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
)
|
||||
as List<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
set database(_i3.IngredientDatabase? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#database,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#database,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set ingredients(List<_i7.Ingredient>? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#ingredients,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#ingredients,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i4.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i4.NutritionalPlan);
|
||||
_i4.NutritionalPlan findById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i4.NutritionalPlan);
|
||||
|
||||
@override
|
||||
_i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
)) as _i5.Meal?);
|
||||
_i5.Meal? findMealById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
),
|
||||
)
|
||||
as _i5.Meal?);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.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>);
|
||||
_i9.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>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i5.Meal> addMeal(
|
||||
@@ -273,49 +309,58 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(
|
||||
_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i5.Meal>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(
|
||||
_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i5.Meal>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i6.MealItem> addMealItem(
|
||||
@@ -323,44 +368,51 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
_i5.Meal? meal,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i6.MealItem>);
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(
|
||||
_FakeMealItem_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i6.MealItem>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> clearIngredientCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clearIngredientCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> clearIngredientCache() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clearIngredientCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient> fetchIngredient(
|
||||
@@ -368,30 +420,35 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
_i3.IngredientDatabase? database,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i7.Ingredient>);
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(
|
||||
_FakeIngredient_5(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i7.Ingredient>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchIngredientsFromCache() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<List<_i7.Ingredient>> searchIngredient(
|
||||
@@ -400,25 +457,28 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
bool? searchEnglish = false,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<_i7.Ingredient>>.value(<_i7.Ingredient>[]),
|
||||
) as _i9.Future<List<_i7.Ingredient>>);
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<_i7.Ingredient>>.value(<_i7.Ingredient>[]),
|
||||
)
|
||||
as _i9.Future<List<_i7.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithBarcode,
|
||||
[barcode],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
) as _i9.Future<_i7.Ingredient?>);
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithBarcode,
|
||||
[barcode],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
)
|
||||
as _i9.Future<_i7.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> logMealToDiary(
|
||||
@@ -426,16 +486,17 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
DateTime? mealDateTime,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[
|
||||
meal,
|
||||
mealDateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[
|
||||
meal,
|
||||
mealDateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> logIngredientToDiary(
|
||||
@@ -444,17 +505,18 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
DateTime? dateTime,
|
||||
]) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logIngredientToDiary,
|
||||
[
|
||||
mealItem,
|
||||
planId,
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#logIngredientToDiary,
|
||||
[
|
||||
mealItem,
|
||||
planId,
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteLog(
|
||||
@@ -462,60 +524,63 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteLog,
|
||||
[
|
||||
logId,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#deleteLog,
|
||||
[
|
||||
logId,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
@@ -70,15 +70,18 @@ void main() {
|
||||
final MealItem mealItem = MealItem(ingredientId: ingredient.id, amount: 2);
|
||||
mockNutrition = MockNutritionPlansProvider();
|
||||
|
||||
when(mockNutrition.searchIngredientWithBarcode('123'))
|
||||
.thenAnswer((_) => Future.value(ingredient));
|
||||
when(
|
||||
mockNutrition.searchIngredientWithBarcode('123'),
|
||||
).thenAnswer((_) => Future.value(ingredient));
|
||||
when(mockNutrition.searchIngredientWithBarcode('')).thenAnswer((_) => Future.value(null));
|
||||
when(mockNutrition.searchIngredientWithBarcode('222')).thenAnswer((_) => Future.value(null));
|
||||
when(mockNutrition.searchIngredient(
|
||||
any,
|
||||
languageCode: anyNamed('languageCode'),
|
||||
searchEnglish: anyNamed('searchEnglish'),
|
||||
)).thenAnswer(
|
||||
when(
|
||||
mockNutrition.searchIngredient(
|
||||
any,
|
||||
languageCode: anyNamed('languageCode'),
|
||||
searchEnglish: anyNamed('searchEnglish'),
|
||||
),
|
||||
).thenAnswer(
|
||||
(_) => Future.value([ingredient1, ingredient2]),
|
||||
);
|
||||
|
||||
@@ -311,9 +314,11 @@ void main() {
|
||||
await tester.enterText(find.byKey(const Key('field-weight')), '2');
|
||||
|
||||
// once ID and weight are set, it'll fetchIngredient and show macros preview and ingredient image
|
||||
when(mockNutrition.fetchIngredient(1)).thenAnswer((_) => Future.value(
|
||||
Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredientinfo_59887.json'))),
|
||||
));
|
||||
when(mockNutrition.fetchIngredient(1)).thenAnswer(
|
||||
(_) => Future.value(
|
||||
Ingredient.fromJson(jsonDecode(fixture('nutrition/ingredientinfo_59887.json'))),
|
||||
),
|
||||
);
|
||||
await mockNetworkImagesFor(() => tester.pumpAndSettle());
|
||||
|
||||
expect(find.byKey(const Key('ingredient-scan-result-dialog')), findsNothing);
|
||||
|
||||
@@ -110,8 +110,11 @@ void main() {
|
||||
await tester.pumpWidget(createHomeScreen(plan2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(''), findsNWidgets(2),
|
||||
reason: 'New nutritional plan needs description, and end date');
|
||||
expect(
|
||||
find.text(''),
|
||||
findsNWidgets(2),
|
||||
reason: 'New nutritional plan needs description, and end date',
|
||||
);
|
||||
// there's also the start date, but it will have a value depending on 'now'
|
||||
await tester.enterText(find.byKey(const Key('field-description')), 'New cool plan');
|
||||
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
|
||||
@@ -35,9 +35,9 @@ class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvi
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredientDatabase_1 extends _i1.SmartFake implements _i3.IngredientDatabase {
|
||||
@@ -45,9 +45,9 @@ class _FakeIngredientDatabase_1 extends _i1.SmartFake implements _i3.IngredientD
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan {
|
||||
@@ -55,9 +55,9 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
@@ -65,9 +65,9 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
@@ -75,9 +75,9 @@ class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
@@ -85,9 +85,9 @@ class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [NutritionPlansProvider].
|
||||
@@ -99,173 +99,209 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
) as _i2.WgerBaseProvider);
|
||||
_i2.WgerBaseProvider get baseProvider =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue: _FakeWgerBaseProvider_0(
|
||||
this,
|
||||
Invocation.getter(#baseProvider),
|
||||
),
|
||||
)
|
||||
as _i2.WgerBaseProvider);
|
||||
|
||||
@override
|
||||
_i3.IngredientDatabase get database => (super.noSuchMethod(
|
||||
Invocation.getter(#database),
|
||||
returnValue: _FakeIngredientDatabase_1(
|
||||
this,
|
||||
Invocation.getter(#database),
|
||||
),
|
||||
) as _i3.IngredientDatabase);
|
||||
_i3.IngredientDatabase get database =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#database),
|
||||
returnValue: _FakeIngredientDatabase_1(
|
||||
this,
|
||||
Invocation.getter(#database),
|
||||
),
|
||||
)
|
||||
as _i3.IngredientDatabase);
|
||||
|
||||
@override
|
||||
List<_i7.Ingredient> get ingredients => (super.noSuchMethod(
|
||||
Invocation.getter(#ingredients),
|
||||
returnValue: <_i7.Ingredient>[],
|
||||
) as List<_i7.Ingredient>);
|
||||
List<_i7.Ingredient> get ingredients =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#ingredients),
|
||||
returnValue: <_i7.Ingredient>[],
|
||||
)
|
||||
as List<_i7.Ingredient>);
|
||||
|
||||
@override
|
||||
List<_i4.NutritionalPlan> get items => (super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
) as List<_i4.NutritionalPlan>);
|
||||
List<_i4.NutritionalPlan> get items =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[],
|
||||
)
|
||||
as List<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
set database(_i3.IngredientDatabase? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#database,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#database,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set ingredients(List<_i7.Ingredient>? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#ingredients,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#ingredients,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get hasListeners => (super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
) as bool);
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#hasListeners),
|
||||
returnValue: false,
|
||||
)
|
||||
as bool);
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
_i4.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
) as _i4.NutritionalPlan);
|
||||
_i4.NutritionalPlan findById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
returnValue: _FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#findById,
|
||||
[id],
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i4.NutritionalPlan);
|
||||
|
||||
@override
|
||||
_i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
)) as _i5.Meal?);
|
||||
_i5.Meal? findMealById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#findMealById,
|
||||
[id],
|
||||
),
|
||||
)
|
||||
as _i5.Meal?);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansSparse,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetAllPlansFull,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanSparse,
|
||||
[planId],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchAndSetPlanFull,
|
||||
[planId],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i4.NutritionalPlan>);
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addPlan,
|
||||
[planData],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editPlan,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.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>);
|
||||
_i9.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>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i5.Meal> addMeal(
|
||||
@@ -273,49 +309,58 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(
|
||||
_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMeal,
|
||||
[
|
||||
meal,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i5.Meal>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i5.Meal>);
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(
|
||||
_FakeMeal_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#editMeal,
|
||||
[meal],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i5.Meal>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMeal,
|
||||
[meal],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i6.MealItem> addMealItem(
|
||||
@@ -323,44 +368,51 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
_i5.Meal? meal,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i6.MealItem>);
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(
|
||||
_FakeMealItem_4(
|
||||
this,
|
||||
Invocation.method(
|
||||
#addMealItem,
|
||||
[
|
||||
mealItem,
|
||||
meal,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i6.MealItem>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteMealItem,
|
||||
[mealItem],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> clearIngredientCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clearIngredientCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> clearIngredientCache() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clearIngredientCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient> fetchIngredient(
|
||||
@@ -368,30 +420,35 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
_i3.IngredientDatabase? database,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
)),
|
||||
) as _i9.Future<_i7.Ingredient>);
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(
|
||||
_FakeIngredient_5(
|
||||
this,
|
||||
Invocation.method(
|
||||
#fetchIngredient,
|
||||
[ingredientId],
|
||||
{#database: database},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i9.Future<_i7.Ingredient>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchIngredientsFromCache() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchIngredientsFromCache,
|
||||
[],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<List<_i7.Ingredient>> searchIngredient(
|
||||
@@ -400,25 +457,28 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
bool? searchEnglish = false,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<_i7.Ingredient>>.value(<_i7.Ingredient>[]),
|
||||
) as _i9.Future<List<_i7.Ingredient>>);
|
||||
Invocation.method(
|
||||
#searchIngredient,
|
||||
[name],
|
||||
{
|
||||
#languageCode: languageCode,
|
||||
#searchEnglish: searchEnglish,
|
||||
},
|
||||
),
|
||||
returnValue: _i9.Future<List<_i7.Ingredient>>.value(<_i7.Ingredient>[]),
|
||||
)
|
||||
as _i9.Future<List<_i7.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithBarcode,
|
||||
[barcode],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
) as _i9.Future<_i7.Ingredient?>);
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#searchIngredientWithBarcode,
|
||||
[barcode],
|
||||
),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value(),
|
||||
)
|
||||
as _i9.Future<_i7.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> logMealToDiary(
|
||||
@@ -426,16 +486,17 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
DateTime? mealDateTime,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[
|
||||
meal,
|
||||
mealDateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#logMealToDiary,
|
||||
[
|
||||
meal,
|
||||
mealDateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> logIngredientToDiary(
|
||||
@@ -444,17 +505,18 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
DateTime? dateTime,
|
||||
]) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logIngredientToDiary,
|
||||
[
|
||||
mealItem,
|
||||
planId,
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#logIngredientToDiary,
|
||||
[
|
||||
mealItem,
|
||||
planId,
|
||||
dateTime,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> deleteLog(
|
||||
@@ -462,60 +524,63 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
int? planId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteLog,
|
||||
[
|
||||
logId,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
Invocation.method(
|
||||
#deleteLog,
|
||||
[
|
||||
logId,
|
||||
planId,
|
||||
],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
) as _i9.Future<void>);
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetchAndSetLogs,
|
||||
[plan],
|
||||
),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value(),
|
||||
)
|
||||
as _i9.Future<void>);
|
||||
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#addListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#removeListener,
|
||||
[listener],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#dispose,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
void notifyListeners() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#notifyListeners,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -20,10 +20,8 @@ import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/database/ingredients/ingredients_database.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
@@ -56,8 +54,9 @@ void main() {
|
||||
});
|
||||
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
when(client.delete(any, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) async => http.Response('', 200));
|
||||
when(
|
||||
client.delete(any, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) async => http.Response('', 200));
|
||||
|
||||
when(mockBaseProvider.deleteRequest(any, any)).thenAnswer(
|
||||
(_) async => http.Response('', 200),
|
||||
@@ -93,15 +92,17 @@ void main() {
|
||||
create: (context) => BodyWeightProvider(mockBaseProvider),
|
||||
),
|
||||
ChangeNotifierProvider<UserProvider>(
|
||||
create: (context) => UserProvider(
|
||||
mockBaseProvider,
|
||||
)..profile = Profile(
|
||||
username: 'test',
|
||||
emailVerified: true,
|
||||
isTrustworthy: true,
|
||||
email: 'test@example.com',
|
||||
weightUnitStr: 'kg',
|
||||
),
|
||||
create: (context) =>
|
||||
UserProvider(
|
||||
mockBaseProvider,
|
||||
)
|
||||
..profile = Profile(
|
||||
username: 'test',
|
||||
emailVerified: true,
|
||||
isTrustworthy: true,
|
||||
email: 'test@example.com',
|
||||
weightUnitStr: 'kg',
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
@@ -151,14 +152,14 @@ void main() {
|
||||
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen());
|
||||
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
expect(find.textContaining('from 1/1/2021 ('), findsOneWidget);
|
||||
expect(find.textContaining('from 1/10/2021 ('), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createHomeScreen(locale: 'de'));
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
// note .. "(open ended)" at the time, depending on localisation strings
|
||||
|
||||
expect(find.textContaining('from 1.1.2021 ('), findsOneWidget);
|
||||
expect(find.textContaining('from 10.1.2021 ('), findsOneWidget);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -124,12 +124,15 @@ void main() {
|
||||
query: 'limit=20&offset=40',
|
||||
);
|
||||
|
||||
when(mockHttpClient.get(paginationUri1, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) => Future.value(response1));
|
||||
when(mockHttpClient.get(paginationUri2, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) => Future.value(response2));
|
||||
when(mockHttpClient.get(paginationUri3, headers: anyNamed('headers')))
|
||||
.thenAnswer((_) => Future.value(response3));
|
||||
when(
|
||||
mockHttpClient.get(paginationUri1, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) => Future.value(response1));
|
||||
when(
|
||||
mockHttpClient.get(paginationUri2, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) => Future.value(response2));
|
||||
when(
|
||||
mockHttpClient.get(paginationUri3, headers: anyNamed('headers')),
|
||||
).thenAnswer((_) => Future.value(response3));
|
||||
|
||||
// Act
|
||||
final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider, mockHttpClient);
|
||||
|
||||
@@ -31,9 +31,9 @@ class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeStreamedResponse_1 extends _i1.SmartFake implements _i2.StreamedResponse {
|
||||
@@ -41,9 +41,9 @@ class _FakeStreamedResponse_1 extends _i1.SmartFake implements _i2.StreamedRespo
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [Client].
|
||||
@@ -60,20 +60,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#head,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> get(
|
||||
@@ -81,20 +84,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#get,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> post(
|
||||
@@ -104,28 +110,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#post,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> put(
|
||||
@@ -135,28 +144,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#put,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> patch(
|
||||
@@ -166,28 +178,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.Response> delete(
|
||||
@@ -197,28 +212,31 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
_i4.Encoding? encoding,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.Response>);
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<_i2.Response>.value(
|
||||
_FakeResponse_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#delete,
|
||||
[url],
|
||||
{
|
||||
#headers: headers,
|
||||
#body: body,
|
||||
#encoding: encoding,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.Response>);
|
||||
|
||||
@override
|
||||
_i3.Future<String> read(
|
||||
@@ -226,20 +244,23 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<String>.value(_i5.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<String>);
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<String>.value(
|
||||
_i5.dummyValue<String>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#read,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<String>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i6.Uint8List> readBytes(
|
||||
@@ -247,35 +268,40 @@ class MockClient extends _i1.Mock implements _i2.Client {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#readBytes,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i6.Uint8List>.value(_i6.Uint8List(0)),
|
||||
) as _i3.Future<_i6.Uint8List>);
|
||||
Invocation.method(
|
||||
#readBytes,
|
||||
[url],
|
||||
{#headers: headers},
|
||||
),
|
||||
returnValue: _i3.Future<_i6.Uint8List>.value(_i6.Uint8List(0)),
|
||||
)
|
||||
as _i3.Future<_i6.Uint8List>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
returnValue: _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
)),
|
||||
) as _i3.Future<_i2.StreamedResponse>);
|
||||
_i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
returnValue: _i3.Future<_i2.StreamedResponse>.value(
|
||||
_FakeStreamedResponse_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#send,
|
||||
[request],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i3.Future<_i2.StreamedResponse>);
|
||||
|
||||
@override
|
||||
void close() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#close,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.method(
|
||||
#close,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
@@ -131,9 +131,11 @@ void main() {
|
||||
testWidgets('shows server side error messages', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
await pumpSessionForm(tester);
|
||||
when(mockRoutinesProvider.addSession(any, any)).thenThrow(WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}));
|
||||
when(mockRoutinesProvider.addSession(any, any)).thenThrow(
|
||||
WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}),
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.tap(find.byKey(const ValueKey('save-button')));
|
||||
|
||||
@@ -60,8 +60,9 @@ void main() {
|
||||
when(mockRoutinesProvider.findRepetitionUnitById(1)).thenReturn(testRepetitionUnit1);
|
||||
when(mockRoutinesProvider.weightUnits).thenReturn(testWeightUnits);
|
||||
when(mockRoutinesProvider.findWeightUnitById(1)).thenReturn(testWeightUnit1);
|
||||
when(mockRoutinesProvider.fetchAndSetRoutineFull(any))
|
||||
.thenAnswer((_) => Future.value(testRoutine));
|
||||
when(
|
||||
mockRoutinesProvider.fetchAndSetRoutineFull(any),
|
||||
).thenAnswer((_) => Future.value(testRoutine));
|
||||
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
@@ -96,10 +97,12 @@ void main() {
|
||||
testWidgets('Test the widgets on the gym mode screen', (WidgetTester tester) async {
|
||||
when(mockExerciseProvider.findExerciseById(1)).thenReturn(testExercises[0]);
|
||||
when(mockExerciseProvider.findExerciseById(6)).thenReturn(testExercises[5]);
|
||||
when(mockExerciseProvider.findExercisesByVariationId(
|
||||
null,
|
||||
exerciseIdToExclude: anyNamed('exerciseIdToExclude'),
|
||||
)).thenReturn([]);
|
||||
when(
|
||||
mockExerciseProvider.findExercisesByVariationId(
|
||||
null,
|
||||
exerciseIdToExclude: anyNamed('exerciseIdToExclude'),
|
||||
),
|
||||
).thenReturn([]);
|
||||
|
||||
await withClock(Clock.fixed(DateTime(2025, 3, 29, 14, 33)), () async {
|
||||
await tester.pumpWidget(renderGymMode());
|
||||
|
||||
@@ -52,8 +52,9 @@ void main() {
|
||||
mockRoutinesProvider = MockRoutinesProvider();
|
||||
when(mockRoutinesProvider.findById(any)).thenAnswer((_) => existingRoutine);
|
||||
when(mockRoutinesProvider.editRoutine(any)).thenAnswer((_) => Future.value(existingRoutine));
|
||||
when(mockRoutinesProvider.fetchAndSetRoutineFull(any))
|
||||
.thenAnswer((_) => Future.value(existingRoutine));
|
||||
when(
|
||||
mockRoutinesProvider.fetchAndSetRoutineFull(any),
|
||||
).thenAnswer((_) => Future.value(existingRoutine));
|
||||
});
|
||||
|
||||
Widget renderWidget(Routine routine, {locale = 'en'}) {
|
||||
@@ -115,9 +116,11 @@ void main() {
|
||||
|
||||
testWidgets('Test editing an existing routine - server error', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
when(mockRoutinesProvider.editRoutine(any)).thenThrow(WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}));
|
||||
when(mockRoutinesProvider.editRoutine(any)).thenThrow(
|
||||
WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}),
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(renderWidget(existingRoutine));
|
||||
@@ -185,9 +188,11 @@ void main() {
|
||||
|
||||
testWidgets('Test creating a new routine - server error', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
when(mockRoutinesProvider.addRoutine(any)).thenThrow(WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}));
|
||||
when(mockRoutinesProvider.addRoutine(any)).thenThrow(
|
||||
WgerHttpException.fromMap({
|
||||
'name': ['The name is not valid'],
|
||||
}),
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(renderWidget(newRoutine));
|
||||
|
||||
@@ -58,8 +58,9 @@ void main() {
|
||||
final exercisesProvider = ExercisesProvider(mockBaseProvider);
|
||||
|
||||
final uri = Uri.https('localhost', 'api/v2/routine/325397/');
|
||||
when(mockBaseProvider.makeUrl('routine', id: 325397, query: {'limit': API_MAX_PAGE_SIZE}))
|
||||
.thenReturn(uri);
|
||||
when(
|
||||
mockBaseProvider.makeUrl('routine', id: 325397, query: {'limit': API_MAX_PAGE_SIZE}),
|
||||
).thenReturn(uri);
|
||||
when(mockBaseProvider.fetch(uri)).thenAnswer(
|
||||
(_) async => Future.value({
|
||||
'id': 325397,
|
||||
@@ -115,8 +116,9 @@ void main() {
|
||||
final uri = Uri.https('localhost', 'api/v2/setting-repetitionunit/');
|
||||
final tRepetitionUnits = jsonDecode(fixture('routines/repetition_units.json'));
|
||||
when(mockBaseProvider.makeUrl('setting-repetitionunit')).thenReturn(uri);
|
||||
when(mockBaseProvider.fetchPaginated(uri))
|
||||
.thenAnswer((_) => Future.value(tRepetitionUnits['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(uri),
|
||||
).thenAnswer((_) => Future.value(tRepetitionUnits['results']));
|
||||
|
||||
// Load the entries
|
||||
final provider = RoutinesProvider(mockBaseProvider, exercisesProvider, []);
|
||||
@@ -130,8 +132,9 @@ void main() {
|
||||
final uri = Uri.https('localhost', 'api/v2/setting-weightunit/');
|
||||
when(mockBaseProvider.makeUrl('setting-weightunit')).thenReturn(uri);
|
||||
final tWeightUnits = jsonDecode(fixture('routines/weight_units.json'));
|
||||
when(mockBaseProvider.fetchPaginated(uri))
|
||||
.thenAnswer((_) => Future.value(tWeightUnits['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(uri),
|
||||
).thenAnswer((_) => Future.value(tWeightUnits['results']));
|
||||
|
||||
final ExercisesProvider testExercisesProvider = ExercisesProvider(mockBaseProvider);
|
||||
|
||||
@@ -148,14 +151,16 @@ void main() {
|
||||
final weightUri = Uri.https('localhost', 'api/v2/setting-weightunit/');
|
||||
when(mockBaseProvider.makeUrl('setting-weightunit')).thenReturn(weightUri);
|
||||
final tWeightUnits = jsonDecode(fixture('routines/weight_units.json'));
|
||||
when(mockBaseProvider.fetchPaginated(weightUri))
|
||||
.thenAnswer((_) => Future.value(tWeightUnits['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(weightUri),
|
||||
).thenAnswer((_) => Future.value(tWeightUnits['results']));
|
||||
|
||||
final repUnit = Uri.https('localhost', 'api/v2/setting-repetitionunit/');
|
||||
final tRepetitionUnits = jsonDecode(fixture('routines/repetition_units.json'));
|
||||
when(mockBaseProvider.makeUrl('setting-repetitionunit')).thenReturn(repUnit);
|
||||
when(mockBaseProvider.fetchPaginated(repUnit))
|
||||
.thenAnswer((_) => Future.value(tRepetitionUnits['results']));
|
||||
when(
|
||||
mockBaseProvider.fetchPaginated(repUnit),
|
||||
).thenAnswer((_) => Future.value(tRepetitionUnits['results']));
|
||||
|
||||
final exercisesProvider = ExercisesProvider(mockBaseProvider);
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -176,32 +181,45 @@ void main() {
|
||||
test('Smoke test fetchAndSetRoutineFull', () async {
|
||||
//Arrange
|
||||
final structureUri = Uri.https('localhost', 'api/v2/routine/101/structure/');
|
||||
when(mockBaseProvider.makeUrl('routine', objectMethod: 'structure', id: 101))
|
||||
.thenReturn(structureUri);
|
||||
when(mockBaseProvider.fetch(structureUri)).thenAnswer((_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_structure.json')),
|
||||
));
|
||||
when(
|
||||
mockBaseProvider.makeUrl('routine', objectMethod: 'structure', id: 101),
|
||||
).thenReturn(structureUri);
|
||||
when(mockBaseProvider.fetch(structureUri)).thenAnswer(
|
||||
(_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_structure.json')),
|
||||
),
|
||||
);
|
||||
|
||||
final dateSequenceDisplayUri =
|
||||
Uri.https('localhost', 'api/v2/routine/101/date-sequence-display/');
|
||||
when(mockBaseProvider.makeUrl('routine', objectMethod: 'date-sequence-display', id: 101))
|
||||
.thenReturn(dateSequenceDisplayUri);
|
||||
when(mockBaseProvider.fetch(dateSequenceDisplayUri)).thenAnswer((_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_date_sequence_display.json')),
|
||||
));
|
||||
final dateSequenceDisplayUri = Uri.https(
|
||||
'localhost',
|
||||
'api/v2/routine/101/date-sequence-display/',
|
||||
);
|
||||
when(
|
||||
mockBaseProvider.makeUrl('routine', objectMethod: 'date-sequence-display', id: 101),
|
||||
).thenReturn(dateSequenceDisplayUri);
|
||||
when(mockBaseProvider.fetch(dateSequenceDisplayUri)).thenAnswer(
|
||||
(_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_date_sequence_display.json')),
|
||||
),
|
||||
);
|
||||
|
||||
final dateSequenceGymUri = Uri.https('localhost', 'api/v2/routine/101/date-sequence-gym/');
|
||||
when(mockBaseProvider.makeUrl('routine', objectMethod: 'date-sequence-gym', id: 101))
|
||||
.thenReturn(dateSequenceGymUri);
|
||||
when(mockBaseProvider.fetch(dateSequenceGymUri)).thenAnswer((_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_date_sequence_gym.json')),
|
||||
));
|
||||
when(
|
||||
mockBaseProvider.makeUrl('routine', objectMethod: 'date-sequence-gym', id: 101),
|
||||
).thenReturn(dateSequenceGymUri);
|
||||
when(mockBaseProvider.fetch(dateSequenceGymUri)).thenAnswer(
|
||||
(_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_date_sequence_gym.json')),
|
||||
),
|
||||
);
|
||||
|
||||
final logsUri = Uri.https('localhost', 'api/v2/routine/101/logs/');
|
||||
when(mockBaseProvider.makeUrl('routine', objectMethod: 'logs', id: 101)).thenReturn(logsUri);
|
||||
when(mockBaseProvider.fetch(logsUri)).thenAnswer((_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_logs.json')),
|
||||
));
|
||||
when(mockBaseProvider.fetch(logsUri)).thenAnswer(
|
||||
(_) async => Future.value(
|
||||
jsonDecode(fixture('routines/routine_logs.json')),
|
||||
),
|
||||
);
|
||||
|
||||
final mockExercisesProvider = MockExercisesProvider();
|
||||
when(mockExercisesProvider.fetchAndSetExercise(76)).thenAnswer(
|
||||
|
||||
@@ -36,8 +36,9 @@ void main() {
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
|
||||
const String profileUrl = 'userprofile';
|
||||
final Map<String, dynamic> tUserProfileMap =
|
||||
jsonDecode(fixture('user/userprofile_response.json'));
|
||||
final Map<String, dynamic> tUserProfileMap = jsonDecode(
|
||||
fixture('user/userprofile_response.json'),
|
||||
);
|
||||
final Uri tProfileUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
@@ -56,10 +57,12 @@ void main() {
|
||||
userProvider = UserProvider(mockWgerBaseProvider);
|
||||
|
||||
when(mockWgerBaseProvider.makeUrl(any)).thenReturn(tProfileUri);
|
||||
when(mockWgerBaseProvider.makeUrl(any, objectMethod: 'verify-email'))
|
||||
.thenReturn(tEmailVerifyUri);
|
||||
when(mockWgerBaseProvider.fetch(any))
|
||||
.thenAnswer((realInvocation) => Future.value(tUserProfileMap));
|
||||
when(
|
||||
mockWgerBaseProvider.makeUrl(any, objectMethod: 'verify-email'),
|
||||
).thenReturn(tEmailVerifyUri);
|
||||
when(
|
||||
mockWgerBaseProvider.fetch(any),
|
||||
).thenAnswer((realInvocation) => Future.value(tUserProfileMap));
|
||||
});
|
||||
|
||||
group('house keeping', () {
|
||||
|
||||
+134
-118
@@ -30,9 +30,9 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
@@ -40,9 +40,9 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
@@ -50,9 +50,9 @@ class _FakeUri_2 extends _i1.SmartFake implements Uri {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
@@ -60,9 +60,9 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response {
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [WgerBaseProvider].
|
||||
@@ -74,50 +74,56 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
}
|
||||
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
) as _i2.AuthProvider);
|
||||
_i2.AuthProvider get auth =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(
|
||||
this,
|
||||
Invocation.getter(#auth),
|
||||
),
|
||||
)
|
||||
as _i2.AuthProvider);
|
||||
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
) as _i3.Client);
|
||||
_i3.Client get client =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(
|
||||
this,
|
||||
Invocation.getter(#client),
|
||||
),
|
||||
)
|
||||
as _i3.Client);
|
||||
|
||||
@override
|
||||
set auth(_i2.AuthProvider? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#auth,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
set client(_i3.Client? value) => super.noSuchMethod(
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
Invocation.setter(
|
||||
#client,
|
||||
value,
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
) as Map<String, String>);
|
||||
Map<String, String> getDefaultHeaders({bool? includeAuth = false}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDefaultHeaders,
|
||||
[],
|
||||
{#includeAuth: includeAuth},
|
||||
),
|
||||
returnValue: <String, String>{},
|
||||
)
|
||||
as Map<String, String>);
|
||||
|
||||
@override
|
||||
Uri makeUrl(
|
||||
@@ -127,46 +133,51 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
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);
|
||||
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<dynamic> fetch(Uri? uri) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<dynamic>.value(),
|
||||
) as _i5.Future<dynamic>);
|
||||
_i5.Future<dynamic> fetch(Uri? uri) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#fetch,
|
||||
[uri],
|
||||
),
|
||||
returnValue: _i5.Future<dynamic>.value(),
|
||||
)
|
||||
as _i5.Future<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>>);
|
||||
_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(
|
||||
@@ -174,15 +185,16 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#post,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
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(
|
||||
@@ -190,15 +202,16 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
Uri? uri,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i5.Future<Map<String, dynamic>>);
|
||||
Invocation.method(
|
||||
#patch,
|
||||
[
|
||||
data,
|
||||
uri,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
)
|
||||
as _i5.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i5.Future<_i3.Response> deleteRequest(
|
||||
@@ -206,22 +219,25 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
int? id,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<_i3.Response>.value(_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i5.Future<_i3.Response>);
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
returnValue: _i5.Future<_i3.Response>.value(
|
||||
_FakeResponse_3(
|
||||
this,
|
||||
Invocation.method(
|
||||
#deleteRequest,
|
||||
[
|
||||
url,
|
||||
id,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
as _i5.Future<_i3.Response>);
|
||||
}
|
||||
Loaded 100 of 105 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user