Automatic linting

This commit is contained in:
Github-actions
2021-06-22 21:10:15 +00:00
parent 15724fc600
commit c877e436b0
104 changed files with 576 additions and 1096 deletions

View File

@@ -60,6 +60,5 @@ String? timeToString(TimeOfDay? time) {
if (time == null) {
return null;
}
return DefaultMaterialLocalizations()
.formatTimeOfDay(time, alwaysUse24HourFormat: true);
return DefaultMaterialLocalizations().formatTimeOfDay(time, alwaysUse24HourFormat: true);
}

View File

@@ -41,9 +41,7 @@ String repText(
// rather "8 repetitions". If there is weight we want to output "8 x 50kg",
// since the repetitions are implied. If other units are used, we always
// print them
if (repetitionUnitObj.id != DEFAULT_REPETITION_UNIT ||
weight == 0 ||
weight == null) {
if (repetitionUnitObj.id != DEFAULT_REPETITION_UNIT || weight == 0 || weight == null) {
out.add(repetitionUnitObj.name);
}
}

View File

@@ -44,8 +44,7 @@ void showErrorDialog(dynamic exception, BuildContext context) {
);
}
void showHttpExceptionErrorDialog(
WgerHttpException exception, BuildContext context) {
void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext context) {
log('showHttpExceptionErrorDialog: ');
log(exception.toString());
log('-------------------');

View File

@@ -58,37 +58,35 @@ class MyApp extends StatelessWidget {
create: (ctx) => AuthProvider(),
),
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
create: (context) => ExercisesProvider(
Provider.of<AuthProvider>(context, listen: false), []),
create: (context) =>
ExercisesProvider(Provider.of<AuthProvider>(context, listen: false), []),
update: (context, auth, previous) =>
previous != null ? previous : ExercisesProvider(auth, []),
),
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider,
WorkoutPlansProvider>(
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider, WorkoutPlansProvider>(
create: (context) => WorkoutPlansProvider(
Provider.of<AuthProvider>(context, listen: false),
Provider.of<ExercisesProvider>(context, listen: false),
[],
),
update: (context, auth, exercises, previous) => previous != null
? previous
: WorkoutPlansProvider(auth, exercises, []),
update: (context, auth, exercises, previous) =>
previous != null ? previous : WorkoutPlansProvider(auth, exercises, []),
),
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
create: (context) => NutritionPlansProvider(
Provider.of<AuthProvider>(context, listen: false), []),
create: (context) =>
NutritionPlansProvider(Provider.of<AuthProvider>(context, listen: false), []),
update: (context, auth, previous) =>
previous != null ? previous : NutritionPlansProvider(auth, []),
),
ChangeNotifierProxyProvider<AuthProvider, BodyWeightProvider>(
create: (context) => BodyWeightProvider(
Provider.of<AuthProvider>(context, listen: false), []),
create: (context) =>
BodyWeightProvider(Provider.of<AuthProvider>(context, listen: false), []),
update: (context, auth, previous) =>
previous != null ? previous : BodyWeightProvider(auth, []),
),
ChangeNotifierProxyProvider<AuthProvider, GalleryProvider>(
create: (context) => GalleryProvider(
Provider.of<AuthProvider>(context, listen: false), []),
create: (context) =>
GalleryProvider(Provider.of<AuthProvider>(context, listen: false), []),
update: (context, auth, previous) =>
previous != null ? previous : GalleryProvider(auth, []),
),
@@ -102,8 +100,7 @@ class MyApp extends StatelessWidget {
: FutureBuilder(
future: auth.tryAutoLogin(),
builder: (ctx, authResultSnapshot) =>
authResultSnapshot.connectionState ==
ConnectionState.waiting
authResultSnapshot.connectionState == ConnectionState.waiting
? SplashScreen()
: AuthScreen(),
),

View File

@@ -45,7 +45,6 @@ class WeightEntry {
}
// Boilerplate
factory WeightEntry.fromJson(Map<String, dynamic> json) =>
_$WeightEntryFromJson(json);
factory WeightEntry.fromJson(Map<String, dynamic> json) => _$WeightEntryFromJson(json);
Map<String, dynamic> toJson() => _$WeightEntryToJson(this);
}

View File

@@ -15,8 +15,7 @@ WeightEntry _$WeightEntryFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$WeightEntryToJson(WeightEntry instance) =>
<String, dynamic>{
Map<String, dynamic> _$WeightEntryToJson(WeightEntry instance) => <String, dynamic>{
'id': instance.id,
'weight': numToString(instance.weight),
'date': toDate(instance.date),

View File

@@ -39,7 +39,6 @@ class ExerciseCategory {
}
// Boilerplate
factory ExerciseCategory.fromJson(Map<String, dynamic> json) =>
_$ExerciseCategoryFromJson(json);
factory ExerciseCategory.fromJson(Map<String, dynamic> json) => _$ExerciseCategoryFromJson(json);
Map<String, dynamic> toJson() => _$ExerciseCategoryToJson(this);
}

View File

@@ -14,8 +14,7 @@ ExerciseCategory _$ExerciseCategoryFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$ExerciseCategoryToJson(ExerciseCategory instance) =>
<String, dynamic>{
Map<String, dynamic> _$ExerciseCategoryToJson(ExerciseCategory instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
};

View File

@@ -34,7 +34,6 @@ class Comment {
});
// Boilerplate
factory Comment.fromJson(Map<String, dynamic> json) =>
_$CommentFromJson(json);
factory Comment.fromJson(Map<String, dynamic> json) => _$CommentFromJson(json);
Map<String, dynamic> toJson() => _$CommentToJson(this);
}

View File

@@ -34,7 +34,6 @@ class Equipment {
});
// Boilerplate
factory Equipment.fromJson(Map<String, dynamic> json) =>
_$EquipmentFromJson(json);
factory Equipment.fromJson(Map<String, dynamic> json) => _$EquipmentFromJson(json);
Map<String, dynamic> toJson() => _$EquipmentToJson(this);
}

View File

@@ -100,7 +100,6 @@ class Exercise {
}
// Boilerplate
factory Exercise.fromJson(Map<String, dynamic> json) =>
_$ExerciseFromJson(json);
factory Exercise.fromJson(Map<String, dynamic> json) => _$ExerciseFromJson(json);
Map<String, dynamic> toJson() => _$ExerciseToJson(this);
}

View File

@@ -42,8 +42,7 @@ Exercise _$ExerciseFromJson(Map<String, dynamic> json) {
tips: (json['comments'] as List<dynamic>?)
?.map((e) => Comment.fromJson(e as Map<String, dynamic>))
.toList(),
)..categoryObj =
ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>);
)..categoryObj = ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>);
}
Map<String, dynamic> _$ExerciseToJson(Exercise instance) => <String, dynamic>{
@@ -55,8 +54,7 @@ Map<String, dynamic> _$ExerciseToJson(Exercise instance) => <String, dynamic>{
'categoryId': instance.categoryId,
'category': instance.categoryObj.toJson(),
'muscles': instance.muscles.map((e) => e.toJson()).toList(),
'muscles_secondary':
instance.musclesSecondary.map((e) => e.toJson()).toList(),
'muscles_secondary': instance.musclesSecondary.map((e) => e.toJson()).toList(),
'equipment': instance.equipment.map((e) => e.toJson()).toList(),
'images': instance.images.map((e) => e.toJson()).toList(),
'comments': instance.tips.map((e) => e.toJson()).toList(),

View File

@@ -46,7 +46,6 @@ class ExerciseImage {
});
// Boilerplate
factory ExerciseImage.fromJson(Map<String, dynamic> json) =>
_$ExerciseImageFromJson(json);
factory ExerciseImage.fromJson(Map<String, dynamic> json) => _$ExerciseImageFromJson(json);
Map<String, dynamic> toJson() => _$ExerciseImageToJson(this);
}

View File

@@ -7,8 +7,7 @@ part of 'image.dart';
// **************************************************************************
ExerciseImage _$ExerciseImageFromJson(Map<String, dynamic> json) {
$checkKeys(json,
requiredKeys: const ['id', 'uuid', 'exercise_base', 'image']);
$checkKeys(json, requiredKeys: const ['id', 'uuid', 'exercise_base', 'image']);
return ExerciseImage(
id: json['id'] as int,
uuid: json['uuid'] as String,
@@ -18,8 +17,7 @@ ExerciseImage _$ExerciseImageFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$ExerciseImageToJson(ExerciseImage instance) =>
<String, dynamic>{
Map<String, dynamic> _$ExerciseImageToJson(ExerciseImage instance) => <String, dynamic>{
'id': instance.id,
'uuid': instance.uuid,
'exercise_base': instance.exerciseBaseId,

View File

@@ -26,10 +26,7 @@ class WgerHttpException implements Exception {
/// JSON. Will use the response as-is if it fails.
WgerHttpException(dynamic responseBody) {
if (responseBody == null) {
errors = {
'unknown_error':
'An unknown error occurred, no further information available'
};
errors = {'unknown_error': 'An unknown error occurred, no further information available'};
} else {
try {
errors = json.decode(responseBody);

View File

@@ -41,11 +41,7 @@ class Ingredient {
final num carbohydrates;
/// g per 100g of product
@JsonKey(
required: true,
fromJson: stringToNum,
toJson: numToString,
name: 'carbohydrates_sugar')
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString, name: 'carbohydrates_sugar')
final num carbohydratesSugar;
/// g per 100g of product
@@ -57,11 +53,7 @@ class Ingredient {
final num fat;
/// g per 100g of product
@JsonKey(
required: true,
fromJson: stringToNum,
toJson: numToString,
name: 'fat_saturated')
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString, name: 'fat_saturated')
final num fatSaturated;
/// g per 100g of product
@@ -87,7 +79,6 @@ class Ingredient {
});
// Boilerplate
factory Ingredient.fromJson(Map<String, dynamic> json) =>
_$IngredientFromJson(json);
factory Ingredient.fromJson(Map<String, dynamic> json) => _$IngredientFromJson(json);
Map<String, dynamic> toJson() => _$IngredientToJson(this);
}

View File

@@ -35,8 +35,7 @@ Ingredient _$IngredientFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$IngredientToJson(Ingredient instance) =>
<String, dynamic>{
Map<String, dynamic> _$IngredientToJson(Ingredient instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
'creation_date': toDate(instance.creationDate),

View File

@@ -7,25 +7,17 @@ part of 'ingredient_weight_unit.dart';
// **************************************************************************
IngredientWeightUnit _$IngredientWeightUnitFromJson(Map<String, dynamic> json) {
$checkKeys(json, requiredKeys: const [
'id',
'weight_unit',
'ingredient',
'grams',
'amount'
]);
$checkKeys(json, requiredKeys: const ['id', 'weight_unit', 'ingredient', 'grams', 'amount']);
return IngredientWeightUnit(
id: json['id'] as int,
weightUnit:
WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
weightUnit: WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
ingredient: Ingredient.fromJson(json['ingredient'] as Map<String, dynamic>),
grams: json['grams'] as int,
amount: (json['amount'] as num).toDouble(),
);
}
Map<String, dynamic> _$IngredientWeightUnitToJson(
IngredientWeightUnit instance) =>
Map<String, dynamic> _$IngredientWeightUnitToJson(IngredientWeightUnit instance) =>
<String, dynamic>{
'id': instance.id,
'weight_unit': instance.weightUnit,

View File

@@ -82,9 +82,8 @@ class Log {
var out = NutritionalValues();
//final weight = amount;
final weight = this.weightUnitObj == null
? amount
: amount * weightUnitObj!.amount * weightUnitObj!.grams;
final weight =
this.weightUnitObj == null ? amount : amount * weightUnitObj!.amount * weightUnitObj!.grams;
out.energy = ingredientObj.energy * weight / 100;
out.protein = ingredientObj.protein * weight / 100;

View File

@@ -7,14 +7,8 @@ part of 'log.dart';
// **************************************************************************
Log _$LogFromJson(Map<String, dynamic> json) {
$checkKeys(json, requiredKeys: const [
'id',
'plan',
'datetime',
'ingredient',
'weight_unit',
'amount'
]);
$checkKeys(json,
requiredKeys: const ['id', 'plan', 'datetime', 'ingredient', 'weight_unit', 'amount']);
return Log(
id: json['id'] as int?,
ingredientId: json['ingredient'] as int,

View File

@@ -63,8 +63,7 @@ class MealItem {
MealItem.empty();
// Boilerplate
factory MealItem.fromJson(Map<String, dynamic> json) =>
_$MealItemFromJson(json);
factory MealItem.fromJson(Map<String, dynamic> json) => _$MealItemFromJson(json);
Map<String, dynamic> toJson() => _$MealItemToJson(this);

View File

@@ -59,8 +59,7 @@ class NutritionalPlan {
}
// Boilerplate
factory NutritionalPlan.fromJson(Map<String, dynamic> json) =>
_$NutritionalPlanFromJson(json);
factory NutritionalPlan.fromJson(Map<String, dynamic> json) => _$NutritionalPlanFromJson(json);
Map<String, dynamic> toJson() => _$NutritionalPlanToJson(this);
/// Calculations
@@ -78,8 +77,7 @@ class NutritionalPlan {
Map<DateTime, NutritionalValues> get logEntriesValues {
var out = <DateTime, NutritionalValues>{};
for (var log in logs) {
final date =
DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
final date = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
if (!out.containsKey(date)) {
out[date] = NutritionalValues();

View File

@@ -15,8 +15,7 @@ NutritionalPlan _$NutritionalPlanFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) =>
<String, dynamic>{
Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) => <String, dynamic>{
'id': instance.id,
'description': instance.description,
'creation_date': toDate(instance.creationDate),

View File

@@ -34,7 +34,6 @@ class WeightUnit {
});
// Boilerplate
factory WeightUnit.fromJson(Map<String, dynamic> json) =>
_$WeightUnitFromJson(json);
factory WeightUnit.fromJson(Map<String, dynamic> json) => _$WeightUnitFromJson(json);
Map<String, dynamic> toJson() => _$WeightUnitToJson(this);
}

View File

@@ -14,8 +14,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
<String, dynamic>{
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
};

View File

@@ -75,8 +75,7 @@ class Day {
final now = DateTime.now();
final firstDayOfWeek = now.subtract(Duration(days: now.weekday));
return DateFormat(DateFormat.WEEKDAY, locale)
.format(firstDayOfWeek.add(Duration(days: day)));
return DateFormat(DateFormat.WEEKDAY, locale).format(firstDayOfWeek.add(Duration(days: day)));
}
// Boilerplate

View File

@@ -7,8 +7,7 @@ part of 'day.dart';
// **************************************************************************
Day _$DayFromJson(Map<String, dynamic> json) {
$checkKeys(json,
requiredKeys: const ['id', 'training', 'description', 'day']);
$checkKeys(json, requiredKeys: const ['id', 'training', 'description', 'day']);
return Day()
..id = json['id'] as int?
..workoutId = json['training'] as int

View File

@@ -112,8 +112,7 @@ class Log {
/// Returns the text representation for a single setting, used in the gym mode
String get singleLogRepTextNoNl {
return repText(reps, repetitionUnitObj, weight, weightUnitObj, rir)
.replaceAll('\n', '');
return repText(reps, repetitionUnitObj, weight, weightUnitObj, rir).replaceAll('\n', '');
}
/// Override the equals operator
@@ -131,8 +130,7 @@ class Log {
}
@override
int get hashCode =>
hashValues(exerciseId, weight, weightUnitId, reps, repetitionUnitId, rir);
int get hashCode => hashValues(exerciseId, weight, weightUnitId, reps, repetitionUnitId, rir);
//@override
//int get hashCode => super.hashCode;

View File

@@ -34,7 +34,6 @@ class RepetitionUnit {
});
// Boilerplate
factory RepetitionUnit.fromJson(Map<String, dynamic> json) =>
_$RepetitionUnitFromJson(json);
factory RepetitionUnit.fromJson(Map<String, dynamic> json) => _$RepetitionUnitFromJson(json);
Map<String, dynamic> toJson() => _$RepetitionUnitToJson(this);
}

View File

@@ -14,8 +14,7 @@ RepetitionUnit _$RepetitionUnitFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) =>
<String, dynamic>{
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
};

View File

@@ -41,18 +41,10 @@ class WorkoutSession {
@JsonKey(required: false, defaultValue: '')
late String notes;
@JsonKey(
required: true,
name: 'time_start',
toJson: timeToString,
fromJson: stringToTime)
@JsonKey(required: true, name: 'time_start', toJson: timeToString, fromJson: stringToTime)
late TimeOfDay timeStart;
@JsonKey(
required: true,
name: 'time_end',
toJson: timeToString,
fromJson: stringToTime)
@JsonKey(required: true, name: 'time_end', toJson: timeToString, fromJson: stringToTime)
late TimeOfDay timeEnd;
WorkoutSession();
@@ -68,8 +60,7 @@ class WorkoutSession {
});
// Boilerplate
factory WorkoutSession.fromJson(Map<String, dynamic> json) =>
_$WorkoutSessionFromJson(json);
factory WorkoutSession.fromJson(Map<String, dynamic> json) => _$WorkoutSessionFromJson(json);
Map<String, dynamic> toJson() => _$WorkoutSessionToJson(this);
get impressionAsString {

View File

@@ -7,14 +7,8 @@ part of 'session.dart';
// **************************************************************************
WorkoutSession _$WorkoutSessionFromJson(Map<String, dynamic> json) {
$checkKeys(json, requiredKeys: const [
'id',
'workout',
'date',
'impression',
'time_start',
'time_end'
]);
$checkKeys(json,
requiredKeys: const ['id', 'workout', 'date', 'impression', 'time_start', 'time_end']);
return WorkoutSession()
..id = json['id'] as int?
..workoutId = json['workout'] as int
@@ -25,8 +19,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map<String, dynamic> json) {
..timeEnd = stringToTime(json['time_end'] as String?);
}
Map<String, dynamic> _$WorkoutSessionToJson(WorkoutSession instance) =>
<String, dynamic>{
Map<String, dynamic> _$WorkoutSessionToJson(WorkoutSession instance) => <String, dynamic>{
'id': instance.id,
'workout': instance.workoutId,
'date': toDate(instance.date),

View File

@@ -109,9 +109,7 @@ class Set {
/// Returns all settings for the given exercise
List<Setting> filterSettingsByExercise(Exercise exercise) {
return settings
.where((element) => element.exerciseId == exercise.id)
.toList();
return settings.where((element) => element.exerciseId == exercise.id).toList();
}
/// Returns a list with all repetitions for the given exercise

View File

@@ -29,18 +29,7 @@ part 'setting.g.dart';
class Setting {
/// Allowed RiR values. This list must be kept in sync with RIR_OPTIONS in the
/// wger server
static const POSSIBLE_RIR_VALUES = [
'',
'0',
'0.5',
'1',
'1.5',
'2',
'2.5',
'3',
'3.5',
'4'
];
static const POSSIBLE_RIR_VALUES = ['', '0', '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4'];
static const DEFAULT_RIR = '';
@JsonKey(required: true)
@@ -99,8 +88,7 @@ class Setting {
Setting.empty();
// Boilerplate
factory Setting.fromJson(Map<String, dynamic> json) =>
_$SettingFromJson(json);
factory Setting.fromJson(Map<String, dynamic> json) => _$SettingFromJson(json);
Map<String, dynamic> toJson() => _$SettingToJson(this);
set exercise(Exercise exercise) {

View File

@@ -34,7 +34,6 @@ class WeightUnit {
});
// Boilerplate
factory WeightUnit.fromJson(Map<String, dynamic> json) =>
_$WeightUnitFromJson(json);
factory WeightUnit.fromJson(Map<String, dynamic> json) => _$WeightUnitFromJson(json);
Map<String, dynamic> toJson() => _$WeightUnitToJson(this);
}

View File

@@ -14,8 +14,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
<String, dynamic>{
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
};

View File

@@ -65,8 +65,7 @@ class WorkoutPlan {
}
// Boilerplate
factory WorkoutPlan.fromJson(Map<String, dynamic> json) =>
_$WorkoutPlanFromJson(json);
factory WorkoutPlan.fromJson(Map<String, dynamic> json) => _$WorkoutPlanFromJson(json);
Map<String, dynamic> toJson() => _$WorkoutPlanToJson(this);
/// Filters the workout logs by exercise and sorts them by date
@@ -76,8 +75,7 @@ class WorkoutPlan {
/// reps, etc. are considered equal. Workout ID, Log ID and date are not
/// considered.
List<Log> filterLogsByExercise(Exercise exercise, {bool unique = false}) {
var out =
logs.where((element) => element.exerciseId == exercise.id).toList();
var out = logs.where((element) => element.exerciseId == exercise.id).toList();
if (unique) {
out = out.toSet().toList();

View File

@@ -7,8 +7,7 @@ part of 'workout_plan.dart';
// **************************************************************************
WorkoutPlan _$WorkoutPlanFromJson(Map<String, dynamic> json) {
$checkKeys(json,
requiredKeys: const ['id', 'creation_date', 'name', 'description']);
$checkKeys(json, requiredKeys: const ['id', 'creation_date', 'name', 'description']);
return WorkoutPlan(
id: json['id'] as int?,
creationDate: DateTime.parse(json['creation_date'] as String),
@@ -17,8 +16,7 @@ WorkoutPlan _$WorkoutPlanFromJson(Map<String, dynamic> json) {
);
}
Map<String, dynamic> _$WorkoutPlanToJson(WorkoutPlan instance) =>
<String, dynamic>{
Map<String, dynamic> _$WorkoutPlanToJson(WorkoutPlan instance) => <String, dynamic>{
'id': instance.id,
'creation_date': instance.creationDate.toIso8601String(),
'name': instance.name,

View File

@@ -38,8 +38,7 @@ class WgerBaseProvider {
}
/// Helper function to make a URL.
Uri makeUrl(String path,
{int? id, String? objectMethod, Map<String, dynamic>? query}) {
Uri makeUrl(String path, {int? id, String? objectMethod, Map<String, dynamic>? query}) {
return makeUri(auth.serverUrl!, path, id, objectMethod, query);
}

View File

@@ -27,8 +27,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
static const bodyWeightUrl = 'weightentry';
List<WeightEntry> _entries = [];
BodyWeightProvider(AuthProvider auth, List<WeightEntry> entries,
[http.Client? client])
BodyWeightProvider(AuthProvider auth, List<WeightEntry> entries, [http.Client? client])
: this._entries = entries,
super(auth, client);
@@ -55,8 +54,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
Future<List<WeightEntry>> fetchAndSetEntries() async {
// Process the response
final data =
await fetch(makeUrl(bodyWeightUrl, query: {'ordering': '-date'}));
final data = await fetch(makeUrl(bodyWeightUrl, query: {'ordering': '-date'}));
final List<WeightEntry> loadedEntries = [];
for (final entry in data['results']) {
loadedEntries.add(WeightEntry.fromJson(entry));
@@ -85,8 +83,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
Future<void> deleteEntry(int id) async {
// Send the request and remove the entry from the list...
final existingEntryIndex =
_entries.indexWhere((element) => element.id == id);
final existingEntryIndex = _entries.indexWhere((element) => element.id == id);
var existingWeightEntry = _entries[existingEntryIndex];
_entries.removeAt(existingEntryIndex);
notifyListeners();

View File

@@ -51,8 +51,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
List<Muscle> _muscles = [];
List<Equipment> _equipment = [];
ExercisesProvider(AuthProvider auth, List<Exercise> entries,
[http.Client? client])
ExercisesProvider(AuthProvider auth, List<Exercise> entries, [http.Client? client])
: this._exercises = entries,
super(auth, client);
@@ -130,14 +129,10 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
if (prefs.containsKey(PREFS_EXERCISES)) {
final exerciseData = json.decode(prefs.getString(PREFS_EXERCISES)!);
if (DateTime.parse(exerciseData['expiresIn']).isAfter(DateTime.now())) {
exerciseData['exercises']
.forEach((e) => _exercises.add(Exercise.fromJson(e)));
exerciseData['equipment']
.forEach((e) => _equipment.add(Equipment.fromJson(e)));
exerciseData['muscles']
.forEach((e) => _muscles.add(Muscle.fromJson(e)));
exerciseData['categories']
.forEach((e) => _categories.add(ExerciseCategory.fromJson(e)));
exerciseData['exercises'].forEach((e) => _exercises.add(Exercise.fromJson(e)));
exerciseData['equipment'].forEach((e) => _equipment.add(Equipment.fromJson(e)));
exerciseData['muscles'].forEach((e) => _muscles.add(Muscle.fromJson(e)));
exerciseData['categories'].forEach((e) => _categories.add(ExerciseCategory.fromJson(e)));
log("Read ${exerciseData['exercises'].length} exercises from cache. Valid till ${exerciseData['expiresIn']}");
return;
}
@@ -156,19 +151,16 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
});
final exercisesData =
json.decode(utf8.decode(response.bodyBytes)) as Map<String, dynamic>;
final exercisesData = json.decode(utf8.decode(response.bodyBytes)) as Map<String, dynamic>;
try {
// Load exercises
exercisesData['results']
.forEach((e) => _exercises.add(Exercise.fromJson(e)));
exercisesData['results'].forEach((e) => _exercises.add(Exercise.fromJson(e)));
// Save the result to the cache
final exerciseData = {
'date': DateTime.now().toIso8601String(),
'expiresIn':
DateTime.now().add(Duration(days: daysToCache)).toIso8601String(),
'expiresIn': DateTime.now().add(Duration(days: daysToCache)).toIso8601String(),
'exercises': _exercises.map((e) => e.toJson()).toList(),
'equipment': _equipment.map((e) => e.toJson()).toList(),
'categories': _categories.map((e) => e.toJson()).toList(),
@@ -210,8 +202,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
}
// Process the response
final result = json.decode(utf8.decode(response.bodyBytes))['suggestions']
as List<dynamic>;
final result = json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
for (var entry in result) {
entry['exercise_obj'] = await fetchAndSetExercise(entry['data']['id']);
}

View File

@@ -32,8 +32,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
List<gallery.Image> images = [];
GalleryProvider(AuthProvider auth, List<gallery.Image> entries,
[http.Client? client])
GalleryProvider(AuthProvider auth, List<gallery.Image> entries, [http.Client? client])
: this.images = entries,
super(auth, client);
@@ -63,8 +62,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
});
request.files
.add(await http.MultipartFile.fromPath('image', imageFile.path));
request.files.add(await http.MultipartFile.fromPath('image', imageFile.path));
request.fields['date'] = toDate(image.date)!;
request.fields['description'] = image.description;
@@ -78,8 +76,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
}
Future<void> editImage(gallery.Image image, PickedFile? imageFile) async {
var request =
http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
var request = http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
request.headers.addAll({
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
@@ -87,8 +84,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
// Only send the image if a new one was selected
if (imageFile != null) {
request.files
.add(await http.MultipartFile.fromPath('image', imageFile.path));
request.files.add(await http.MultipartFile.fromPath('image', imageFile.path));
}
// Update image info

View File

@@ -45,8 +45,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
List<NutritionalPlan> _plans = [];
List<Ingredient> _ingredients = [];
NutritionPlansProvider(AuthProvider auth, List<NutritionalPlan> entries,
[http.Client? client])
NutritionPlansProvider(AuthProvider auth, List<NutritionalPlan> entries, [http.Client? client])
: this._plans = entries,
super(auth, client);
@@ -85,8 +84,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Fetches and sets all plans sparsely, i.e. only with the data on the plan
/// object itself and no child attributes
Future<void> fetchAndSetAllPlansSparse() async {
final data =
await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
for (final planData in data['results']) {
final plan = NutritionalPlan.fromJson(planData);
_plans.add(plan);
@@ -127,8 +125,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
}
// Plan
final fullPlanData =
await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId));
final fullPlanData = await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId));
// Meals
List<Meal> meals = [];
@@ -286,8 +283,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
if (prefs.containsKey('ingredientData')) {
final ingredientData = json.decode(prefs.getString('ingredientData')!);
if (DateTime.parse(ingredientData['expiresIn']).isAfter(DateTime.now())) {
ingredientData['ingredients']
.forEach((e) => _ingredients.add(Ingredient.fromJson(e)));
ingredientData['ingredients'].forEach((e) => _ingredients.add(Ingredient.fromJson(e)));
log("Read ${ingredientData['ingredients'].length} ingredients from cache. Valid till ${ingredientData['expiresIn']}");
return;
}
@@ -296,8 +292,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Initialise an empty cache
final ingredientData = {
'date': DateTime.now().toIso8601String(),
'expiresIn':
DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'expiresIn': DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'ingredients': []
};
prefs.setString('ingredientData', json.encode(ingredientData));
@@ -305,8 +300,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
}
/// Searches for an ingredient
Future<List> searchIngredient(String name,
[String languageCode = 'en']) async {
Future<List> searchIngredient(String name, [String languageCode = 'en']) async {
if (name.length <= 1) {
return [];
}
@@ -329,8 +323,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
}
// Process the response
return json.decode(utf8.decode(response.bodyBytes))['suggestions']
as List<dynamic>;
return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
}
/// Log meal to nutrition diary
@@ -350,8 +343,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
// TODO: update fetch to that it can use the pagination
final data = await fetch(
makeUrl(_nutritionDiaryPath,
query: {'plan': plan.id.toString(), 'limit': '1000'}),
makeUrl(_nutritionDiaryPath, query: {'plan': plan.id.toString(), 'limit': '1000'}),
);
for (var logData in data['results']) {

View File

@@ -53,8 +53,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
List<WeightUnit> _weightUnits = [];
List<RepetitionUnit> _repetitionUnit = [];
WorkoutPlansProvider(
AuthProvider auth, ExercisesProvider exercises, List<WorkoutPlan> entries,
WorkoutPlansProvider(AuthProvider auth, ExercisesProvider exercises, List<WorkoutPlan> entries,
[http.Client? client])
: this._exercises = exercises,
this._workoutPlans = entries,
@@ -78,8 +77,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Return the default weight unit (kg)
WeightUnit get defaultWeightUnit {
return _weightUnits
.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
return _weightUnits.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
}
List<RepetitionUnit> get repetitionUnits {
@@ -88,8 +86,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Return the default weight unit (reps)
RepetitionUnit get defaultRepetitionUnit {
return _repetitionUnit
.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT);
return _repetitionUnit.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT);
}
WorkoutPlan findById(int id) {
@@ -144,8 +141,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
/// Fetches all workout plan sparsely, i.e. only with the data on the plan
/// object itself and no child attributes
Future<void> fetchAndSetAllPlansSparse() async {
final data =
await fetch(makeUrl(_workoutPlansUrlPath, query: {'limit': '1000'}));
final data = await fetch(makeUrl(_workoutPlansUrlPath, query: {'limit': '1000'}));
for (final workoutPlanData in data['results']) {
final plan = WorkoutPlan.fromJson(workoutPlanData);
_workoutPlans.add(plan);
@@ -187,8 +183,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Plan
final fullPlanData = await fetch(
makeUrl(_workoutPlansUrlPath,
id: workoutId, objectMethod: 'canonical_representation'),
makeUrl(_workoutPlansUrlPath, id: workoutId, objectMethod: 'canonical_representation'),
);
// Days
@@ -205,14 +200,12 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Settings
List<Setting> settings = [];
final settingData =
allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
final settingData = allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
for (final settingEntry in settingData) {
final workoutSetting = Setting.fromJson(settingEntry);
workoutSetting.exercise =
await _exercises.fetchAndSetExercise(workoutSetting.exerciseId);
workoutSetting.exercise = await _exercises.fetchAndSetExercise(workoutSetting.exerciseId);
workoutSetting.weightUnit = _weightUnits.firstWhere(
(e) => e.id == workoutSetting.weightUnitId,
);
@@ -251,10 +244,8 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
for (final entry in logData['results']) {
try {
var log = Log.fromJson(entry);
log.weightUnit =
_weightUnits.firstWhere((e) => e.id == log.weightUnitId);
log.repetitionUnit =
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
log.exercise = await _exercises.fetchAndSetExercise(log.exerciseId);
plan.logs.add(log);
} catch (e) {
@@ -284,14 +275,12 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
}
Future<void> editWorkout(WorkoutPlan workout) async {
await patch(
workout.toJson(), makeUrl(_workoutPlansUrlPath, id: workout.id));
await patch(workout.toJson(), makeUrl(_workoutPlansUrlPath, id: workout.id));
notifyListeners();
}
Future<void> deleteWorkout(int id) async {
final existingWorkoutIndex =
_workoutPlans.indexWhere((element) => element.id == id);
final existingWorkoutIndex = _workoutPlans.indexWhere((element) => element.id == id);
var existingWorkout = _workoutPlans[existingWorkoutIndex];
_workoutPlans.removeAt(existingWorkoutIndex);
notifyListeners();
@@ -305,8 +294,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
}
}
Future<Map<String, dynamic>> fetchLogData(
WorkoutPlan workout, Exercise exercise) async {
Future<Map<String, dynamic>> fetchLogData(WorkoutPlan workout, Exercise exercise) async {
final data = await fetch(
makeUrl(
_workoutPlansUrlPath,
@@ -356,8 +344,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
unitData['weightUnit'].forEach(
(e) => _weightUnits.add(WeightUnit.fromJson(e)),
);
dev.log(
"Read workout units data from cache. Valid till ${unitData['expiresIn']}");
dev.log("Read workout units data from cache. Valid till ${unitData['expiresIn']}");
return;
}
}
@@ -369,8 +356,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Save the result to the cache
final exerciseData = {
'date': DateTime.now().toIso8601String(),
'expiresIn':
DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'expiresIn': DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'repetitionUnits': _repetitionUnit.map((e) => e.toJson()).toList(),
'weightUnit': _weightUnits.map((e) => e.toJson()).toList(),
};
@@ -501,8 +487,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
log.id = newLog.id;
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
log.repetitionUnit =
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
log.exercise = await _exercises.fetchAndSetExercise(log.exerciseId);
final plan = findById(log.workoutPlan);

View File

@@ -56,8 +56,7 @@ class AuthScreen extends StatelessWidget {
),
Container(
margin: EdgeInsets.only(bottom: 20.0),
padding:
EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0),
padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0),
child: Text(
'WGER',
style: TextStyle(
@@ -208,8 +207,7 @@ class _AuthCardState extends State<AuthCard> {
if (_authMode == AuthMode.Signup)
TextFormField(
key: Key('inputEmail'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).email),
decoration: InputDecoration(labelText: AppLocalizations.of(context).email),
autofillHints: [AutofillHints.email],
controller: _emailController,
keyboardType: TextInputType.emailAddress,
@@ -228,8 +226,7 @@ class _AuthCardState extends State<AuthCard> {
),
TextFormField(
key: Key('inputPassword'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).password),
decoration: InputDecoration(labelText: AppLocalizations.of(context).password),
autofillHints: [AutofillHints.password],
obscureText: true,
controller: _passwordController,
@@ -247,17 +244,15 @@ class _AuthCardState extends State<AuthCard> {
if (_authMode == AuthMode.Signup)
TextFormField(
key: Key('inputPassword2'),
decoration: InputDecoration(
labelText:
AppLocalizations.of(context).confirmPassword),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).confirmPassword),
controller: _password2Controller,
enabled: _authMode == AuthMode.Signup,
obscureText: true,
validator: _authMode == AuthMode.Signup
? (value) {
if (value != _passwordController.text) {
return AppLocalizations.of(context)
.passwordsDontMatch;
return AppLocalizations.of(context).passwordsDontMatch;
}
return null;
}
@@ -274,10 +269,8 @@ class _AuthCardState extends State<AuthCard> {
child: TextFormField(
key: Key('inputServer'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context)
.customServerUrl,
helperText: AppLocalizations.of(context)
.customServerHint,
labelText: AppLocalizations.of(context).customServerUrl,
helperText: AppLocalizations.of(context).customServerHint,
helperMaxLines: 4),
controller: _serverUrlController,
validator: (value) {
@@ -332,12 +325,8 @@ class _AuthCardState extends State<AuthCard> {
key: Key('toggleActionButton'),
child: Text(
_authMode == AuthMode.Login
? AppLocalizations.of(context)
.registerInstead
.toUpperCase()
: AppLocalizations.of(context)
.loginInstead
.toUpperCase(),
? AppLocalizations.of(context).registerInstead.toUpperCase()
: AppLocalizations.of(context).loginInstead.toUpperCase(),
),
onPressed: _switchAuthMode,
),

View File

@@ -53,16 +53,11 @@ class _DashboardScreenState extends State<DashboardScreen> {
if (!Provider.of<AuthProvider>(context, listen: false).dataInit) {
Provider.of<AuthProvider>(context, listen: false).setServerVersion();
final workoutPlansProvider =
Provider.of<WorkoutPlansProvider>(context, listen: false);
final nutritionPlansProvider =
Provider.of<NutritionPlansProvider>(context, listen: false);
final exercisesProvider =
Provider.of<ExercisesProvider>(context, listen: false);
final galleryProvider =
Provider.of<GalleryProvider>(context, listen: false);
final weightProvider =
Provider.of<BodyWeightProvider>(context, listen: false);
final workoutPlansProvider = Provider.of<WorkoutPlansProvider>(context, listen: false);
final nutritionPlansProvider = Provider.of<NutritionPlansProvider>(context, listen: false);
final exercisesProvider = Provider.of<ExercisesProvider>(context, listen: false);
final galleryProvider = Provider.of<GalleryProvider>(context, listen: false);
final weightProvider = Provider.of<BodyWeightProvider>(context, listen: false);
// Base data
await Future.wait([

View File

@@ -33,8 +33,7 @@ class HomeTabsScreen extends StatefulWidget {
_HomeTabsScreenState createState() => _HomeTabsScreenState();
}
class _HomeTabsScreenState extends State<HomeTabsScreen>
with SingleTickerProviderStateMixin {
class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProviderStateMixin {
int _selectedIndex = 0;
void _onItemTapped(int index) {

View File

@@ -34,16 +34,14 @@ enum NutritionalPlanOptions {
class NutritionalPlanScreen extends StatelessWidget {
static const routeName = '/nutritional-plan-detail';
Future<NutritionalPlan> _loadFullPlan(
BuildContext context, int planId) async {
Future<NutritionalPlan> _loadFullPlan(BuildContext context, int planId) async {
return await Provider.of<NutritionPlansProvider>(context, listen: false)
.fetchAndSetPlanFull(planId);
}
@override
Widget build(BuildContext context) {
final _nutritionalPlan =
ModalRoute.of(context)!.settings.arguments as NutritionalPlan;
final _nutritionalPlan = ModalRoute.of(context)!.settings.arguments as NutritionalPlan;
return Scaffold(
//appBar: getAppBar(nutritionalPlan),
@@ -93,8 +91,7 @@ class NutritionalPlanScreen extends StatelessWidget {
flexibleSpace: FlexibleSpaceBar(
title: Text(_nutritionalPlan.description),
background: Image(
image: AssetImage(
'assets/images/backgrounds/nutritional_plans.jpg'),
image: AssetImage('assets/images/backgrounds/nutritional_plans.jpg'),
fit: BoxFit.cover,
),
),

View File

@@ -46,8 +46,7 @@ class NutritionScreen extends StatelessWidget {
},
),
body: Consumer<NutritionPlansProvider>(
builder: (context, nutritionProvider, child) =>
NutritionalPlansList(nutritionProvider),
builder: (context, nutritionProvider, child) => NutritionalPlansList(nutritionProvider),
),
);
}

View File

@@ -70,8 +70,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
@override
Widget build(BuildContext context) {
final workoutPlan =
ModalRoute.of(context)!.settings.arguments as WorkoutPlan;
final workoutPlan = ModalRoute.of(context)!.settings.arguments as WorkoutPlan;
return Scaffold(
body: CustomScrollView(
@@ -82,8 +81,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
flexibleSpace: FlexibleSpaceBar(
title: Text(workoutPlan.name),
background: Image(
image:
AssetImage('assets/images/backgrounds/workout_plans.jpg'),
image: AssetImage('assets/images/backgrounds/workout_plans.jpg'),
fit: BoxFit.cover,
),
),
@@ -129,8 +127,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
),
FutureBuilder(
future: _loadFullWorkout(context, workoutPlan.id!),
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) =>
SliverList(
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) => SliverList(
delegate: SliverChildListDelegate(
[
snapshot.connectionState == ConnectionState.waiting
@@ -141,8 +138,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
),
)
: Consumer<WorkoutPlansProvider>(
builder: (context, value, child) =>
getBody(workoutPlan),
builder: (context, value, child) => getBody(workoutPlan),
),
],
),

View File

@@ -50,8 +50,7 @@ class WorkoutPlansScreen extends StatelessWidget {
},
),
body: Consumer<WorkoutPlansProvider>(
builder: (context, workoutProvider, child) =>
WorkoutPlansList(workoutProvider),
builder: (context, workoutProvider, child) => WorkoutPlansList(workoutProvider),
),
);
}

View File

@@ -30,10 +30,8 @@ const Color wgerTextMuted = Colors.black38;
const Color wgerBackground = Color(0xfff4f4f6);
// Chart colors
const charts.Color wgerChartPrimaryColor =
charts.Color(r: 0x2a, g: 0x4c, b: 0x7d);
const charts.Color wgerChartSecondaryColor =
charts.Color(r: 0xe6, g: 0x39, b: 0x46);
const charts.Color wgerChartPrimaryColor = charts.Color(r: 0x2a, g: 0x4c, b: 0x7d);
const charts.Color wgerChartSecondaryColor = charts.Color(r: 0xe6, g: 0x39, b: 0x46);
/// Original sizes for the material text theme
/// https://api.flutter.dev/flutter/material/TextTheme-class.html

View File

@@ -43,8 +43,7 @@ class AppDrawer extends StatelessWidget {
onTap: () {
Provider.of<AuthProvider>(context, listen: false).logout();
Provider.of<WorkoutPlansProvider>(context, listen: false).clear();
Provider.of<NutritionPlansProvider>(context, listen: false)
.clear();
Provider.of<NutritionPlansProvider>(context, listen: false).clear();
Provider.of<BodyWeightProvider>(context, listen: false).clear();
Provider.of<GalleryProvider>(context, listen: false).clear();
Navigator.of(context).pop();

View File

@@ -68,8 +68,7 @@ class WgerAboutListTile extends StatelessWidget {
],
),
contentPadding: EdgeInsets.zero,
onTap: () async =>
_launchURL("https://github.com/wger-project", context),
onTap: () async => _launchURL("https://github.com/wger-project", context),
),
SizedBox(height: 10),
ListTile(
@@ -86,9 +85,8 @@ class WgerAboutListTile extends StatelessWidget {
],
),
contentPadding: EdgeInsets.zero,
onTap: () async => _launchURL(
'https://github.com/wger-project/flutter/issues/new/choose',
context),
onTap: () async =>
_launchURL('https://github.com/wger-project/flutter/issues/new/choose', context),
),
SizedBox(height: 10),
ListTile(
@@ -122,8 +120,7 @@ class WgerAboutListTile extends StatelessWidget {
],
),
contentPadding: EdgeInsets.zero,
onTap: () async =>
_launchURL('https://hosted.weblate.org/engage/wger/', context),
onTap: () async => _launchURL('https://hosted.weblate.org/engage/wger/', context),
),
],
);

View File

@@ -47,8 +47,7 @@ class WgerAppBar extends StatelessWidget with PreferredSizeWidget {
title: Text(AppLocalizations.of(context).optionsLabel),
actions: [
TextButton(
child: Text(
MaterialLocalizations.of(context).closeButtonLabel),
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
onPressed: () {
Navigator.of(context).pop();
},
@@ -64,19 +63,11 @@ class WgerAppBar extends StatelessWidget with PreferredSizeWidget {
leading: Icon(Icons.exit_to_app),
title: Text(AppLocalizations.of(context).logout),
onTap: () {
Provider.of<AuthProvider>(context, listen: false)
.logout();
Provider.of<WorkoutPlansProvider>(context,
listen: false)
.clear();
Provider.of<NutritionPlansProvider>(context,
listen: false)
.clear();
Provider.of<BodyWeightProvider>(context,
listen: false)
.clear();
Provider.of<GalleryProvider>(context, listen: false)
.clear();
Provider.of<AuthProvider>(context, listen: false).logout();
Provider.of<WorkoutPlansProvider>(context, listen: false).clear();
Provider.of<NutritionPlansProvider>(context, listen: false).clear();
Provider.of<BodyWeightProvider>(context, listen: false).clear();
Provider.of<GalleryProvider>(context, listen: false).clear();
Navigator.of(context).pop();
Navigator.of(context).pushReplacementNamed('/');
},

View File

@@ -57,16 +57,15 @@ class DashboardCalendarWidget extends StatefulWidget {
DashboardCalendarWidget();
@override
_DashboardCalendarWidgetState createState() =>
_DashboardCalendarWidgetState();
_DashboardCalendarWidgetState createState() => _DashboardCalendarWidgetState();
}
class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
with TickerProviderStateMixin {
late Map<String, List<Event>> _events;
late final ValueNotifier<List<Event>> _selectedEvents;
RangeSelectionMode _rangeSelectionMode = RangeSelectionMode
.toggledOff; // Can be toggled on/off by longpressing a date
RangeSelectionMode _rangeSelectionMode =
RangeSelectionMode.toggledOff; // Can be toggled on/off by longpressing a date
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay;
DateTime? _rangeStart;
@@ -84,8 +83,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
void loadEvents() async {
// Process weight entries
BodyWeightProvider weightProvider =
Provider.of<BodyWeightProvider>(context, listen: false);
BodyWeightProvider weightProvider = Provider.of<BodyWeightProvider>(context, listen: false);
for (var entry in weightProvider.items) {
final date = DateFormatLists.format(entry.date);
@@ -98,8 +96,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
}
// Process workout sessions
WorkoutPlansProvider plans =
Provider.of<WorkoutPlansProvider>(context, listen: false);
WorkoutPlansProvider plans = Provider.of<WorkoutPlansProvider>(context, listen: false);
plans.fetchSessionData().then((entries) {
for (var entry in entries['results']) {
final session = WorkoutSession.fromJson(entry);
@@ -109,8 +106,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
}
var time = '';
if (session.timeStart != null && session.timeEnd != null) {
time =
'(${timeToString(session.timeStart)} - ${timeToString(session.timeEnd)})';
time = '(${timeToString(session.timeStart)} - ${timeToString(session.timeEnd)})';
}
// Add events to lists
@@ -240,12 +236,10 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
title: Text((() {
switch (event.type) {
case EventType.caloriesDiary:
return AppLocalizations.of(context)
.nutritionalDiary;
return AppLocalizations.of(context).nutritionalDiary;
case EventType.session:
return AppLocalizations.of(context)
.workoutSession;
return AppLocalizations.of(context).workoutSession;
case EventType.weight:
return AppLocalizations.of(context).weight;

View File

@@ -41,8 +41,7 @@ import 'package:wger/widgets/workouts/forms.dart';
class DashboardNutritionWidget extends StatefulWidget {
@override
_DashboardNutritionWidgetState createState() =>
_DashboardNutritionWidgetState();
_DashboardNutritionWidgetState createState() => _DashboardNutritionWidgetState();
}
class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
@@ -53,8 +52,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
@override
void initState() {
super.initState();
_plan =
Provider.of<NutritionPlansProvider>(context, listen: false).currentPlan;
_plan = Provider.of<NutritionPlansProvider>(context, listen: false).currentPlan;
_hasContent = _plan != null;
}
@@ -97,8 +95,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
icon: Icon(Icons.history_edu),
color: wgerPrimaryButtonColor,
onPressed: () {
Provider.of<NutritionPlansProvider>(context, listen: false)
.logMealToDiary(meal);
Provider.of<NutritionPlansProvider>(context, listen: false).logMealToDiary(meal);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
@@ -129,8 +126,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
),
),
SizedBox(width: 5),
Text(
'${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'),
Text('${item.amount.toStringAsFixed(0)} ${AppLocalizations.of(context).g}'),
],
),
],
@@ -160,9 +156,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
children: [
ListTile(
title: Text(
_hasContent
? _plan!.description
: AppLocalizations.of(context).labelWorkoutPlan,
_hasContent ? _plan!.description : AppLocalizations.of(context).labelWorkoutPlan,
style: Theme.of(context).textTheme.headline4,
),
subtitle: Text(
@@ -191,8 +185,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
Container(
padding: EdgeInsets.all(15),
height: 180,
child: NutritionalPlanPieChartWidget(
_plan!.nutritionalValues),
child: NutritionalPlanPieChartWidget(_plan!.nutritionalValues),
)
],
),
@@ -209,9 +202,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
TextButton(
child: Text(AppLocalizations.of(context).goToDetailPage),
onPressed: () {
Navigator.of(context).pushNamed(
NutritionalPlanScreen.routeName,
arguments: _plan);
Navigator.of(context)
.pushNamed(NutritionalPlanScreen.routeName, arguments: _plan);
}),
],
),
@@ -334,8 +326,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
icon: Icon(Icons.play_arrow),
color: wgerPrimaryButtonColor,
onPressed: () {
Navigator.of(context)
.pushNamed(GymModeScreen.routeName, arguments: day);
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: day);
},
),
],
@@ -357,8 +348,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
children: [
Text(s.exerciseObj.name),
SizedBox(width: 10),
MutedText(
set.getSmartRepr(s.exerciseObj).join('\n')),
MutedText(set.getSmartRepr(s.exerciseObj).join('\n')),
],
),
SizedBox(height: 10),
@@ -383,9 +373,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
children: [
ListTile(
title: Text(
_hasContent
? _workoutPlan!.name
: AppLocalizations.of(context).labelWorkoutPlan,
_hasContent ? _workoutPlan!.name : AppLocalizations.of(context).labelWorkoutPlan,
style: Theme.of(context).textTheme.headline4,
),
subtitle: Text(
@@ -426,8 +414,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
TextButton(
child: Text(AppLocalizations.of(context).goToDetailPage),
onPressed: () {
Navigator.of(context).pushNamed(WorkoutPlanScreen.routeName,
arguments: _workoutPlan);
Navigator.of(context)
.pushNamed(WorkoutPlanScreen.routeName, arguments: _workoutPlan);
},
),
],

View File

@@ -68,10 +68,7 @@ class ExerciseDetail extends StatelessWidget {
style: Theme.of(context).textTheme.headline6,
),
if (_exercise.musclesSecondary.length > 0)
Text(_exercise.musclesSecondary
.map((e) => e.name)
.toList()
.join('\n')),
Text(_exercise.musclesSecondary.map((e) => e.name).toList().join('\n')),
if (_exercise.musclesSecondary.length == 0) Text('-/-'),
SizedBox(height: 8),

View File

@@ -113,8 +113,7 @@ class _ImageFormState extends State<ImageForm> {
_showPicker(ImageSource.camera);
},
leading: Icon(Icons.photo_camera),
title:
Text(AppLocalizations.of(context).takePicture),
title: Text(AppLocalizations.of(context).takePicture),
),
ListTile(
onTap: () {
@@ -122,8 +121,7 @@ class _ImageFormState extends State<ImageForm> {
_showPicker(ImageSource.gallery);
},
leading: Icon(Icons.photo_library),
title: Text(AppLocalizations.of(context)
.chooseFromLibrary))
title: Text(AppLocalizations.of(context).chooseFromLibrary))
],
),
);
@@ -135,8 +133,7 @@ class _ImageFormState extends State<ImageForm> {
),
TextFormField(
key: Key('field-date'),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).date),
decoration: InputDecoration(labelText: AppLocalizations.of(context).date),
controller: dateController,
onTap: () async {
// Stop keyboard from appearing
@@ -165,8 +162,7 @@ class _ImageFormState extends State<ImageForm> {
),
TextFormField(
key: Key('field-description'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).description),
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
minLines: 3,
maxLines: 10,
controller: descriptionController,

View File

@@ -53,8 +53,7 @@ class Gallery extends StatelessWidget {
child: Column(
children: [
Text(
DateFormat.yMd(
Localizations.localeOf(context).languageCode)
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(currentImage.date),
style: Theme.of(context).textTheme.headline5,
),
@@ -71,8 +70,7 @@ class Gallery extends StatelessWidget {
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
Provider.of<GalleryProvider>(context,
listen: false)
Provider.of<GalleryProvider>(context, listen: false)
.deleteImage(currentImage);
Navigator.of(context).pop();
}),

View File

@@ -47,10 +47,7 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
data: [
[AppLocalizations.of(context).protein, _nutritionalValues.protein],
[AppLocalizations.of(context).fat, _nutritionalValues.fat],
[
AppLocalizations.of(context).carbohydrates,
_nutritionalValues.carbohydrates
],
[AppLocalizations.of(context).carbohydrates, _nutritionalValues.carbohydrates],
],
labelAccessorFn: (List<dynamic> row, _) =>
'${row[0]}\n${row[1].toStringAsFixed(0)}${AppLocalizations.of(context).g}',

View File

@@ -52,8 +52,7 @@ class MealForm extends StatelessWidget {
children: [
TextFormField(
key: Key('field-time'),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).time),
decoration: InputDecoration(labelText: AppLocalizations.of(context).time),
controller: _timeController,
onTap: () async {
// Stop keyboard from appearing
@@ -83,12 +82,9 @@ class MealForm extends StatelessWidget {
try {
_meal.id == null
? Provider.of<NutritionPlansProvider>(context,
listen: false)
? Provider.of<NutritionPlansProvider>(context, listen: false)
.addMeal(_meal, _planId)
: Provider.of<NutritionPlansProvider>(context,
listen: false)
.editMeal(_meal);
: Provider.of<NutritionPlansProvider>(context, listen: false).editMeal(_meal);
} on WgerHttpException catch (error) {
showHttpExceptionErrorDialog(error, context);
} catch (error) {
@@ -128,12 +124,10 @@ class MealItemForm extends StatelessWidget {
TypeAheadFormField(
textFieldConfiguration: TextFieldConfiguration(
controller: this._ingredientController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).ingredient),
decoration: InputDecoration(labelText: AppLocalizations.of(context).ingredient),
),
suggestionsCallback: (pattern) async {
return await Provider.of<NutritionPlansProvider>(context,
listen: false)
return await Provider.of<NutritionPlansProvider>(context, listen: false)
.searchIngredient(
pattern,
Localizations.localeOf(context).languageCode,
@@ -160,8 +154,7 @@ class MealItemForm extends StatelessWidget {
},
),
TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).weight),
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
controller: _amountController,
keyboardType: TextInputType.number,
onFieldSubmitted: (_) {},
@@ -222,8 +215,7 @@ class PlanForm extends StatelessWidget {
// Description
TextFormField(
key: Key('field-description'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).description),
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
controller: _descriptionController,
onFieldSubmitted: (_) {},
onSaved: (newValue) {
@@ -244,13 +236,10 @@ class PlanForm extends StatelessWidget {
// Save to DB
try {
if (_plan.id != null) {
await Provider.of<NutritionPlansProvider>(context,
listen: false)
.editPlan(_plan);
await Provider.of<NutritionPlansProvider>(context, listen: false).editPlan(_plan);
Navigator.of(context).pop();
} else {
_plan = await Provider.of<NutritionPlansProvider>(context,
listen: false)
_plan = await Provider.of<NutritionPlansProvider>(context, listen: false)
.addPlan(_plan);
Navigator.of(context).pushReplacementNamed(
NutritionalPlanScreen.routeName,

View File

@@ -54,8 +54,7 @@ class _MealWidgetState extends State<MealWidget> {
child: Card(
child: Column(
children: [
DismissibleMealHeader(_expanded, _toggleExpanded,
meal: widget._meal),
DismissibleMealHeader(_expanded, _toggleExpanded, meal: widget._meal),
if (_expanded)
Row(
mainAxisSize: MainAxisSize.max,
@@ -64,8 +63,7 @@ class _MealWidgetState extends State<MealWidget> {
IconButton(
onPressed: () {
// Delete the meal
Provider.of<NutritionPlansProvider>(context,
listen: false)
Provider.of<NutritionPlansProvider>(context, listen: false)
.deleteMeal(widget._meal);
// and inform the user
@@ -90,8 +88,7 @@ class _MealWidgetState extends State<MealWidget> {
icon: const Icon(Icons.history_edu),
color: Colors.white,
onPressed: () {
Provider.of<NutritionPlansProvider>(context,
listen: false)
Provider.of<NutritionPlansProvider>(context, listen: false)
.logMealToDiary(widget._meal);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
@@ -152,9 +149,7 @@ class _MealWidgetState extends State<MealWidget> {
],
),
),
...widget._meal.mealItems
.map((item) => MealItemWidget(item, _expanded))
.toList(),
...widget._meal.mealItems.map((item) => MealItemWidget(item, _expanded)).toList(),
OutlinedButton(
child: Text(AppLocalizations.of(context).addIngredient),
onPressed: () {
@@ -215,8 +210,7 @@ class MealItemWidget extends StatelessWidget {
iconSize: ICON_SIZE_SMALL,
onPressed: () {
// Delete the meal item
Provider.of<NutritionPlansProvider>(context,
listen: false)
Provider.of<NutritionPlansProvider>(context, listen: false)
.deleteMealItem(_item);
// and inform the user
@@ -297,8 +291,7 @@ class DismissibleMealHeader extends StatelessWidget {
),
IconButton(
visualDensity: VisualDensity.compact,
icon:
_expanded ? Icon(Icons.unfold_less) : Icon(Icons.unfold_more),
icon: _expanded ? Icon(Icons.unfold_less) : Icon(Icons.unfold_more),
onPressed: () {
_toggle();
},
@@ -327,8 +320,7 @@ class DismissibleMealHeader extends StatelessWidget {
confirmDismiss: (direction) async {
// Delete
if (direction == DismissDirection.startToEnd) {
Provider.of<NutritionPlansProvider>(context, listen: false)
.logMealToDiary(_meal);
Provider.of<NutritionPlansProvider>(context, listen: false).logMealToDiary(_meal);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(

View File

@@ -89,8 +89,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
Text(nutritionalValues.energy.toStringAsFixed(0)),
Text(nutritionalValues.protein.toStringAsFixed(0)),
Text(nutritionalValues.carbohydrates.toStringAsFixed(0)),
Text(nutritionalValues.carbohydratesSugar
.toStringAsFixed(0)),
Text(nutritionalValues.carbohydratesSugar.toStringAsFixed(0)),
Text(nutritionalValues.fat.toStringAsFixed(0)),
Text(nutritionalValues.fatSaturated.toStringAsFixed(0)),
Text(nutritionalValues.fibres.toStringAsFixed(0)),
@@ -122,8 +121,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
Container(
padding: EdgeInsets.all(15),
height: 220,
child:
NutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan),
child: NutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan),
),
Container(
height: 200,
@@ -181,8 +179,7 @@ class NutritionDiaryEntry extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(date),
DateFormat.yMd(Localizations.localeOf(context).languageCode).format(date),
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(values.energy.toStringAsFixed(0)),

View File

@@ -42,13 +42,11 @@ class NutritionalPlansList extends StatelessWidget {
builder: (BuildContext contextDialog) {
return AlertDialog(
content: Text(
AppLocalizations.of(context)
.confirmDelete(currentPlan.description),
AppLocalizations.of(context).confirmDelete(currentPlan.description),
),
actions: [
TextButton(
child: Text(MaterialLocalizations.of(context)
.cancelButtonLabel),
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
onPressed: () => Navigator.of(contextDialog).pop(),
),
TextButton(
@@ -67,8 +65,7 @@ class NutritionalPlansList extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
AppLocalizations.of(context)
.successfullyDeleted,
AppLocalizations.of(context).successfullyDeleted,
textAlign: TextAlign.center,
),
),

View File

@@ -43,8 +43,7 @@ class WeightChartWidget extends StatelessWidget {
],
defaultRenderer: new charts.LineRendererConfig(includePoints: true),
primaryMeasureAxis: new charts.NumericAxisSpec(
tickProviderSpec:
new charts.BasicNumericTickProviderSpec(zeroBound: false),
tickProviderSpec: new charts.BasicNumericTickProviderSpec(zeroBound: false),
),
);
}

View File

@@ -28,8 +28,7 @@ import 'package:wger/widgets/weight/forms.dart';
class WeightEntriesList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _weightProvider =
Provider.of<BodyWeightProvider>(context, listen: false);
final _weightProvider = Provider.of<BodyWeightProvider>(context, listen: false);
return Column(
children: [
@@ -107,8 +106,7 @@ class WeightEntriesList extends StatelessWidget {
child: ListTile(
title: Text('${currentEntry.weight} kg'),
subtitle: Text(
DateFormat.yMd(
Localizations.localeOf(context).languageCode)
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(currentEntry.date),
),
),

View File

@@ -35,8 +35,7 @@ class WeightForm extends StatelessWidget {
WeightForm([WeightEntry? weightEntry]) {
this._weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
weightController.text =
_weightEntry.id == null ? '' : _weightEntry.weight.toString();
weightController.text = _weightEntry.id == null ? '' : _weightEntry.weight.toString();
dateController.text = toDate(_weightEntry.date)!;
}
@@ -48,8 +47,7 @@ class WeightForm extends StatelessWidget {
children: [
// Weight date
TextFormField(
decoration:
InputDecoration(labelText: AppLocalizations.of(context).date),
decoration: InputDecoration(labelText: AppLocalizations.of(context).date),
controller: dateController,
onTap: () async {
// Stop keyboard from appearing
@@ -68,8 +66,7 @@ class WeightForm extends StatelessWidget {
}
// if the date is known, don't allow it
return Provider.of<BodyWeightProvider>(context, listen: false)
.findByDate(day) ==
return Provider.of<BodyWeightProvider>(context, listen: false).findByDate(day) ==
null
? true
: false;
@@ -85,8 +82,7 @@ class WeightForm extends StatelessWidget {
// Weight
TextFormField(
decoration:
InputDecoration(labelText: AppLocalizations.of(context).weight),
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
controller: weightController,
keyboardType: TextInputType.number,
onSaved: (newValue) {
@@ -117,11 +113,9 @@ class WeightForm extends StatelessWidget {
// Save the entry on the server
try {
_weightEntry.id == null
? await Provider.of<BodyWeightProvider>(context,
listen: false)
? await Provider.of<BodyWeightProvider>(context, listen: false)
.addEntry(_weightEntry)
: await Provider.of<BodyWeightProvider>(context,
listen: false)
: await Provider.of<BodyWeightProvider>(context, listen: false)
.editEntry(_weightEntry);
} on WgerHttpException catch (error) {
showHttpExceptionErrorDialog(error, context);

View File

@@ -56,8 +56,7 @@ class LogChartWidget extends StatelessWidget {
}),
],
primaryMeasureAxis: new charts.NumericAxisSpec(
tickProviderSpec:
new charts.BasicNumericTickProviderSpec(zeroBound: false),
tickProviderSpec: new charts.BasicNumericTickProviderSpec(zeroBound: false),
),
behaviors: [
new charts.SeriesLegend(

View File

@@ -61,8 +61,7 @@ class SettingWidget extends StatelessWidget {
content: ExerciseDetail(setting.exerciseObj),
actions: [
TextButton(
child: Text(
MaterialLocalizations.of(context).closeButtonLabel),
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
onPressed: () {
Navigator.of(context).pop();
},
@@ -129,8 +128,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
icon: Icon(Icons.delete),
iconSize: ICON_SIZE_SMALL,
onPressed: () {
Provider.of<WorkoutPlansProvider>(context, listen: false)
.deleteSet(set);
Provider.of<WorkoutPlansProvider>(context, listen: false).deleteSet(set);
},
),
],
@@ -157,8 +155,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
children: [
IconButton(
onPressed: () {
Provider.of<WorkoutPlansProvider>(context, listen: false)
.deleteDay(
Provider.of<WorkoutPlansProvider>(context, listen: false).deleteDay(
widget._day,
);
},
@@ -189,8 +186,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
DayFormWidget(
Provider.of<WorkoutPlansProvider>(context,
listen: false)
Provider.of<WorkoutPlansProvider>(context, listen: false)
.findById(widget._day.workoutId),
widget._day),
hasListView: true,
@@ -263,14 +259,12 @@ class DayHeaderDismissible extends StatelessWidget {
style: Theme.of(context).textTheme.headline5,
overflow: TextOverflow.ellipsis,
),
Text(_day.getDaysTextTranslated(
Localizations.localeOf(context).languageCode)),
Text(_day.getDaysTextTranslated(Localizations.localeOf(context).languageCode)),
],
),
),
IconButton(
icon:
_expanded ? Icon(Icons.unfold_less) : Icon(Icons.unfold_more),
icon: _expanded ? Icon(Icons.unfold_less) : Icon(Icons.unfold_more),
onPressed: () {
_toggle();
},
@@ -299,8 +293,7 @@ class DayHeaderDismissible extends StatelessWidget {
confirmDismiss: (direction) async {
// Delete day
if (direction == DismissDirection.startToEnd) {
Navigator.of(context)
.pushNamed(GymModeScreen.routeName, arguments: _day);
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: _day);
}
return false;
},

View File

@@ -41,8 +41,7 @@ class WorkoutForm extends StatelessWidget {
WorkoutForm(this._plan);
final TextEditingController workoutNameController = TextEditingController();
final TextEditingController workoutDescriptionController =
TextEditingController();
final TextEditingController workoutDescriptionController = TextEditingController();
@override
Widget build(BuildContext context) {
@@ -57,17 +56,13 @@ class WorkoutForm extends StatelessWidget {
children: [
TextFormField(
key: Key('field-name'),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).name),
decoration: InputDecoration(labelText: AppLocalizations.of(context).name),
controller: workoutNameController,
validator: (value) {
const minLength = 5;
const maxLength = 100;
if (value!.isEmpty ||
value.length < minLength ||
value.length > maxLength) {
return AppLocalizations.of(context)
.enterCharacters(minLength, maxLength);
if (value!.isEmpty || value.length < minLength || value.length > maxLength) {
return AppLocalizations.of(context).enterCharacters(minLength, maxLength);
}
return null;
},
@@ -78,8 +73,7 @@ class WorkoutForm extends StatelessWidget {
),
TextFormField(
key: Key('field-description'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).description),
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
minLines: 3,
maxLines: 10,
controller: workoutDescriptionController,
@@ -87,8 +81,7 @@ class WorkoutForm extends StatelessWidget {
const minLength = 0;
const maxLength = 1000;
if (value!.length > maxLength) {
return AppLocalizations.of(context)
.enterCharacters(minLength, maxLength);
return AppLocalizations.of(context).enterCharacters(minLength, maxLength);
}
return null;
},
@@ -110,12 +103,10 @@ class WorkoutForm extends StatelessWidget {
// Save to DB
if (_plan.id != null) {
await Provider.of<WorkoutPlansProvider>(context, listen: false)
.editWorkout(_plan);
await Provider.of<WorkoutPlansProvider>(context, listen: false).editWorkout(_plan);
Navigator.of(context).pop();
} else {
_plan = await Provider.of<WorkoutPlansProvider>(context,
listen: false)
_plan = await Provider.of<WorkoutPlansProvider>(context, listen: false)
.addWorkout(_plan);
Navigator.of(context).pushReplacementNamed(
WorkoutPlanScreen.routeName,
@@ -203,11 +194,8 @@ class _DayFormWidgetState extends State<DayFormWidget> {
validator: (value) {
const minLength = 5;
const maxLength = 100;
if (value!.isEmpty ||
value.length < minLength ||
value.length > maxLength) {
return AppLocalizations.of(context)
.enterCharacters(minLength, maxLength);
if (value!.isEmpty || value.length < minLength || value.length > maxLength) {
return AppLocalizations.of(context).enterCharacters(minLength, maxLength);
}
if (widget._day.daysOfWeek.length == 0) {
@@ -217,9 +205,7 @@ class _DayFormWidgetState extends State<DayFormWidget> {
},
),
SizedBox(height: 10),
...Day.weekdays.keys
.map((dayNr) => DayCheckbox(dayNr, widget._day))
.toList(),
...Day.weekdays.keys.map((dayNr) => DayCheckbox(dayNr, widget._day)).toList(),
ElevatedButton(
key: Key(SUBMIT_BUTTON_KEY_NAME),
child: Text(AppLocalizations.of(context).save),
@@ -231,14 +217,12 @@ class _DayFormWidgetState extends State<DayFormWidget> {
try {
if (widget._day.id == null) {
Provider.of<WorkoutPlansProvider>(context, listen: false)
.addDay(
Provider.of<WorkoutPlansProvider>(context, listen: false).addDay(
widget._day,
widget.workout,
);
} else {
Provider.of<WorkoutPlansProvider>(context, listen: false)
.editDay(
Provider.of<WorkoutPlansProvider>(context, listen: false).editDay(
widget._day,
);
}
@@ -316,11 +300,9 @@ class _SetFormWidgetState extends State<SetFormWidget> {
setting.order = order;
setting.exercise = exercise;
setting.weightUnit =
Provider.of<WorkoutPlansProvider>(context, listen: false)
.defaultWeightUnit;
Provider.of<WorkoutPlansProvider>(context, listen: false).defaultWeightUnit;
setting.repetitionUnit =
Provider.of<WorkoutPlansProvider>(context, listen: false)
.defaultRepetitionUnit;
Provider.of<WorkoutPlansProvider>(context, listen: false).defaultRepetitionUnit;
widget._set.settings.add(setting);
}
@@ -339,8 +321,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
child: Column(
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(AppLocalizations.of(context)
.nrOfSets(_currentSetSliderValue.round())),
Text(AppLocalizations.of(context).nrOfSets(_currentSetSliderValue.round())),
Slider(
value: _currentSetSliderValue,
min: 1,
@@ -389,18 +370,14 @@ class _SetFormWidgetState extends State<SetFormWidget> {
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(AppLocalizations.of(context)
.selectExercises),
Text(AppLocalizations.of(context).selectExercises),
SizedBox(height: 10),
Text(AppLocalizations.of(context)
.sameRepetitions)
Text(AppLocalizations.of(context).sameRepetitions)
],
),
actions: [
TextButton(
child: Text(
MaterialLocalizations.of(context)
.closeButtonLabel),
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
onPressed: () {
Navigator.of(context).pop();
},
@@ -414,8 +391,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
),
),
suggestionsCallback: (pattern) async {
return await Provider.of<ExercisesProvider>(context,
listen: false)
return await Provider.of<ExercisesProvider>(context, listen: false)
.searchExercise(
pattern,
Localizations.localeOf(context).languageCode,
@@ -424,14 +400,12 @@ class _SetFormWidgetState extends State<SetFormWidget> {
itemBuilder: (context, suggestion) {
final result = suggestion! as Map;
final exercise =
Provider.of<ExercisesProvider>(context, listen: false)
.findById(result['data']['id']);
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
.findById(result['data']['id']);
return ListTile(
leading: Container(
width: 45,
child:
ExerciseImageWidget(image: exercise.getMainImage),
child: ExerciseImageWidget(image: exercise.getMainImage),
),
title: Text(exercise.name),
subtitle: Text(
@@ -443,9 +417,8 @@ class _SetFormWidgetState extends State<SetFormWidget> {
},
onSuggestionSelected: (suggestion) {
final result = suggestion! as Map;
final exercise =
Provider.of<ExercisesProvider>(context, listen: false)
.findById(result['data']['id']);
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
.findById(result['data']['id']);
addExercise(exercise);
this._exercisesController.text = '';
},
@@ -460,8 +433,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
.where((s) => s.weight == null && s.reps == null)
.length ==
widget._set.settings.length) {
return AppLocalizations.of(context)
.enterRepetitionsOrWeight;
return AppLocalizations.of(context).enterRepetitionsOrWeight;
}
return null;
},
@@ -469,9 +441,8 @@ class _SetFormWidgetState extends State<SetFormWidget> {
),
SizedBox(height: 10),
...widget._set.exercisesObj.map((exercise) {
final settings = widget._set.settings
.where((e) => e.exerciseObj.id == exercise.id)
.toList();
final settings =
widget._set.settings.where((e) => e.exerciseObj.id == exercise.id).toList();
return ExerciseSetting(
exercise,
@@ -491,25 +462,22 @@ class _SetFormWidgetState extends State<SetFormWidget> {
}
_formKey.currentState!.save();
final workoutProvider = Provider.of<WorkoutPlansProvider>(
context,
listen: false);
final workoutProvider =
Provider.of<WorkoutPlansProvider>(context, listen: false);
// Save set
Set setDb = await workoutProvider.addSet(widget._set);
widget._set.id = setDb.id;
// Remove unused settings
widget._set.settings
.removeWhere((s) => s.weight == null && s.reps == null);
widget._set.settings.removeWhere((s) => s.weight == null && s.reps == null);
// Save remaining settings
for (var setting in widget._set.settings) {
setting.setId = setDb.id!;
setting.comment = '';
Setting settingDb =
await workoutProvider.addSetting(setting);
Setting settingDb = await workoutProvider.addSetting(setting);
setting.id = settingDb.id;
}
@@ -585,8 +553,7 @@ class ExerciseSetting extends StatelessWidget {
SizedBox(width: 4),
Flexible(
flex: 3,
child:
WeightUnitInputWidget(setting, key: Key(i.toString())),
child: WeightUnitInputWidget(setting, key: Key(i.toString())),
),
],
),
@@ -833,8 +800,7 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
return DropdownButtonFormField(
value: selectedWeightUnit,
decoration:
InputDecoration(labelText: AppLocalizations.of(context).weightUnit),
decoration: InputDecoration(labelText: AppLocalizations.of(context).weightUnit),
onChanged: (WeightUnit? newValue) {
setState(() {
selectedWeightUnit = newValue!;
@@ -861,8 +827,7 @@ class RepetitionUnitInputWidget extends StatefulWidget {
RepetitionUnitInputWidget(this._setting);
@override
_RepetitionUnitInputWidgetState createState() =>
_RepetitionUnitInputWidgetState();
_RepetitionUnitInputWidgetState createState() => _RepetitionUnitInputWidgetState();
}
class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
@@ -872,8 +837,7 @@ class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
return DropdownButtonFormField(
value: selectedWeightUnit,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).repetitionUnit),
decoration: InputDecoration(labelText: AppLocalizations.of(context).repetitionUnit),
isDense: true,
onChanged: (RepetitionUnit? newValue) {
setState(() {

View File

@@ -87,8 +87,8 @@ class _GymModeState extends State<GymMode> {
for (var set in widget._workoutDay.sets) {
var firstPage = true;
for (var setting in set.settingsComputed) {
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
.findById(setting.exerciseId);
final exercise =
Provider.of<ExercisesProvider>(context, listen: false).findById(setting.exerciseId);
if (firstPage) {
_exercisePages[exercise.name] = currentPage;
@@ -107,10 +107,8 @@ class _GymModeState extends State<GymMode> {
// Returns the list of exercise overview, sets and pause pages
List<Widget> getContent() {
final exerciseProvider =
Provider.of<ExercisesProvider>(context, listen: false);
final workoutProvider =
Provider.of<WorkoutPlansProvider>(context, listen: false);
final exerciseProvider = Provider.of<ExercisesProvider>(context, listen: false);
final workoutProvider = Provider.of<WorkoutPlansProvider>(context, listen: false);
var currentElement = 1;
List<Widget> out = [];
@@ -200,10 +198,7 @@ class StartPage extends StatelessWidget {
s.exerciseObj.name,
style: Theme.of(context).textTheme.headline6,
),
...set
.getSmartRepr(s.exerciseObj)
.map((e) => Text(e))
.toList(),
...set.getSmartRepr(s.exerciseObj).map((e) => Text(e)).toList(),
SizedBox(height: 15),
],
);
@@ -218,8 +213,7 @@ class StartPage extends StatelessWidget {
ElevatedButton(
child: Text(AppLocalizations.of(context).start),
onPressed: () {
_controller.nextPage(
duration: Duration(milliseconds: 200), curve: Curves.bounceIn);
_controller.nextPage(duration: Duration(milliseconds: 200), curve: Curves.bounceIn);
},
),
NavigationFooter(
@@ -347,8 +341,7 @@ class _LogPageState extends State<LogPage> {
),
onPressed: () {
try {
double newValue =
double.parse(_weightController.text) - (2 * minPlateWeight);
double newValue = double.parse(_weightController.text) - (2 * minPlateWeight);
if (newValue > 0) {
setState(() {
widget._log.weight = newValue;
@@ -396,8 +389,7 @@ class _LogPageState extends State<LogPage> {
),
onPressed: () {
try {
double newValue =
double.parse(_weightController.text) + (2 * minPlateWeight);
double newValue = double.parse(_weightController.text) + (2 * minPlateWeight);
setState(() {
widget._log.weight = newValue;
_weightController.text = newValue.toString();
@@ -468,8 +460,7 @@ class _LogPageState extends State<LogPage> {
// Save the entry on the server
try {
await Provider.of<WorkoutPlansProvider>(context, listen: false)
.addLog(widget._log);
await Provider.of<WorkoutPlansProvider>(context, listen: false).addLog(widget._log);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: Duration(seconds: 2), // default is 4
@@ -503,14 +494,11 @@ class _LogPageState extends State<LogPage> {
style: Theme.of(context).textTheme.headline6,
textAlign: TextAlign.center,
),
...widget._workoutPlan
.filterLogsByExercise(widget._exercise, unique: true)
.map((log) {
...widget._workoutPlan.filterLogsByExercise(widget._exercise, unique: true).map((log) {
return ListTile(
title: Text(log.singleLogRepTextNoNl),
subtitle: Text(
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(log.date)),
subtitle:
Text(DateFormat.yMd(Localizations.localeOf(context).languageCode).format(log.date)),
trailing: Icon(Icons.copy),
onTap: () {
setState(() {
@@ -563,8 +551,7 @@ class _LogPageState extends State<LogPage> {
shape: BoxShape.circle,
),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 3),
padding: const EdgeInsets.symmetric(horizontal: 3),
child: SizedBox(
height: 35,
width: 35,
@@ -572,8 +559,7 @@ class _LogPageState extends State<LogPage> {
alignment: Alignment.center,
child: Text(
key.toString(),
style: TextStyle(
fontWeight: FontWeight.bold),
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
@@ -586,8 +572,7 @@ class _LogPageState extends State<LogPage> {
.toList()
],
)
: MutedText(
AppLocalizations.of(context).plateCalculatorNotDivisible),
: MutedText(AppLocalizations.of(context).plateCalculatorNotDivisible),
),
SizedBox(height: 3),
],
@@ -612,16 +597,11 @@ class _LogPageState extends State<LogPage> {
),
SizedBox(height: 10),
Expanded(
child: (widget._workoutPlan
.filterLogsByExercise(widget._exercise)
.length >
0)
child: (widget._workoutPlan.filterLogsByExercise(widget._exercise).length > 0)
? getPastLogs()
: Container()),
// Only show calculator for barbell
if (widget._log.exerciseObj.equipment
.map((e) => e.id)
.contains(ID_EQUIPMENT_BARBELL))
if (widget._log.exerciseObj.equipment.map((e) => e.id).contains(ID_EQUIPMENT_BARBELL))
getPlates(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
@@ -682,9 +662,7 @@ class ExerciseOverview extends StatelessWidget {
child: ListView(
scrollDirection: Axis.horizontal,
children: [
..._exercise.images
.map((e) => ExerciseImageWidget(image: e))
.toList(),
..._exercise.images.map((e) => ExerciseImageWidget(image: e)).toList(),
],
),
),
@@ -810,8 +788,7 @@ class _SessionPageState extends State<SessionPage> {
onFieldSubmitted: (_) {},
onTap: () async {
// Stop keyboard from appearing
FocusScope.of(context)
.requestFocus(new FocusNode());
FocusScope.of(context).requestFocus(new FocusNode());
// Open time picker
var pickedTime = await showTimePicker(
@@ -820,21 +797,17 @@ class _SessionPageState extends State<SessionPage> {
);
if (pickedTime != null) {
timeStartController.text =
timeToString(pickedTime)!;
timeStartController.text = timeToString(pickedTime)!;
}
},
onSaved: (newValue) {
_session.timeStart = stringToTime(newValue);
},
validator: (_) {
TimeOfDay startTime =
stringToTime(timeStartController.text);
TimeOfDay endTime =
stringToTime(timeEndController.text);
TimeOfDay startTime = stringToTime(timeStartController.text);
TimeOfDay endTime = stringToTime(timeEndController.text);
if (startTime.isAfter(endTime)) {
return AppLocalizations.of(context)
.timeStartAhead;
return AppLocalizations.of(context).timeStartAhead;
}
return null;
}),
@@ -842,8 +815,8 @@ class _SessionPageState extends State<SessionPage> {
SizedBox(width: 10),
Flexible(
child: TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).timeEnd),
decoration:
InputDecoration(labelText: AppLocalizations.of(context).timeEnd),
controller: timeEndController,
onFieldSubmitted: (_) {},
onTap: () async {
@@ -877,8 +850,7 @@ class _SessionPageState extends State<SessionPage> {
// Save the entry on the server
try {
await Provider.of<WorkoutPlansProvider>(context,
listen: false)
await Provider.of<WorkoutPlansProvider>(context, listen: false)
.addSession(_session);
Navigator.of(context).pop();
} on WgerHttpException catch (error) {
@@ -971,10 +943,7 @@ class _TimerWidgetState extends State<TimerWidget> {
child: Center(
child: Text(
DateFormat('m:ss').format(today.add(Duration(seconds: _seconds))),
style: Theme.of(context)
.textTheme
.headline1!
.copyWith(color: wgerPrimaryColor),
style: Theme.of(context).textTheme.headline1!.copyWith(color: wgerPrimaryColor),
),
),
),

View File

@@ -34,8 +34,7 @@ class ExerciseLogChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _workoutPlansData =
Provider.of<WorkoutPlansProvider>(context, listen: false);
final _workoutPlansData = Provider.of<WorkoutPlansProvider>(context, listen: false);
final _workout = _workoutPlansData.currentPlan;
Future<Map<String, dynamic>> _getChartEntries(BuildContext context) async {
@@ -44,8 +43,7 @@ class ExerciseLogChart extends StatelessWidget {
return FutureBuilder(
future: _getChartEntries(context),
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) =>
Container(
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) => Container(
height: 150,
child: snapshot.connectionState == ConnectionState.waiting
? Center(child: CircularProgressIndicator())
@@ -68,8 +66,7 @@ class DayLogWidget extends StatelessWidget {
child: Column(
children: [
Text(
DateFormat.yMd(Localizations.localeOf(context).languageCode)
.format(_date),
DateFormat.yMd(Localizations.localeOf(context).languageCode).format(_date),
style: Theme.of(context).textTheme.headline5,
),
if (_session != null) Text('Session data here'),
@@ -80,9 +77,7 @@ class DayLogWidget extends StatelessWidget {
exercise.name,
style: Theme.of(context).textTheme.headline6,
),
..._exerciseData[exercise]!
.map((log) => Text(log.singleLogRepTextNoNl))
.toList(),
..._exerciseData[exercise]!.map((log) => Text(log.singleLogRepTextNoNl)).toList(),
ExerciseLogChart(exercise, _date),
SizedBox(height: 30),
],

View File

@@ -57,9 +57,7 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
padding: const EdgeInsets.all(15),
child: Text(widget._workoutPlan.description),
),
...widget._workoutPlan.days
.map((workoutDay) => WorkoutDayWidget(workoutDay))
.toList(),
...widget._workoutPlan.days.map((workoutDay) => WorkoutDayWidget(workoutDay)).toList(),
Column(
children: [
ElevatedButton(

View File

@@ -44,13 +44,11 @@ class WorkoutPlansList extends StatelessWidget {
builder: (BuildContext contextDialog) {
return AlertDialog(
content: Text(
AppLocalizations.of(context)
.confirmDelete(currentWorkout.name),
AppLocalizations.of(context).confirmDelete(currentWorkout.name),
),
actions: [
TextButton(
child: Text(MaterialLocalizations.of(context)
.cancelButtonLabel),
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
onPressed: () => Navigator.of(contextDialog).pop(),
),
TextButton(
@@ -60,8 +58,7 @@ class WorkoutPlansList extends StatelessWidget {
),
onPressed: () {
// Confirmed, delete the workout
Provider.of<WorkoutPlansProvider>(context,
listen: false)
Provider.of<WorkoutPlansProvider>(context, listen: false)
.deleteWorkout(currentWorkout.id!);
// Close the popup
@@ -71,8 +68,7 @@ class WorkoutPlansList extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
AppLocalizations.of(context)
.successfullyDeleted,
AppLocalizations.of(context).successfullyDeleted,
textAlign: TextAlign.center,
),
),
@@ -103,8 +99,8 @@ class WorkoutPlansList extends StatelessWidget {
onTap: () {
_workoutProvider.setCurrentPlan(currentWorkout.id!);
Navigator.of(context).pushNamed(WorkoutPlanScreen.routeName,
arguments: currentWorkout);
Navigator.of(context)
.pushNamed(WorkoutPlanScreen.routeName, arguments: currentWorkout);
},
title: Text(currentWorkout.name),
subtitle: Text(

View File

@@ -24,8 +24,7 @@ import 'package:wger/providers/auth.dart';
import 'package:wger/screens/auth_screen.dart';
void main() {
testWidgets('Test the widgets on the auth screen, login mode',
(WidgetTester tester) async {
testWidgets('Test the widgets on the auth screen, login mode', (WidgetTester tester) async {
// Wrap screen in material app so that the media query gets a context
await tester.pumpWidget(
MultiProvider(
@@ -81,8 +80,7 @@ void main() {
// either the provider wasn't found or, if the call was removed, the
// localization data could not be loaded...
testWidgets('Test the widgets on the auth screen, registration',
(WidgetTester tester) async {
testWidgets('Test the widgets on the auth screen, registration', (WidgetTester tester) async {
// Wrap screen in material app so that the media query gets a context
await tester.pumpWidget(MaterialApp(home: AuthScreen()));
await tester.tap(find.byKey(Key('toggleActionButton')));

View File

@@ -46,20 +46,16 @@ void main() {
provider.makeUrl('endpoint', query: {'a': '2', 'b': 'c'}),
);
expect(
Uri.https(
'localhost', '/api/v2/endpoint/log_data/', {'a': '2', 'b': 'c'}),
provider.makeUrl('endpoint',
objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}),
Uri.https('localhost', '/api/v2/endpoint/log_data/', {'a': '2', 'b': 'c'}),
provider.makeUrl('endpoint', objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}),
);
expect(
Uri.https('localhost', '/api/v2/endpoint/42/', {'a': '2', 'b': 'c'}),
provider.makeUrl('endpoint', id: 42, query: {'a': '2', 'b': 'c'}),
);
expect(
Uri.https(
'localhost', '/api/v2/endpoint/42/log_data/', {'a': '2', 'b': 'c'}),
provider.makeUrl('endpoint',
id: 42, objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}),
Uri.https('localhost', '/api/v2/endpoint/42/log_data/', {'a': '2', 'b': 'c'}),
provider.makeUrl('endpoint', id: 42, objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}),
);
});
});

View File

@@ -36,71 +36,49 @@ class MockClient extends _i1.Mock implements _i5.Client {
@override
_i6.Future<_i2.Response> head(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(Invocation.method(#head, [url], {#headers: headers}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<_i2.Response> get(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(Invocation.method(#get, [url], {#headers: headers}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<_i2.Response> post(Uri? url,
{Map<String, String>? headers,
Object? body,
_i7.Encoding? encoding}) =>
{Map<String, String>? headers, Object? body, _i7.Encoding? encoding}) =>
(super.noSuchMethod(
Invocation.method(#post, [url],
{#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
Invocation.method(#post, [url], {#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<_i2.Response> put(Uri? url,
{Map<String, String>? headers,
Object? body,
_i7.Encoding? encoding}) =>
{Map<String, String>? headers, Object? body, _i7.Encoding? encoding}) =>
(super.noSuchMethod(
Invocation.method(#put, [url],
{#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
Invocation.method(#put, [url], {#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<_i2.Response> patch(Uri? url,
{Map<String, String>? headers,
Object? body,
_i7.Encoding? encoding}) =>
{Map<String, String>? headers, Object? body, _i7.Encoding? encoding}) =>
(super.noSuchMethod(
Invocation.method(#patch, [url],
{#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
Invocation.method(#patch, [url], {#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<_i2.Response> delete(Uri? url,
{Map<String, String>? headers,
Object? body,
_i7.Encoding? encoding}) =>
{Map<String, String>? headers, Object? body, _i7.Encoding? encoding}) =>
(super.noSuchMethod(
Invocation.method(#delete, [url],
{#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse()))
as _i6.Future<_i2.Response>);
Invocation.method(#delete, [url], {#headers: headers, #body: body, #encoding: encoding}),
returnValue: Future<_i2.Response>.value(_FakeResponse())) as _i6.Future<_i2.Response>);
@override
_i6.Future<String> read(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}),
returnValue: Future<String>.value('')) as _i6.Future<String>);
@override
_i6.Future<_i3.Uint8List> readBytes(Uri? url,
{Map<String, String>? headers}) =>
(super.noSuchMethod(
Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: Future<_i3.Uint8List>.value(_FakeUint8List()))
as _i6.Future<_i3.Uint8List>);
_i6.Future<_i3.Uint8List> readBytes(Uri? url, {Map<String, String>? headers}) =>
(super.noSuchMethod(Invocation.method(#readBytes, [url], {#headers: headers}),
returnValue: Future<_i3.Uint8List>.value(_FakeUint8List())) as _i6.Future<_i3.Uint8List>);
@override
_i6.Future<_i4.StreamedResponse> send(_i8.BaseRequest? request) =>
(super.noSuchMethod(Invocation.method(#send, [request]),
returnValue:
Future<_i4.StreamedResponse>.value(_FakeStreamedResponse()))
returnValue: Future<_i4.StreamedResponse>.value(_FakeStreamedResponse()))
as _i6.Future<_i4.StreamedResponse>);
@override
void close() => super.noSuchMethod(Invocation.method(#close, []),
returnValueForMissingStub: null);
void close() =>
super.noSuchMethod(Invocation.method(#close, []), returnValueForMissingStub: null);
}

View File

@@ -54,8 +54,7 @@ main() {
);
}
testWidgets('Test the widgets on the SetFormWidget',
(WidgetTester tester) async {
testWidgets('Test the widgets on the SetFormWidget', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.pumpAndSettle();
@@ -66,8 +65,7 @@ main() {
expect(find.text('Bench\nDumbbell'), findsOneWidget, reason: 'Equipment');
expect(find.text('Muscles'), findsOneWidget);
expect(find.text('Flutterus maximus\nBiceps'), findsOneWidget,
reason: 'Muscles');
expect(find.text('Flutterus maximus\nBiceps'), findsOneWidget, reason: 'Muscles');
expect(find.text('Secondary muscles'), findsOneWidget);
expect(find.text('Booty'), findsOneWidget, reason: 'Secondary muscles');

View File

@@ -52,14 +52,11 @@ void main() {
);
}
testWidgets('Test opening the form for an existing image',
(WidgetTester tester) async {
await mockNetworkImagesFor(
() => tester.pumpWidget(createScreen(useImage: true)));
testWidgets('Test opening the form for an existing image', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen(useImage: true)));
await tester.pumpAndSettle();
expect(find.byType(TextFormField),
findsNWidgets(2)); // four in the overview, one in the popup
expect(find.byType(TextFormField), findsNWidgets(2)); // four in the overview, one in the popup
expect(find.text('A very cool image from the gym'), findsOneWidget);
expect(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)), findsOneWidget);
@@ -70,10 +67,8 @@ void main() {
verify(mockGalleryProvider.editImage(any, any));
});
testWidgets('Test opening the form for a new image',
(WidgetTester tester) async {
await mockNetworkImagesFor(
() => tester.pumpWidget(createScreen(useImage: false)));
testWidgets('Test opening the form for a new image', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen(useImage: false)));
await tester.pumpAndSettle();
expect(find.text('Please select an image'), findsOneWidget);

View File

@@ -54,15 +54,13 @@ void main() {
);
}
testWidgets('Test the widgets on the gallery screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the gallery screen', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen()));
expect(find.byType(GestureDetector), findsNWidgets(4));
});
testWidgets('Test opening the form for an existing image',
(WidgetTester tester) async {
testWidgets('Test opening the form for an existing image', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen()));
await tester.tap(find.byKey(Key('image-1')));
@@ -70,8 +68,7 @@ void main() {
// Detail dialog opens
expect(find.byKey(Key('image-1-detail')), findsOneWidget);
expect(find.byType(Image),
findsNWidgets(5)); // four in the overview, one in the popup
expect(find.byType(Image), findsNWidgets(5)); // four in the overview, one in the popup
expect(find.text('A very cool image from the gym'), findsOneWidget);
expect(find.byIcon(Icons.edit), findsOneWidget);
expect(find.byIcon(Icons.delete), findsOneWidget);
@@ -85,8 +82,7 @@ void main() {
expect(find.byType(ElevatedButton), findsOneWidget);
});
testWidgets('Tests the localization of dates - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen()));
await tester.tap(find.byKey(Key('image-1')));
await tester.pumpAndSettle();
@@ -94,10 +90,8 @@ void main() {
expect(find.text('5/30/2021'), findsOneWidget);
});
testWidgets('Tests the localization of dates - DE',
(WidgetTester tester) async {
await mockNetworkImagesFor(
() => tester.pumpWidget(createScreen(locale: 'de')));
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
await mockNetworkImagesFor(() => tester.pumpWidget(createScreen(locale: 'de')));
await tester.tap(find.byKey(Key('image-1')));
await tester.pumpAndSettle();

View File

@@ -7,8 +7,7 @@ import 'dart:ui' as _i9;
import 'package:http/src/client.dart' as _i3;
import 'package:http/src/response.dart' as _i4;
import 'package:image_picker_platform_interface/src/types/picked_file/io.dart'
as _i8;
import 'package:image_picker_platform_interface/src/types/picked_file/io.dart' as _i8;
import 'package:mockito/mockito.dart' as _i1;
import 'package:wger/models/gallery/image.dart' as _i6;
import 'package:wger/providers/auth.dart' as _i2;
@@ -38,30 +37,28 @@ class MockGalleryProvider extends _i1.Mock implements _i5.GalleryProvider {
}
@override
List<_i6.Image> get images => (super.noSuchMethod(Invocation.getter(#images),
returnValue: <_i6.Image>[]) as List<_i6.Image>);
List<_i6.Image> get images =>
(super.noSuchMethod(Invocation.getter(#images), returnValue: <_i6.Image>[])
as List<_i6.Image>);
@override
set images(List<_i6.Image>? _images) =>
super.noSuchMethod(Invocation.setter(#images, _images),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#images, _images), returnValueForMissingStub: null);
@override
bool get hasListeners =>
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
as bool);
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool);
@override
_i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth),
returnValue: _FakeAuthProvider()) as _i2.AuthProvider);
_i2.AuthProvider get auth =>
(super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider())
as _i2.AuthProvider);
@override
set auth(_i2.AuthProvider? _auth) =>
super.noSuchMethod(Invocation.setter(#auth, _auth),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null);
@override
_i3.Client get client => (super.noSuchMethod(Invocation.getter(#client),
returnValue: _FakeClient()) as _i3.Client);
_i3.Client get client =>
(super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient()) as _i3.Client);
@override
set client(_i3.Client? _client) =>
super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null);
@override
_i7.Future<void> fetchAndSetGallery() =>
(super.noSuchMethod(Invocation.method(#fetchAndSetGallery, []),
@@ -83,48 +80,41 @@ class MockGalleryProvider extends _i1.Mock implements _i5.GalleryProvider {
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i7.Future<void>);
@override
void addListener(_i9.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null);
void addListener(_i9.VoidCallback? listener) => super
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
@override
void removeListener(_i9.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null);
@override
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
returnValueForMissingStub: null);
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
@override
void notifyListeners() =>
super.noSuchMethod(Invocation.method(#notifyListeners, []),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null);
@override
Uri makeUrl(String? path,
{int? id, String? objectMethod, Map<String, dynamic>? query}) =>
Uri makeUrl(String? path, {int? id, String? objectMethod, Map<String, dynamic>? query}) =>
(super.noSuchMethod(
Invocation.method(#makeUrl, [path],
{#id: id, #objectMethod: objectMethod, #query: query}),
Invocation.method(
#makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}),
returnValue: _FakeUri()) as Uri);
@override
_i7.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i7.Future<Map<String, dynamic>>);
_i7.Future<Map<String, dynamic>> fetch(Uri? uri) =>
(super.noSuchMethod(Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i7.Future<Map<String, dynamic>>);
@override
_i7.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i7.Future<Map<String, dynamic>>);
@override
_i7.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data, Uri? uri) =>
_i7.Future<Map<String, dynamic>> patch(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#patch, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i7.Future<Map<String, dynamic>>);
@override
_i7.Future<_i4.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
returnValue: Future<_i4.Response>.value(_FakeResponse()))
as _i7.Future<_i4.Response>);
returnValue: Future<_i4.Response>.value(_FakeResponse())) as _i7.Future<_i4.Response>);
}

View File

@@ -69,8 +69,7 @@ void main() {
);
}
testWidgets('Test the widgets on the gym mode screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the gym mode screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
@@ -106,8 +105,7 @@ void main() {
expect(find.text('test exercise 1'), findsOneWidget);
expect(find.byType(LogPage), findsOneWidget);
expect(find.byType(Form), findsOneWidget);
expect(find.byType(ListTile), findsNWidgets(3),
reason: 'Two logs and the switch tile');
expect(find.byType(ListTile), findsNWidgets(3), reason: 'Two logs and the switch tile');
expect(find.text('10 × 10 kg (1.5 RiR)'), findsOneWidget);
expect(find.text('12 × 10 kg (2 RiR)'), findsOneWidget);
expect(find.byIcon(Icons.close), findsOneWidget);

View File

@@ -94,8 +94,7 @@ void main() {
verifyNever(mockNutrition.addMeal(any, any));
});
testWidgets('Test creating a new nutritional plan',
(WidgetTester tester) async {
testWidgets('Test creating a new nutritional plan', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(meal2));
await tester.pumpAndSettle();

View File

@@ -68,8 +68,7 @@ void main() {
);
}
testWidgets('Test the widgets on the nutritional plan form',
(WidgetTester tester) async {
testWidgets('Test the widgets on the nutritional plan form', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(plan1));
await tester.pumpAndSettle();
@@ -78,8 +77,7 @@ void main() {
expect(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)), findsOneWidget);
});
testWidgets('Test editing an existing nutritional plan',
(WidgetTester tester) async {
testWidgets('Test editing an existing nutritional plan', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(plan1));
await tester.pumpAndSettle();
@@ -88,8 +86,7 @@ void main() {
findsOneWidget,
reason: 'Description of existing nutritional plan is filled in',
);
await tester.enterText(
find.byKey(Key('field-description')), 'New description');
await tester.enterText(find.byKey(Key('field-description')), 'New description');
await tester.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
// Correct method was called
@@ -110,15 +107,12 @@ void main() {
//);
});
testWidgets('Test creating a new nutritional plan',
(WidgetTester tester) async {
testWidgets('Test creating a new nutritional plan', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(plan2));
await tester.pumpAndSettle();
expect(find.text(('')), findsOneWidget,
reason: 'New nutritional plan has no description');
await tester.enterText(
find.byKey(Key('field-description')), 'New cool plan');
expect(find.text(('')), findsOneWidget, reason: 'New nutritional plan has no description');
await tester.enterText(find.byKey(Key('field-description')), 'New cool plan');
await tester.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
// Correct method was called
@@ -127,7 +121,6 @@ void main() {
// Detail page
await tester.pumpAndSettle();
expect(find.text(('New cool plan')), findsOneWidget,
reason: 'Nutritional plan detail page');
expect(find.text(('New cool plan')), findsOneWidget, reason: 'Nutritional plan detail page');
});
}

View File

@@ -41,38 +41,35 @@ class _FakeResponse extends _i1.Fake implements _i8.Response {}
/// A class which mocks [NutritionPlansProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockNutritionPlansProvider extends _i1.Mock
implements _i9.NutritionPlansProvider {
class MockNutritionPlansProvider extends _i1.Mock implements _i9.NutritionPlansProvider {
MockNutritionPlansProvider() {
_i1.throwOnMissingStub(this);
}
@override
List<_i4.NutritionalPlan> get items =>
(super.noSuchMethod(Invocation.getter(#items),
returnValue: <_i4.NutritionalPlan>[]) as List<_i4.NutritionalPlan>);
(super.noSuchMethod(Invocation.getter(#items), returnValue: <_i4.NutritionalPlan>[])
as List<_i4.NutritionalPlan>);
@override
bool get hasListeners =>
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
as bool);
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool);
@override
_i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth),
returnValue: _FakeAuthProvider()) as _i2.AuthProvider);
_i2.AuthProvider get auth =>
(super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider())
as _i2.AuthProvider);
@override
set auth(_i2.AuthProvider? _auth) =>
super.noSuchMethod(Invocation.setter(#auth, _auth),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null);
@override
_i3.Client get client => (super.noSuchMethod(Invocation.getter(#client),
returnValue: _FakeClient()) as _i3.Client);
_i3.Client get client =>
(super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient()) as _i3.Client);
@override
set client(_i3.Client? _client) =>
super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null);
@override
_i4.NutritionalPlan findById(int? id) =>
(super.noSuchMethod(Invocation.method(#findById, [id]),
returnValue: _FakeNutritionalPlan()) as _i4.NutritionalPlan);
(super.noSuchMethod(Invocation.method(#findById, [id]), returnValue: _FakeNutritionalPlan())
as _i4.NutritionalPlan);
@override
_i5.Meal? findMealById(int? id) =>
(super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?);
@@ -89,20 +86,17 @@ class MockNutritionPlansProvider extends _i1.Mock
@override
_i10.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
(super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]),
returnValue:
Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
as _i10.Future<_i4.NutritionalPlan>);
@override
_i10.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) =>
(super.noSuchMethod(Invocation.method(#fetchAndSetPlanFull, [planId]),
returnValue:
Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
as _i10.Future<_i4.NutritionalPlan>);
@override
_i10.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
(super.noSuchMethod(Invocation.method(#addPlan, [planData]),
returnValue:
Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan()))
as _i10.Future<_i4.NutritionalPlan>);
@override
_i10.Future<void> editPlan(_i4.NutritionalPlan? plan) =>
@@ -110,53 +104,44 @@ class MockNutritionPlansProvider extends _i1.Mock
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
_i10.Future<void> deletePlan(int? id) =>
(super.noSuchMethod(Invocation.method(#deletePlan, [id]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
_i10.Future<void> deletePlan(int? id) => (super.noSuchMethod(Invocation.method(#deletePlan, [id]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
_i10.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) =>
(super.noSuchMethod(Invocation.method(#addMeal, [meal, planId]),
returnValue: Future<_i5.Meal>.value(_FakeMeal()))
as _i10.Future<_i5.Meal>);
returnValue: Future<_i5.Meal>.value(_FakeMeal())) as _i10.Future<_i5.Meal>);
@override
_i10.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
(super.noSuchMethod(Invocation.method(#editMeal, [meal]),
returnValue: Future<_i5.Meal>.value(_FakeMeal()))
as _i10.Future<_i5.Meal>);
returnValue: Future<_i5.Meal>.value(_FakeMeal())) as _i10.Future<_i5.Meal>);
@override
_i10.Future<void> deleteMeal(_i5.Meal? meal) =>
(super.noSuchMethod(Invocation.method(#deleteMeal, [meal]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
_i10.Future<_i6.MealItem> addMealItem(
_i6.MealItem? mealItem, _i5.Meal? meal) =>
_i10.Future<_i6.MealItem> addMealItem(_i6.MealItem? mealItem, _i5.Meal? meal) =>
(super.noSuchMethod(Invocation.method(#addMealItem, [mealItem, meal]),
returnValue: Future<_i6.MealItem>.value(_FakeMealItem()))
as _i10.Future<_i6.MealItem>);
returnValue: Future<_i6.MealItem>.value(_FakeMealItem())) as _i10.Future<_i6.MealItem>);
@override
_i10.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
(super.noSuchMethod(Invocation.method(#deleteMealItem, [mealItem]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
_i10.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) =>
(super.noSuchMethod(Invocation.method(#fetchIngredient, [ingredientId]),
returnValue: Future<_i7.Ingredient>.value(_FakeIngredient()))
as _i10.Future<_i7.Ingredient>);
_i10.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(
Invocation.method(#fetchIngredient, [ingredientId]),
returnValue: Future<_i7.Ingredient>.value(_FakeIngredient())) as _i10.Future<_i7.Ingredient>);
@override
_i10.Future<void> fetchIngredientsFromCache() =>
(super.noSuchMethod(Invocation.method(#fetchIngredientsFromCache, []),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
_i10.Future<List<dynamic>> searchIngredient(String? name,
[String? languageCode = r'en']) =>
(super.noSuchMethod(
Invocation.method(#searchIngredient, [name, languageCode]),
returnValue: Future<List<dynamic>>.value(<dynamic>[]))
as _i10.Future<List<dynamic>>);
_i10.Future<List<dynamic>> searchIngredient(String? name, [String? languageCode = r'en']) =>
(super.noSuchMethod(Invocation.method(#searchIngredient, [name, languageCode]),
returnValue: Future<List<dynamic>>.value(<dynamic>[])) as _i10.Future<List<dynamic>>);
@override
_i10.Future<void> logMealToDiary(_i5.Meal? meal) =>
(super.noSuchMethod(Invocation.method(#logMealToDiary, [meal]),
@@ -168,49 +153,41 @@ class MockNutritionPlansProvider extends _i1.Mock
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i10.Future<void>);
@override
void addListener(_i11.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null);
void addListener(_i11.VoidCallback? listener) => super
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
@override
void removeListener(_i11.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null);
@override
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
returnValueForMissingStub: null);
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
@override
void notifyListeners() =>
super.noSuchMethod(Invocation.method(#notifyListeners, []),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null);
@override
Uri makeUrl(String? path,
{int? id, String? objectMethod, Map<String, dynamic>? query}) =>
Uri makeUrl(String? path, {int? id, String? objectMethod, Map<String, dynamic>? query}) =>
(super.noSuchMethod(
Invocation.method(#makeUrl, [path],
{#id: id, #objectMethod: objectMethod, #query: query}),
Invocation.method(
#makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}),
returnValue: _FakeUri()) as Uri);
@override
_i10.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i10.Future<Map<String, dynamic>>);
@override
_i10.Future<Map<String, dynamic>> post(
Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
_i10.Future<Map<String, dynamic>> fetch(Uri? uri) =>
(super.noSuchMethod(Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i10.Future<Map<String, dynamic>>);
@override
_i10.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data, Uri? uri) =>
_i10.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i10.Future<Map<String, dynamic>>);
@override
_i10.Future<Map<String, dynamic>> patch(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#patch, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i10.Future<Map<String, dynamic>>);
@override
_i10.Future<_i8.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
returnValue: Future<_i8.Response>.value(_FakeResponse()))
as _i10.Future<_i8.Response>);
returnValue: Future<_i8.Response>.value(_FakeResponse())) as _i10.Future<_i8.Response>);
}

View File

@@ -25,16 +25,14 @@ void main() {
group('model tests', () {
test('Test the nutritionalValues method for nutritional plans', () {
final plan = getNutritionalPlan();
final values = NutritionalValues.values(
4118.75, 28.75, 347.5, 9.5, 41.0, 31.75, 41.5, 30.0);
final values = NutritionalValues.values(4118.75, 28.75, 347.5, 9.5, 41.0, 31.75, 41.5, 30.0);
expect(plan.nutritionalValues, values);
});
test('Test the nutritionalValues method for meals', () {
final plan = getNutritionalPlan();
final meal = plan.meals.first;
final values = NutritionalValues.values(
518.75, 1.75, 17.5, 3.5, 11.0, 7.75, 38.5, 0.0);
final values = NutritionalValues.values(518.75, 1.75, 17.5, 3.5, 11.0, 7.75, 38.5, 0.0);
expect(meal.nutritionalValues, values);
});
});

View File

@@ -55,8 +55,7 @@ void main() {
);
}
testWidgets('Test the widgets on the nutritional plan screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the nutritional plan screen', (WidgetTester tester) async {
await tester.pumpWidget(createNutritionalPlan());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
@@ -73,8 +72,7 @@ void main() {
expect(find.byType(NutritionalDiaryChartWidget), findsNothing);
});
testWidgets('Tests the localization of times - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of times - EN', (WidgetTester tester) async {
await tester.pumpWidget(createNutritionalPlan());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
@@ -82,8 +80,7 @@ void main() {
expect(find.text('5:00 PM'), findsOneWidget);
});
testWidgets('Tests the localization of times - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of times - DE', (WidgetTester tester) async {
await tester.pumpWidget(createNutritionalPlan(locale: 'de'));
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();

View File

@@ -43,14 +43,8 @@ void main() {
create: (context) => NutritionPlansProvider(
testAuthProvider,
[
NutritionalPlan(
id: 1,
description: 'test plan 1',
creationDate: DateTime(2021, 01, 01)),
NutritionalPlan(
id: 2,
description: 'test plan 2',
creationDate: DateTime(2021, 01, 10)),
NutritionalPlan(id: 1, description: 'test plan 1', creationDate: DateTime(2021, 01, 01)),
NutritionalPlan(id: 2, description: 'test plan 2', creationDate: DateTime(2021, 01, 10)),
],
client,
),
@@ -66,8 +60,7 @@ void main() {
);
}
testWidgets('Test the widgets on the nutritional plans screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the nutritional plans screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
//debugDumpApp();
@@ -76,8 +69,7 @@ void main() {
expect(find.byType(ListTile), findsNWidgets(2));
});
testWidgets('Test deleting an item by dragging the dismissible',
(WidgetTester tester) async {
testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.drag(find.byKey(Key('1')), Offset(-500.0, 0.0));
@@ -92,8 +84,7 @@ void main() {
expect(find.byType(ListTile), findsOneWidget);
});
testWidgets('Test the form on the nutritional plan screen',
(WidgetTester tester) async {
testWidgets('Test the form on the nutritional plan screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.byType(PlanForm), findsNothing);
@@ -102,16 +93,14 @@ void main() {
expect(find.byType(PlanForm), findsOneWidget);
});
testWidgets('Tests the localization of dates - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.text('1/1/2021'), findsOneWidget);
expect(find.text('1/10/2021'), findsOneWidget);
});
testWidgets('Tests the localization of dates - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(locale: 'de'));
expect(find.text('1.1.2021'), findsOneWidget);

View File

@@ -27,12 +27,9 @@ void main() {
group('Test the NutritionalValues class', () {
setUp(() {
values1 = NutritionalValues.values(
4000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values2 = NutritionalValues.values(
4000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values3 = NutritionalValues.values(
5000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values1 = NutritionalValues.values(4000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values2 = NutritionalValues.values(4000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values3 = NutritionalValues.values(5000, 30.5, 340.5, 11.7, 41.0, 31.75, 21.3, 33.3);
values4 = NutritionalValues.values(1000, 10, 100, 1, 10.0, 10, 10, 10);
});
@@ -43,15 +40,13 @@ void main() {
test('Test the plus operator', () {
final values5 = values1 + values4;
final result = NutritionalValues.values(
5000, 40.5, 440.5, 12.7, 51.0, 41.75, 31.3, 43.3);
final result = NutritionalValues.values(5000, 40.5, 440.5, 12.7, 51.0, 41.75, 31.3, 43.3);
expect(values5, result);
});
test('Test the add method', () {
values1.add(values4);
final result = NutritionalValues.values(
5000, 40.5, 440.5, 12.7, 51.0, 41.75, 31.3, 43.3);
final result = NutritionalValues.values(5000, 40.5, 440.5, 12.7, 51.0, 41.75, 31.3, 43.3);
expect(values1, result);
});
});

View File

@@ -25,10 +25,8 @@ void main() {
test('Regular weights', () async {
expect(plateCalculator(40, BAR_WEIGHT, AVAILABLE_PLATES), [10]);
expect(plateCalculator(100, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10]);
expect(plateCalculator(102.5, BAR_WEIGHT, AVAILABLE_PLATES),
[15, 15, 10, 1.25]);
expect(
plateCalculator(140, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 15, 15]);
expect(plateCalculator(102.5, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10, 1.25]);
expect(plateCalculator(140, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 15, 15]);
expect(plateCalculator(45, BAR_WEIGHT, AVAILABLE_PLATES), [10, 2.5]);
expect(plateCalculator(85, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 2.5]);
});

View File

@@ -21,23 +21,16 @@ import 'package:wger/models/body_weight/weight_entry.dart';
void main() {
group('fetchPost', () {
test('Test that the weight entries are correctly converted to json',
() async {
WeightEntry weightEntry =
WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31));
expect(weightEntry.toJson(),
{'id': 1, 'weight': '80', 'date': '2020-12-31'});
test('Test that the weight entries are correctly converted to json', () async {
WeightEntry weightEntry = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31));
expect(weightEntry.toJson(), {'id': 1, 'weight': '80', 'date': '2020-12-31'});
weightEntry =
WeightEntry(id: 2, weight: 70.2, date: DateTime(2020, 12, 01));
expect(weightEntry.toJson(),
{'id': 2, 'weight': '70.2', 'date': '2020-12-01'});
weightEntry = WeightEntry(id: 2, weight: 70.2, date: DateTime(2020, 12, 01));
expect(weightEntry.toJson(), {'id': 2, 'weight': '70.2', 'date': '2020-12-01'});
});
test('Test that the weight entries are correctly converted from json',
() async {
WeightEntry weightEntryObj =
WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31));
test('Test that the weight entries are correctly converted from json', () async {
WeightEntry weightEntryObj = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31));
WeightEntry weightEntry = WeightEntry.fromJson({
'id': 1,
'weight': '80',
@@ -53,8 +46,7 @@ void main() {
test('Test the individual values from the model', () {
WeightEntry _weightModel;
//_weightModel = WeightEntry();
_weightModel =
WeightEntry(id: 1, weight: 80, date: DateTime(2020, 10, 01));
_weightModel = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 10, 01));
expect(_weightModel.id, 1);
expect(_weightModel.weight, 80);

View File

@@ -41,8 +41,7 @@ void main() {
200));
// Load the entries
BodyWeightProvider provider =
BodyWeightProvider(testAuthProvider, [], client);
BodyWeightProvider provider = BodyWeightProvider(testAuthProvider, [], client);
await provider.fetchAndSetEntries();
// Check that everything is ok
@@ -60,14 +59,12 @@ void main() {
headers: anyNamed('headers'),
body: '{"id":null,"weight":"80","date":"2021-01-01"}',
),
).thenAnswer((_) async => http.Response(
'{"id": 25, "date": "2021-01-01", "weight": "80"}', 200));
).thenAnswer(
(_) async => http.Response('{"id": 25, "date": "2021-01-01", "weight": "80"}', 200));
// POST the data to the server
final WeightEntry weightEntry =
WeightEntry(date: DateTime(2021, 1, 1), weight: 80);
final BodyWeightProvider provider =
BodyWeightProvider(testAuthProvider, [], client);
final WeightEntry weightEntry = WeightEntry(date: DateTime(2021, 1, 1), weight: 80);
final BodyWeightProvider provider = BodyWeightProvider(testAuthProvider, [], client);
final WeightEntry weightEntryNew = await provider.addEntry(weightEntry);
// Check that the server response is what we expect

View File

@@ -43,8 +43,8 @@ void main() {
any,
headers: anyNamed('headers'),
body: anyNamed('body'),
)).thenAnswer((_) async =>
http.Response('{"id": 3, "date": "2021-01-01", "weight": "80"}', 200));
)).thenAnswer(
(_) async => http.Response('{"id": 3, "date": "2021-01-01", "weight": "80"}', 200));
return ChangeNotifierProvider<BodyWeightProvider>(
create: (context) => BodyWeightProvider(
@@ -67,8 +67,7 @@ void main() {
);
}
testWidgets('Test the widgets on the body weight screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the body weight screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
//debugDumpApp();
@@ -78,8 +77,7 @@ void main() {
expect(find.byType(ListTile), findsNWidgets(2));
});
testWidgets('Test deleting an item by dragging the dismissible',
(WidgetTester tester) async {
testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.drag(find.byKey(Key('1')), Offset(-500.0, 0.0));
@@ -87,8 +85,7 @@ void main() {
expect(find.byType(ListTile), findsOneWidget);
});
testWidgets('Test the form on the body weight screen',
(WidgetTester tester) async {
testWidgets('Test the form on the body weight screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.byType(WeightForm), findsNothing);
@@ -97,16 +94,14 @@ void main() {
expect(find.byType(WeightForm), findsOneWidget);
});
testWidgets('Tests the localization of dates - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.text('1/1/2021'), findsOneWidget);
expect(find.text('1/10/2021'), findsOneWidget);
});
testWidgets('Tests the localization of dates - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(locale: 'de'));
expect(find.text('1.1.2021'), findsOneWidget);

View File

@@ -56,8 +56,7 @@ void main() {
);
}
testWidgets('Test the widgets on the DayFormWidget',
(WidgetTester tester) async {
testWidgets('Test the widgets on the DayFormWidget', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.pumpAndSettle();
@@ -67,14 +66,12 @@ void main() {
});
testWidgets('Test creating a new day', (WidgetTester tester) async {
when(mockWorkoutPlans.addDay(any, any))
.thenAnswer((_) => Future.value(Day()));
when(mockWorkoutPlans.addDay(any, any)).thenAnswer((_) => Future.value(Day()));
await tester.pumpWidget(createHomeScreen());
await tester.pumpAndSettle();
expect(find.text(('')), findsOneWidget,
reason: 'New day has no description');
expect(find.text(('')), findsOneWidget, reason: 'New day has no description');
await tester.enterText(find.byKey(Key('field-description')), 'Leg day!');
await tester.tap(find.byKey(Key('field-checkbox-1')));
await tester.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
@@ -86,8 +83,7 @@ void main() {
//verify(mockObserver.didPop(any, any));
});
testWidgets('Tests the localization of days - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of days - EN', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.text('Monday'), findsOneWidget);
@@ -95,8 +91,7 @@ void main() {
expect(find.text('Thursday'), findsOneWidget);
});
testWidgets('Tests the localization of days - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of days - DE', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(locale: 'de'));
expect(find.text('Montag'), findsOneWidget);

View File

@@ -44,8 +44,7 @@ void main() {
setUp(() {
mockWorkoutPlans = MockWorkoutPlansProvider();
when(mockWorkoutPlans.editWorkout(any))
.thenAnswer((_) => Future.value(existingPlan));
when(mockWorkoutPlans.editWorkout(any)).thenAnswer((_) => Future.value(existingPlan));
when(mockWorkoutPlans.fetchAndSetWorkoutPlanFull(any))
.thenAnswer((_) => Future.value(existingPlan));
});
@@ -70,8 +69,7 @@ void main() {
);
}
testWidgets('Test the widgets on the workout form',
(WidgetTester tester) async {
testWidgets('Test the widgets on the workout form', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(existingPlan));
await tester.pumpAndSettle();
@@ -109,22 +107,19 @@ void main() {
//expect(find.text(('New description')), findsOneWidget, reason: 'Workout plan detail page');
});
testWidgets('Test creating a new workout - only name',
(WidgetTester tester) async {
testWidgets('Test creating a new workout - only name', (WidgetTester tester) async {
final editWorkout = WorkoutPlan(
id: 2,
creationDate: newPlan.creationDate,
name: 'New cool workout',
);
when(mockWorkoutPlans.addWorkout(any))
.thenAnswer((_) => Future.value(editWorkout));
when(mockWorkoutPlans.addWorkout(any)).thenAnswer((_) => Future.value(editWorkout));
await tester.pumpWidget(createHomeScreen(newPlan));
await tester.pumpAndSettle();
expect(find.text(('')), findsNWidgets(2),
reason: 'New workout has no name or description');
expect(find.text(('')), findsNWidgets(2), reason: 'New workout has no name or description');
await tester.enterText(find.byKey(Key('field-name')), editWorkout.name);
await tester.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
@@ -133,28 +128,20 @@ void main() {
// Detail page
await tester.pumpAndSettle();
expect(find.text(('New cool workout')), findsOneWidget,
reason: 'Workout plan detail page');
expect(find.text(('New cool workout')), findsOneWidget, reason: 'Workout plan detail page');
});
testWidgets('Test creating a new workout - name and description',
(WidgetTester tester) async {
testWidgets('Test creating a new workout - name and description', (WidgetTester tester) async {
final editWorkout = WorkoutPlan(
id: 2,
creationDate: newPlan.creationDate,
name: 'My workout',
description: 'Get yuuuge');
when(mockWorkoutPlans.addWorkout(any))
.thenAnswer((_) => Future.value(editWorkout));
id: 2, creationDate: newPlan.creationDate, name: 'My workout', description: 'Get yuuuge');
when(mockWorkoutPlans.addWorkout(any)).thenAnswer((_) => Future.value(editWorkout));
await tester.pumpWidget(createHomeScreen(newPlan));
await tester.pumpAndSettle();
expect(find.text(('')), findsNWidgets(2),
reason: 'New workout has no name or description');
expect(find.text(('')), findsNWidgets(2), reason: 'New workout has no name or description');
await tester.enterText(find.byKey(Key('field-name')), editWorkout.name);
await tester.enterText(
find.byKey(Key('field-description')), editWorkout.description);
await tester.enterText(find.byKey(Key('field-description')), editWorkout.description);
await tester.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
verifyNever(mockWorkoutPlans.editWorkout(any));
@@ -162,7 +149,6 @@ void main() {
// Detail page
await tester.pumpAndSettle();
expect(find.text(('My workout')), findsOneWidget,
reason: 'Workout plan detail page');
expect(find.text(('My workout')), findsOneWidget, reason: 'Workout plan detail page');
});
}

View File

@@ -54,66 +54,60 @@ class _FakeResponse extends _i1.Fake implements _i12.Response {}
/// A class which mocks [WorkoutPlansProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockWorkoutPlansProvider extends _i1.Mock
implements _i13.WorkoutPlansProvider {
class MockWorkoutPlansProvider extends _i1.Mock implements _i13.WorkoutPlansProvider {
MockWorkoutPlansProvider() {
_i1.throwOnMissingStub(this);
}
@override
List<_i6.WorkoutPlan> get items =>
(super.noSuchMethod(Invocation.getter(#items),
returnValue: <_i6.WorkoutPlan>[]) as List<_i6.WorkoutPlan>);
(super.noSuchMethod(Invocation.getter(#items), returnValue: <_i6.WorkoutPlan>[])
as List<_i6.WorkoutPlan>);
@override
List<_i2.WeightUnit> get weightUnits =>
(super.noSuchMethod(Invocation.getter(#weightUnits),
returnValue: <_i2.WeightUnit>[]) as List<_i2.WeightUnit>);
(super.noSuchMethod(Invocation.getter(#weightUnits), returnValue: <_i2.WeightUnit>[])
as List<_i2.WeightUnit>);
@override
_i2.WeightUnit get defaultWeightUnit =>
(super.noSuchMethod(Invocation.getter(#defaultWeightUnit),
returnValue: _FakeWeightUnit()) as _i2.WeightUnit);
(super.noSuchMethod(Invocation.getter(#defaultWeightUnit), returnValue: _FakeWeightUnit())
as _i2.WeightUnit);
@override
List<_i3.RepetitionUnit> get repetitionUnits =>
(super.noSuchMethod(Invocation.getter(#repetitionUnits),
returnValue: <_i3.RepetitionUnit>[]) as List<_i3.RepetitionUnit>);
(super.noSuchMethod(Invocation.getter(#repetitionUnits), returnValue: <_i3.RepetitionUnit>[])
as List<_i3.RepetitionUnit>);
@override
_i3.RepetitionUnit get defaultRepetitionUnit =>
(super.noSuchMethod(Invocation.getter(#defaultRepetitionUnit),
returnValue: _FakeRepetitionUnit()) as _i3.RepetitionUnit);
@override
bool get hasListeners =>
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
as bool);
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool);
@override
_i4.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth),
returnValue: _FakeAuthProvider()) as _i4.AuthProvider);
_i4.AuthProvider get auth =>
(super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider())
as _i4.AuthProvider);
@override
set auth(_i4.AuthProvider? _auth) =>
super.noSuchMethod(Invocation.setter(#auth, _auth),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null);
@override
_i5.Client get client => (super.noSuchMethod(Invocation.getter(#client),
returnValue: _FakeClient()) as _i5.Client);
_i5.Client get client =>
(super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient()) as _i5.Client);
@override
set client(_i5.Client? _client) =>
super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null);
@override
_i6.WorkoutPlan findById(int? id) =>
(super.noSuchMethod(Invocation.method(#findById, [id]),
returnValue: _FakeWorkoutPlan()) as _i6.WorkoutPlan);
(super.noSuchMethod(Invocation.method(#findById, [id]), returnValue: _FakeWorkoutPlan())
as _i6.WorkoutPlan);
@override
int findIndexById(int? id) => (super
.noSuchMethod(Invocation.method(#findIndexById, [id]), returnValue: 0)
as int);
int findIndexById(int? id) =>
(super.noSuchMethod(Invocation.method(#findIndexById, [id]), returnValue: 0) as int);
@override
void setCurrentPlan(int? id) =>
super.noSuchMethod(Invocation.method(#setCurrentPlan, [id]),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.method(#setCurrentPlan, [id]), returnValueForMissingStub: null);
@override
void resetCurrentPlan() =>
super.noSuchMethod(Invocation.method(#resetCurrentPlan, []),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.method(#resetCurrentPlan, []), returnValueForMissingStub: null);
@override
_i14.Future<void> fetchAndSetAllPlansFull() =>
(super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansFull, []),
@@ -131,8 +125,7 @@ class MockWorkoutPlansProvider extends _i1.Mock
as _i14.Future<_i6.WorkoutPlan>);
@override
_i14.Future<_i6.WorkoutPlan> fetchAndSetWorkoutPlanFull(int? workoutId) =>
(super.noSuchMethod(
Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]),
(super.noSuchMethod(Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]),
returnValue: Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan()))
as _i14.Future<_i6.WorkoutPlan>);
@override
@@ -154,8 +147,7 @@ class MockWorkoutPlansProvider extends _i1.Mock
_i14.Future<Map<String, dynamic>> fetchLogData(
_i6.WorkoutPlan? workout, _i15.Exercise? exercise) =>
(super.noSuchMethod(Invocation.method(#fetchLogData, [workout, exercise]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i14.Future<Map<String, dynamic>>);
@override
_i14.Future<void> fetchAndSetRepetitionUnits() =>
@@ -175,27 +167,24 @@ class MockWorkoutPlansProvider extends _i1.Mock
@override
_i14.Future<_i7.Day> addDay(_i7.Day? day, _i6.WorkoutPlan? workout) =>
(super.noSuchMethod(Invocation.method(#addDay, [day, workout]),
returnValue: Future<_i7.Day>.value(_FakeDay()))
as _i14.Future<_i7.Day>);
returnValue: Future<_i7.Day>.value(_FakeDay())) as _i14.Future<_i7.Day>);
@override
_i14.Future<void> deleteDay(_i7.Day? day) =>
(super.noSuchMethod(Invocation.method(#deleteDay, [day]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i14.Future<void>);
@override
_i14.Future<_i8.Set> addSet(_i8.Set? workoutSet) => (super.noSuchMethod(
Invocation.method(#addSet, [workoutSet]),
returnValue: Future<_i8.Set>.value(_FakeSet())) as _i14.Future<_i8.Set>);
_i14.Future<_i8.Set> addSet(_i8.Set? workoutSet) =>
(super.noSuchMethod(Invocation.method(#addSet, [workoutSet]),
returnValue: Future<_i8.Set>.value(_FakeSet())) as _i14.Future<_i8.Set>);
@override
_i14.Future<void> fetchComputedSettings(_i8.Set? workoutSet) => (super
.noSuchMethod(Invocation.method(#fetchComputedSettings, [workoutSet]),
_i14.Future<void> fetchComputedSettings(_i8.Set? workoutSet) =>
(super.noSuchMethod(Invocation.method(#fetchComputedSettings, [workoutSet]),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i14.Future<void>);
@override
_i14.Future<String> fetchSmartText(
_i8.Set? workoutSet, _i15.Exercise? exercise) =>
(super.noSuchMethod(
Invocation.method(#fetchSmartText, [workoutSet, exercise]),
_i14.Future<String> fetchSmartText(_i8.Set? workoutSet, _i15.Exercise? exercise) =>
(super.noSuchMethod(Invocation.method(#fetchSmartText, [workoutSet, exercise]),
returnValue: Future<String>.value('')) as _i14.Future<String>);
@override
_i14.Future<void> deleteSet(_i8.Set? workoutSet) =>
@@ -205,8 +194,7 @@ class MockWorkoutPlansProvider extends _i1.Mock
@override
_i14.Future<_i9.Setting> addSetting(_i9.Setting? workoutSetting) =>
(super.noSuchMethod(Invocation.method(#addSetting, [workoutSetting]),
returnValue: Future<_i9.Setting>.value(_FakeSetting()))
as _i14.Future<_i9.Setting>);
returnValue: Future<_i9.Setting>.value(_FakeSetting())) as _i14.Future<_i9.Setting>);
@override
_i14.Future<dynamic> fetchSessionData() =>
(super.noSuchMethod(Invocation.method(#fetchSessionData, []),
@@ -214,58 +202,48 @@ class MockWorkoutPlansProvider extends _i1.Mock
@override
_i14.Future<_i10.WorkoutSession> addSession(_i10.WorkoutSession? session) =>
(super.noSuchMethod(Invocation.method(#addSession, [session]),
returnValue:
Future<_i10.WorkoutSession>.value(_FakeWorkoutSession()))
returnValue: Future<_i10.WorkoutSession>.value(_FakeWorkoutSession()))
as _i14.Future<_i10.WorkoutSession>);
@override
_i14.Future<_i11.Log> addLog(_i11.Log? log) =>
(super.noSuchMethod(Invocation.method(#addLog, [log]),
returnValue: Future<_i11.Log>.value(_FakeLog()))
as _i14.Future<_i11.Log>);
returnValue: Future<_i11.Log>.value(_FakeLog())) as _i14.Future<_i11.Log>);
@override
void addListener(_i16.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null);
void addListener(_i16.VoidCallback? listener) => super
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
@override
void removeListener(_i16.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null);
@override
void dispose() => super.noSuchMethod(Invocation.method(#dispose, []),
returnValueForMissingStub: null);
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
@override
void notifyListeners() =>
super.noSuchMethod(Invocation.method(#notifyListeners, []),
returnValueForMissingStub: null);
super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null);
@override
Uri makeUrl(String? path,
{int? id, String? objectMethod, Map<String, dynamic>? query}) =>
Uri makeUrl(String? path, {int? id, String? objectMethod, Map<String, dynamic>? query}) =>
(super.noSuchMethod(
Invocation.method(#makeUrl, [path],
{#id: id, #objectMethod: objectMethod, #query: query}),
Invocation.method(
#makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}),
returnValue: _FakeUri()) as Uri);
@override
_i14.Future<Map<String, dynamic>> fetch(Uri? uri) => (super.noSuchMethod(
Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i14.Future<Map<String, dynamic>>);
@override
_i14.Future<Map<String, dynamic>> post(
Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
_i14.Future<Map<String, dynamic>> fetch(Uri? uri) =>
(super.noSuchMethod(Invocation.method(#fetch, [uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i14.Future<Map<String, dynamic>>);
@override
_i14.Future<Map<String, dynamic>> patch(
Map<String, dynamic>? data, Uri? uri) =>
_i14.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i14.Future<Map<String, dynamic>>);
@override
_i14.Future<Map<String, dynamic>> patch(Map<String, dynamic>? data, Uri? uri) =>
(super.noSuchMethod(Invocation.method(#patch, [data, uri]),
returnValue:
Future<Map<String, dynamic>>.value(<String, dynamic>{}))
returnValue: Future<Map<String, dynamic>>.value(<String, dynamic>{}))
as _i14.Future<Map<String, dynamic>>);
@override
_i14.Future<_i12.Response> deleteRequest(String? url, int? id) =>
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
returnValue: Future<_i12.Response>.value(_FakeResponse()))
as _i14.Future<_i12.Response>);
returnValue: Future<_i12.Response>.value(_FakeResponse())) as _i14.Future<_i12.Response>);
}

View File

@@ -33,8 +33,8 @@ void main() {
final client = MockClient();
return ChangeNotifierProvider<WorkoutPlansProvider>(
create: (context) => WorkoutPlansProvider(
testAuthProvider, testExercisesProvider, [], client),
create: (context) =>
WorkoutPlansProvider(testAuthProvider, testExercisesProvider, [], client),
child: MaterialApp(
locale: Locale(locale),
localizationsDelegates: AppLocalizations.localizationsDelegates,
@@ -56,8 +56,7 @@ void main() {
);
}
testWidgets('Test the widgets on the nutritional plan screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the nutritional plan screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
@@ -68,8 +67,7 @@ void main() {
expect(find.byType(Dismissible), findsNWidgets(2));
});
testWidgets('Tests the localization of times - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of times - EN', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
@@ -78,8 +76,7 @@ void main() {
expect(find.text('Thursday'), findsOneWidget);
});
testWidgets('Tests the localization of times - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of times - DE', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(locale: 'de'));
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();

View File

@@ -45,10 +45,8 @@ void main() {
testAuthProvider,
testExercisesProvider,
[
WorkoutPlan(
id: 1, creationDate: DateTime(2021, 01, 01), name: 'test 1'),
WorkoutPlan(
id: 2, creationDate: DateTime(2021, 02, 12), name: 'test 2'),
WorkoutPlan(id: 1, creationDate: DateTime(2021, 01, 01), name: 'test 1'),
WorkoutPlan(id: 2, creationDate: DateTime(2021, 02, 12), name: 'test 2'),
],
client,
),
@@ -64,8 +62,7 @@ void main() {
);
}
testWidgets('Test the widgets on the workout plans screen',
(WidgetTester tester) async {
testWidgets('Test the widgets on the workout plans screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
//debugDumpApp();
@@ -74,8 +71,7 @@ void main() {
expect(find.byType(ListTile), findsNWidgets(2));
});
testWidgets('Test deleting an item by dragging the dismissible',
(WidgetTester tester) async {
testWidgets('Test deleting an item by dragging the dismissible', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.drag(find.byKey(Key('1')), Offset(-500.0, 0.0));
@@ -90,8 +86,7 @@ void main() {
expect(find.byType(ListTile), findsOneWidget);
});
testWidgets('Test the form on the workout plan screen',
(WidgetTester tester) async {
testWidgets('Test the form on the workout plan screen', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.byType(PlanForm), findsNothing);
@@ -100,16 +95,14 @@ void main() {
expect(find.byType(WorkoutForm), findsOneWidget);
});
testWidgets('Tests the localization of dates - EN',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
expect(find.text('1/1/2021'), findsOneWidget);
expect(find.text('2/12/2021'), findsOneWidget);
});
testWidgets('Tests the localization of dates - DE',
(WidgetTester tester) async {
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen(locale: 'de'));
expect(find.text('1.1.2021'), findsOneWidget);

View File

@@ -74,8 +74,7 @@ void main() {
);
}
testWidgets('Test the widgets on the SetFormWidget',
(WidgetTester tester) async {
testWidgets('Test the widgets on the SetFormWidget', (WidgetTester tester) async {
await tester.pumpWidget(createHomeScreen());
await tester.pumpAndSettle();
@@ -87,12 +86,9 @@ void main() {
});
testWidgets('Test creating a new set', (WidgetTester tester) async {
when(mockWorkoutPlans.addSet(any))
.thenAnswer((_) => Future.value(Set.empty()));
when(mockWorkoutPlans.addSetting(any))
.thenAnswer((_) => Future.value(Setting.empty()));
when(mockWorkoutPlans.fetchSmartText(any, any))
.thenAnswer((_) => Future.value('2 x 10'));
when(mockWorkoutPlans.addSet(any)).thenAnswer((_) => Future.value(Set.empty()));
when(mockWorkoutPlans.addSetting(any)).thenAnswer((_) => Future.value(Setting.empty()));
when(mockWorkoutPlans.fetchSmartText(any, any)).thenAnswer((_) => Future.value('2 x 10'));
await tester.pumpWidget(createHomeScreen());
await tester.pumpAndSettle();

Some files were not shown because too many files have changed in this diff Show More