mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-01 02:02:35 +01:00
Fixes pt 1
This commit is contained in:
@@ -34,7 +34,7 @@ class WgerHttpException implements Exception {
|
||||
errors = responseBody;
|
||||
}
|
||||
}
|
||||
this.errors = errors;
|
||||
errors = errors;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
/// Calculates the number of plates needed to reach a specific weight
|
||||
List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||
List<num> ans = [];
|
||||
var platesCount = plates.length;
|
||||
final List<num> ans = [];
|
||||
final platesCount = plates.length;
|
||||
|
||||
// Weight is less than the bar
|
||||
if (totalWeight < barWeight) {
|
||||
@@ -35,7 +35,7 @@ List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||
}
|
||||
|
||||
// Iterate through the plates, beginning with the biggest ones
|
||||
for (var plate in plates.reversed) {
|
||||
for (final plate in plates.reversed) {
|
||||
while (totalWeight >= plate) {
|
||||
totalWeight -= plate;
|
||||
ans.add(plate);
|
||||
@@ -49,8 +49,8 @@ List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||
///
|
||||
/// e.g. [15, 15, 15, 10, 10, 5] returns {15: 3, 10: 2, 5: 1}
|
||||
Map<num, int> groupPlates(List<num> plates) {
|
||||
Map<num, int> out = {};
|
||||
for (var plate in plates) {
|
||||
final Map<num, int> out = {};
|
||||
for (final plate in plates) {
|
||||
if (!out.containsKey(plate)) {
|
||||
out[plate] = 1;
|
||||
} else {
|
||||
|
||||
@@ -39,7 +39,7 @@ String? toDate(DateTime? dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
return DateFormat('yyyy-MM-dd').format(dateTime).toString();
|
||||
return DateFormat('yyyy-MM-dd').format(dateTime);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -47,7 +47,7 @@ String? toDate(DateTime? dateTime) {
|
||||
* Needed e.g. when the wger api only sends a time but no date information.
|
||||
*/
|
||||
TimeOfDay stringToTime(String? time) {
|
||||
String out = time ?? '00:00';
|
||||
final String out = time ?? '00:00';
|
||||
return TimeOfDay.fromDateTime(
|
||||
DateTime.parse('2020-01-01 $out'),
|
||||
);
|
||||
|
||||
@@ -29,9 +29,9 @@ String repText(
|
||||
WeightUnit weightUnitObj,
|
||||
String? rir,
|
||||
) {
|
||||
// TODO: how to (easily?) translate strings like the units or 'RiR'?
|
||||
// TODO(x): how to (easily?) translate strings like the units or 'RiR'
|
||||
|
||||
List<String> out = [];
|
||||
final List<String> out = [];
|
||||
|
||||
if (reps != null) {
|
||||
out.add(reps.toString());
|
||||
@@ -71,20 +71,22 @@ List<DateTime> daysInRange(DateTime first, DateTime last) {
|
||||
|
||||
extension TimeOfDayExtension on TimeOfDay {
|
||||
bool isAfter(TimeOfDay other) {
|
||||
if (toMinutes() > other.toMinutes())
|
||||
if (toMinutes() > other.toMinutes()) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isBefore(TimeOfDay other) {
|
||||
if (toMinutes() < other.toMinutes())
|
||||
if (toMinutes() < other.toMinutes()) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int toMinutes() {
|
||||
return ((hour * 60) + minute);
|
||||
return (hour * 60) + minute;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
log(exception.toString());
|
||||
log('-------------------');
|
||||
|
||||
List<Widget> errorList = [];
|
||||
for (var key in exception.errors!.keys) {
|
||||
final List<Widget> errorList = [];
|
||||
for (final key in exception.errors!.keys) {
|
||||
// Error headers
|
||||
errorList.add(Text(key, style: TextStyle(fontWeight: FontWeight.bold)));
|
||||
|
||||
@@ -58,7 +58,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
if (exception.errors![key] is String) {
|
||||
errorList.add(Text(exception.errors![key]));
|
||||
} else {
|
||||
for (var value in exception.errors![key]) {
|
||||
for (final value in exception.errors![key]) {
|
||||
errorList.add(Text(value));
|
||||
}
|
||||
}
|
||||
@@ -69,11 +69,9 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(AppLocalizations.of(ctx).anErrorOccurred),
|
||||
content: Container(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [...errorList],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [...errorList],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -66,7 +66,7 @@ class MyApp extends StatelessWidget {
|
||||
create: (context) =>
|
||||
ExercisesProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) =>
|
||||
previous != null ? previous : ExercisesProvider(auth, []),
|
||||
previous ?? ExercisesProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider, WorkoutPlansProvider>(
|
||||
create: (context) => WorkoutPlansProvider(
|
||||
@@ -75,31 +75,31 @@ class MyApp extends StatelessWidget {
|
||||
[],
|
||||
),
|
||||
update: (context, auth, exercises, previous) =>
|
||||
previous != null ? previous : WorkoutPlansProvider(auth, exercises, []),
|
||||
previous ?? WorkoutPlansProvider(auth, exercises, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
|
||||
create: (context) =>
|
||||
NutritionPlansProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) =>
|
||||
previous != null ? previous : NutritionPlansProvider(auth, []),
|
||||
previous ?? NutritionPlansProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, MeasurementProvider>(
|
||||
create: (context) => MeasurementProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false))),
|
||||
update: (context, base, previous) =>
|
||||
previous != null ? previous : MeasurementProvider(WgerBaseProvider(base)),
|
||||
previous ?? MeasurementProvider(WgerBaseProvider(base)),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, BodyWeightProvider>(
|
||||
create: (context) =>
|
||||
BodyWeightProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) =>
|
||||
previous != null ? previous : BodyWeightProvider(auth, []),
|
||||
previous ?? BodyWeightProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, GalleryProvider>(
|
||||
create: (context) =>
|
||||
GalleryProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) =>
|
||||
previous != null ? previous : GalleryProvider(auth, []),
|
||||
previous ?? GalleryProvider(auth, []),
|
||||
),
|
||||
],
|
||||
child: Consumer<AuthProvider>(
|
||||
@@ -118,7 +118,7 @@ class MyApp extends StatelessWidget {
|
||||
routes: {
|
||||
DashboardScreen.routeName: (ctx) => DashboardScreen(),
|
||||
FormScreen.routeName: (ctx) => FormScreen(),
|
||||
GalleryScreen.routeName: (ctx) => GalleryScreen(),
|
||||
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
|
||||
GymModeScreen.routeName: (ctx) => GymModeScreen(),
|
||||
HomeTabsScreen.routeName: (ctx) => HomeTabsScreen(),
|
||||
MeasurementCategoriesScreen.routeName: (ctx) => MeasurementCategoriesScreen(),
|
||||
|
||||
@@ -81,8 +81,8 @@ class Exercise {
|
||||
this.musclesSecondary = musclesSecondary ?? [];
|
||||
this.muscles = muscles ?? [];
|
||||
if (category != null) {
|
||||
this.categoryObj = category;
|
||||
this.categoryId = category.id;
|
||||
categoryObj = category;
|
||||
categoryId = category.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ class Exercise {
|
||||
}
|
||||
|
||||
set category(ExerciseCategory category) {
|
||||
this.categoryId = category.id;
|
||||
this.categoryObj = category;
|
||||
categoryId = category.id;
|
||||
categoryObj = category;
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -43,8 +43,8 @@ class Image {
|
||||
});
|
||||
|
||||
Image.emtpy() {
|
||||
this.date = DateTime.now();
|
||||
this.description = '';
|
||||
date = DateTime.now();
|
||||
description = '';
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/exceptions/no_such_entry_exception.dart';
|
||||
import 'package:wger/models/measurements/measurement_entry.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'measurement_category.g.dart';
|
||||
|
||||
@@ -19,7 +19,7 @@ class MeasurementCategory extends Equatable {
|
||||
@JsonKey(defaultValue: [], toJson: _nullValue)
|
||||
final List<MeasurementEntry> entries;
|
||||
|
||||
MeasurementCategory({
|
||||
const MeasurementCategory({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.unit,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'measurement_entry.g.dart';
|
||||
|
||||
@@ -21,7 +21,7 @@ class MeasurementEntry extends Equatable {
|
||||
@JsonKey(required: true, defaultValue: '')
|
||||
final String notes;
|
||||
|
||||
MeasurementEntry({
|
||||
const MeasurementEntry({
|
||||
required this.id,
|
||||
required this.category,
|
||||
required this.date,
|
||||
|
||||
@@ -65,11 +65,11 @@ class Log {
|
||||
});
|
||||
|
||||
Log.fromMealItem(MealItem mealItem, this.planId, [DateTime? dateTime]) {
|
||||
this.ingredientId = mealItem.ingredientId;
|
||||
this.ingredientObj = mealItem.ingredientObj;
|
||||
this.weightUnitId = mealItem.weightUnitId;
|
||||
this.datetime = dateTime ?? DateTime.now();
|
||||
this.amount = mealItem.amount;
|
||||
ingredientId = mealItem.ingredientId;
|
||||
ingredientObj = mealItem.ingredientObj;
|
||||
weightUnitId = mealItem.weightUnitId;
|
||||
datetime = dateTime ?? DateTime.now();
|
||||
amount = mealItem.amount;
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
@@ -79,11 +79,11 @@ class Log {
|
||||
/// Calculations
|
||||
NutritionalValues get nutritionalValues {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
final out = NutritionalValues();
|
||||
|
||||
//final weight = amount;
|
||||
final weight =
|
||||
this.weightUnitObj == null ? amount : amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
weightUnitObj == null ? amount : amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
|
||||
out.energy = ingredientObj.energy * weight / 100;
|
||||
out.protein = ingredientObj.protein * weight / 100;
|
||||
|
||||
@@ -46,7 +46,7 @@ class Meal {
|
||||
List<MealItem>? mealItems,
|
||||
}) {
|
||||
if (plan != null) {
|
||||
this.planId = plan;
|
||||
planId = plan;
|
||||
}
|
||||
|
||||
this.mealItems = mealItems ?? [];
|
||||
@@ -63,7 +63,7 @@ class Meal {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
|
||||
for (var item in mealItems) {
|
||||
for (final item in mealItems) {
|
||||
out += item.nutritionalValues;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class MealItem {
|
||||
/// Calculations
|
||||
NutritionalValues get nutritionalValues {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
final out = NutritionalValues();
|
||||
|
||||
//final weight = this.weightUnit == null ? amount : amount * weightUnit.amount * weightUnit.grams;
|
||||
final weight = amount;
|
||||
|
||||
@@ -68,7 +68,7 @@ class NutritionalPlan {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
|
||||
for (var meal in meals) {
|
||||
for (final meal in meals) {
|
||||
out += meal.nutritionalValues;
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ class NutritionalPlan {
|
||||
}
|
||||
|
||||
Map<DateTime, NutritionalValues> get logEntriesValues {
|
||||
var out = <DateTime, NutritionalValues>{};
|
||||
for (var log in logs) {
|
||||
final out = <DateTime, NutritionalValues>{};
|
||||
for (final log in logs) {
|
||||
final date = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
|
||||
if (!out.containsKey(date)) {
|
||||
@@ -114,7 +114,7 @@ class NutritionalPlan {
|
||||
|
||||
/// Returns the nutritional values for the given date
|
||||
NutritionalValues? getValuesForDate(DateTime date) {
|
||||
final values = this.logEntriesValues;
|
||||
final values = logEntriesValues;
|
||||
final dateKey = DateTime(date.year, date.month, date.day);
|
||||
|
||||
return values.containsKey(dateKey) ? values[dateKey] : null;
|
||||
@@ -122,8 +122,8 @@ class NutritionalPlan {
|
||||
|
||||
/// Returns the nutritional logs for the given date
|
||||
List<Log> getLogsForDate(DateTime date) {
|
||||
List<Log> out = [];
|
||||
for (var log in logs) {
|
||||
final List<Log> out = [];
|
||||
for (final log in logs) {
|
||||
final dateKey = DateTime(date.year, date.month, date.day);
|
||||
final logKey = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class NutritionalValues {
|
||||
);
|
||||
|
||||
/// Convert to kilo joules
|
||||
get energyKj {
|
||||
double get energyKj {
|
||||
return energy * 4.184;
|
||||
}
|
||||
|
||||
@@ -57,17 +57,18 @@ class NutritionalValues {
|
||||
|
||||
NutritionalValues operator +(NutritionalValues o) {
|
||||
return NutritionalValues.values(
|
||||
this.energy + o.energy,
|
||||
this.protein + o.protein,
|
||||
this.carbohydrates + o.carbohydrates,
|
||||
this.carbohydratesSugar + o.carbohydratesSugar,
|
||||
this.fat + o.fat,
|
||||
this.fatSaturated + o.fatSaturated,
|
||||
this.fibres + o.fibres,
|
||||
this.sodium + o.sodium,
|
||||
energy + o.energy,
|
||||
protein + o.protein,
|
||||
carbohydrates + o.carbohydrates,
|
||||
carbohydratesSugar + o.carbohydratesSugar,
|
||||
fat + o.fat,
|
||||
fatSaturated + o.fatSaturated,
|
||||
fibres + o.fibres,
|
||||
sodium + o.sodium,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(o) {
|
||||
return o is NutritionalValues &&
|
||||
energy == o.energy &&
|
||||
@@ -80,13 +81,14 @@ class NutritionalValues {
|
||||
sodium == o.sodium;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => super.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fibres, s: $sodium';
|
||||
}
|
||||
|
||||
//@override
|
||||
// TODO(x): implement hashCode
|
||||
//int get hashCode => super.hashCode;
|
||||
}
|
||||
|
||||
class BaseNutritionalValues {
|
||||
|
||||
@@ -53,8 +53,8 @@ class Day {
|
||||
//late WorkoutPlan workout;
|
||||
|
||||
Day() {
|
||||
this.daysOfWeek = [];
|
||||
this.sets = [];
|
||||
daysOfWeek = [];
|
||||
sets = [];
|
||||
}
|
||||
|
||||
String getDayName(int weekDay) {
|
||||
|
||||
@@ -87,18 +87,18 @@ class Log {
|
||||
Map<String, dynamic> toJson() => _$LogToJson(this);
|
||||
|
||||
set exercise(Exercise exercise) {
|
||||
this.exerciseObj = exercise;
|
||||
this.exerciseId = exercise.id;
|
||||
exerciseObj = exercise;
|
||||
exerciseId = exercise.id;
|
||||
}
|
||||
|
||||
set weightUnit(WeightUnit weightUnit) {
|
||||
this.weightUnitObj = weightUnit;
|
||||
this.weightUnitId = weightUnit.id;
|
||||
weightUnitObj = weightUnit;
|
||||
weightUnitId = weightUnit.id;
|
||||
}
|
||||
|
||||
set repetitionUnit(RepetitionUnit repetitionUnit) {
|
||||
this.repetitionUnitObj = repetitionUnit;
|
||||
this.repetitionUnitId = repetitionUnit.id;
|
||||
repetitionUnitObj = repetitionUnit;
|
||||
repetitionUnitId = repetitionUnit.id;
|
||||
}
|
||||
|
||||
void setRir(String rir) {
|
||||
@@ -119,6 +119,7 @@ class Log {
|
||||
///
|
||||
/// Two logs are considered equal if their content is equal. This is used e.g.
|
||||
/// in lists where we want to have unique values
|
||||
@override
|
||||
bool operator ==(o) {
|
||||
return o is Log &&
|
||||
exerciseId == o.exerciseId &&
|
||||
|
||||
@@ -76,8 +76,8 @@ class Set {
|
||||
this.sets = sets ?? DEFAULT_NR_SETS;
|
||||
this.order = order ?? 1;
|
||||
this.comment = comment ?? '';
|
||||
this.exercisesObj = exercises ?? [];
|
||||
this.exercisesIds = exercisesObj.map((e) => e.id).toList();
|
||||
exercisesObj = exercises ?? [];
|
||||
exercisesIds = exercisesObj.map((e) => e.id).toList();
|
||||
this.settings = settings ?? [];
|
||||
this.settingsComputed = settingsComputed ?? [];
|
||||
if (day != null) {
|
||||
@@ -88,17 +88,17 @@ class Set {
|
||||
/// Return only one setting object per exercise, this makes rendering workout
|
||||
/// plans easier and the gym mode uses the synthetic settings anyway.
|
||||
List<Setting> get settingsFiltered {
|
||||
List<Setting> out = [];
|
||||
final List<Setting> out = [];
|
||||
|
||||
settings.forEach((setting) {
|
||||
for (final setting in settings) {
|
||||
final foundSettings = out.where(
|
||||
(element) => element.exerciseId == setting.exerciseId,
|
||||
);
|
||||
|
||||
if (foundSettings.length == 0) {
|
||||
if (foundSettings.isEmpty) {
|
||||
out.add(setting);
|
||||
}
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -119,11 +119,11 @@ class Set {
|
||||
|
||||
/// Returns a list with all repetitions for the given exercise
|
||||
List<String> getSmartRepr(Exercise exercise) {
|
||||
List<String> out = [];
|
||||
final List<String> out = [];
|
||||
|
||||
final settingList = filterSettingsByExercise(exercise);
|
||||
|
||||
if (settingList.length == 0) {
|
||||
if (settingList.isEmpty) {
|
||||
out.add('');
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ class Set {
|
||||
}
|
||||
|
||||
if (settingList.length > 1) {
|
||||
for (var setting in settingList) {
|
||||
for (final setting in settingList) {
|
||||
out.add(setting.singleSettingRepText.replaceAll('\n', ''));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class Setting {
|
||||
|
||||
void setRir(String newRir) {
|
||||
if (POSSIBLE_RIR_VALUES.contains(newRir)) {
|
||||
this.rir = newRir;
|
||||
rir = newRir;
|
||||
} else {
|
||||
throw Exception('RiR value not allowed: $newRir');
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/workouts/day.dart';
|
||||
@@ -87,16 +85,16 @@ class WorkoutPlan {
|
||||
|
||||
/// Massages the log data to more easily present on the log overview
|
||||
///
|
||||
LinkedHashMap<DateTime, Map<String, dynamic>> get logData {
|
||||
var out = LinkedHashMap<DateTime, Map<String, dynamic>>();
|
||||
for (var log in logs) {
|
||||
Map<DateTime, Map<String, dynamic>> get logData {
|
||||
final out = <DateTime, Map<String, dynamic>>{};
|
||||
for (final log in logs) {
|
||||
final exercise = log.exerciseObj;
|
||||
final date = log.date;
|
||||
|
||||
if (!out.containsKey(date)) {
|
||||
out[date] = {
|
||||
'session': null,
|
||||
'exercises': LinkedHashMap<Exercise, List<Log>>(),
|
||||
'exercises': <Exercise, List<Log>>{},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
|
||||
import 'helpers.dart';
|
||||
|
||||
@@ -72,7 +72,7 @@ class AuthProvider with ChangeNotifier {
|
||||
|
||||
/// (flutter) Application version
|
||||
Future<void> setApplicationVersion() async {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
applicationVersion = packageInfo;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ class AuthProvider with ChangeNotifier {
|
||||
required String email,
|
||||
required String serverUrl,
|
||||
}) async {
|
||||
final uri = Uri.parse(serverUrl + '/api/v2/register/');
|
||||
Map<String, String>? metadata = Map();
|
||||
final uri = Uri.parse('$serverUrl/api/v2/register/');
|
||||
Map<String, String>? metadata = {};
|
||||
|
||||
// Read the api key from the manifest file
|
||||
try {
|
||||
@@ -95,7 +95,7 @@ class AuthProvider with ChangeNotifier {
|
||||
|
||||
// Register
|
||||
try {
|
||||
Map<String, String> data = {'username': username, 'password': password};
|
||||
final Map<String, String> data = {'username': username, 'password': password};
|
||||
if (email != '') {
|
||||
data['email'] = email;
|
||||
}
|
||||
@@ -115,13 +115,13 @@ class AuthProvider with ChangeNotifier {
|
||||
|
||||
login(username, password, serverUrl);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Authenticates a user
|
||||
Future<void> login(String username, String password, String serverUrl) async {
|
||||
final uri = Uri.parse(serverUrl + '/api/v2/login/');
|
||||
final uri = Uri.parse('$serverUrl/api/v2/login/');
|
||||
await logout();
|
||||
|
||||
try {
|
||||
@@ -167,7 +167,7 @@ class AuthProvider with ChangeNotifier {
|
||||
prefs.setString('userData', userData);
|
||||
prefs.setString('lastServer', serverData);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ class AuthProvider with ChangeNotifier {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
token = extractedUserData['token']!;
|
||||
serverUrl = extractedUserData['serverUrl']!;
|
||||
token = extractedUserData['token'];
|
||||
serverUrl = extractedUserData['serverUrl'];
|
||||
// _userId = extractedUserData['userId'];
|
||||
// _expiryDate = expiryDate;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class WgerBaseProvider {
|
||||
late http.Client client;
|
||||
|
||||
WgerBaseProvider(this.auth, [http.Client? client]) {
|
||||
this.auth = auth;
|
||||
auth = auth;
|
||||
this.client = client ?? http.Client();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ class WgerBaseProvider {
|
||||
|
||||
// Something wrong with our request
|
||||
if (response.statusCode >= 400) {
|
||||
print(response);
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:wger/models/body_weight/weight_entry.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/models/body_weight/weight_entry.dart';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
|
||||
@@ -28,7 +28,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
List<WeightEntry> _entries = [];
|
||||
BodyWeightProvider(AuthProvider auth, List<WeightEntry> entries, [http.Client? client])
|
||||
: this._entries = entries,
|
||||
: _entries = entries,
|
||||
super(auth, client);
|
||||
|
||||
List<WeightEntry> get items {
|
||||
@@ -42,7 +42,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Returns the latest (newest) weight entry or null if there are no entries
|
||||
WeightEntry? getLastEntry() {
|
||||
return this._entries.length > 0 ? this._entries.last : null;
|
||||
return _entries.isNotEmpty ? _entries.last : null;
|
||||
}
|
||||
|
||||
WeightEntry findById(int id) {
|
||||
@@ -73,7 +73,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
Future<WeightEntry> addEntry(WeightEntry entry) async {
|
||||
// Create entry and return it
|
||||
final data = await post(entry.toJson(), makeUrl(bodyWeightUrl));
|
||||
WeightEntry weightEntry = WeightEntry.fromJson(data);
|
||||
final WeightEntry weightEntry = WeightEntry.fromJson(data);
|
||||
_entries.add(weightEntry);
|
||||
_entries.sort((a, b) => b.date.compareTo(a.date));
|
||||
notifyListeners();
|
||||
@@ -89,7 +89,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);
|
||||
var existingWeightEntry = _entries[existingEntryIndex];
|
||||
final existingWeightEntry = _entries[existingEntryIndex];
|
||||
_entries.removeAt(existingEntryIndex);
|
||||
notifyListeners();
|
||||
|
||||
|
||||
@@ -25,16 +25,20 @@ import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/exercises/category.dart';
|
||||
import 'package:wger/models/exercises/equipment.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/exercises/muscle.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
|
||||
class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
ExercisesProvider(AuthProvider auth, List<Exercise> entries, [http.Client? client])
|
||||
: _exercises = entries,
|
||||
super(auth, client);
|
||||
|
||||
static const daysToCache = 7;
|
||||
|
||||
static const _exerciseInfoUrlPath = 'exerciseinfo';
|
||||
@@ -46,14 +50,10 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
static const _musclesUrlPath = 'muscle';
|
||||
static const _equipmentUrlPath = 'equipment';
|
||||
|
||||
List<Exercise> _exercises = [];
|
||||
List<ExerciseCategory> _categories = [];
|
||||
List<Muscle> _muscles = [];
|
||||
List<Equipment> _equipment = [];
|
||||
|
||||
ExercisesProvider(AuthProvider auth, List<Exercise> entries, [http.Client? client])
|
||||
: this._exercises = entries,
|
||||
super(auth, client);
|
||||
final List<Exercise> _exercises;
|
||||
final List<ExerciseCategory> _categories = [];
|
||||
final List<Muscle> _muscles = [];
|
||||
final List<Equipment> _equipment = [];
|
||||
|
||||
List<Exercise> get items {
|
||||
return [..._exercises];
|
||||
@@ -72,7 +72,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_categories.add(ExerciseCategory.fromJson(category));
|
||||
}
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_muscles.add(Muscle.fromJson(muscle));
|
||||
}
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_equipment.add(Equipment.fromJson(equipment));
|
||||
}
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
} on MissingRequiredKeysException catch (error) {
|
||||
log(error.missingKeys.toString());
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Process the response
|
||||
final result = json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
|
||||
for (var entry in result) {
|
||||
for (final entry in result) {
|
||||
entry['exercise_obj'] = await fetchAndSetExercise(entry['data']['id']);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -33,7 +33,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
List<gallery.Image> images = [];
|
||||
|
||||
GalleryProvider(AuthProvider auth, List<gallery.Image> entries, [http.Client? client])
|
||||
: this.images = entries,
|
||||
: images = entries,
|
||||
super(auth, client);
|
||||
|
||||
/// Clears all lists
|
||||
@@ -48,7 +48,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
final data = await fetch(makeUrl(_galleryUrlPath));
|
||||
|
||||
data['results'].forEach((e) {
|
||||
gallery.Image image = gallery.Image.fromJson(e);
|
||||
final gallery.Image image = gallery.Image.fromJson(e);
|
||||
images.add(image);
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> addImage(gallery.Image image, XFile imageFile) async {
|
||||
// create multipart request
|
||||
var request = http.MultipartRequest('POST', makeUrl(_galleryUrlPath));
|
||||
final request = http.MultipartRequest('POST', makeUrl(_galleryUrlPath));
|
||||
request.headers.addAll({
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
@@ -66,7 +66,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
request.fields['date'] = toDate(image.date)!;
|
||||
request.fields['description'] = image.description;
|
||||
|
||||
var res = await request.send();
|
||||
final res = await request.send();
|
||||
final respStr = await res.stream.bytesToString();
|
||||
|
||||
images.add(gallery.Image.fromJson(json.decode(respStr)));
|
||||
@@ -76,7 +76,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editImage(gallery.Image image, XFile? imageFile) async {
|
||||
var request = http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
|
||||
final request = http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
|
||||
request.headers.addAll({
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
|
||||
@@ -24,9 +24,9 @@ Uri makeUri(
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
]) {
|
||||
Uri uriServer = Uri.parse(serverUrl);
|
||||
final Uri uriServer = Uri.parse(serverUrl);
|
||||
|
||||
var pathList = ['api', 'v2', path];
|
||||
final pathList = ['api', 'v2', path];
|
||||
if (id != null) {
|
||||
pathList.add(id.toString());
|
||||
}
|
||||
@@ -38,7 +38,7 @@ Uri makeUri(
|
||||
scheme: uriServer.scheme,
|
||||
host: uriServer.host,
|
||||
port: uriServer.port,
|
||||
path: pathList.join('/') + '/',
|
||||
path: '${pathList.join('/')}/',
|
||||
queryParameters: query,
|
||||
);
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
for (final entry in data['results']) {
|
||||
loadedEntries.add(MeasurementEntry.fromJson(entry));
|
||||
}
|
||||
MeasurementCategory editedCategory = category.copyWith(entries: loadedEntries);
|
||||
final MeasurementCategory editedCategory = category.copyWith(entries: loadedEntries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, editedCategory);
|
||||
notifyListeners();
|
||||
@@ -84,12 +84,12 @@ class MeasurementProvider with ChangeNotifier {
|
||||
/// Fetches and sets the measurement categories and their entries
|
||||
Future<void> fetchAndSetAllCategoriesAndEntries() async {
|
||||
await fetchAndSetCategories();
|
||||
await Future.wait(_categories.map((e) => this.fetchAndSetCategoryEntries(e.id!)).toList());
|
||||
await Future.wait(_categories.map((e) => fetchAndSetCategoryEntries(e.id!)).toList());
|
||||
}
|
||||
|
||||
/// Adds a measurement category
|
||||
Future<void> addCategory(MeasurementCategory category) async {
|
||||
Uri postUri = baseProvider.makeUrl(_categoryUrl);
|
||||
final Uri postUri = baseProvider.makeUrl(_categoryUrl);
|
||||
|
||||
final Map<String, dynamic> newCategoryMap = await baseProvider.post(category.toJson(), postUri);
|
||||
final MeasurementCategory newCategory = MeasurementCategory.fromJson(newCategoryMap);
|
||||
@@ -100,8 +100,8 @@ class MeasurementProvider with ChangeNotifier {
|
||||
|
||||
/// Deletes a measurement category
|
||||
Future<void> deleteCategory(int id) async {
|
||||
MeasurementCategory category = findCategoryById(id);
|
||||
int categoryIndex = _categories.indexOf(category);
|
||||
final MeasurementCategory category = findCategoryById(id);
|
||||
final int categoryIndex = _categories.indexOf(category);
|
||||
_categories.remove(category);
|
||||
notifyListeners();
|
||||
|
||||
@@ -110,7 +110,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
} on WgerHttpException catch (e) {
|
||||
_categories.insert(categoryIndex, category);
|
||||
notifyListeners();
|
||||
throw e;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
/// Currently there isn't any fallback if the call to the api is unsuccessful, as WgerBaseProvider.patch only returns the response body and not the whole response
|
||||
Future<void> editCategory(int id, String? newName, String? newUnit) async {
|
||||
final MeasurementCategory oldCategory = findCategoryById(id);
|
||||
int categoryIndex = _categories.indexOf(oldCategory);
|
||||
final int categoryIndex = _categories.indexOf(oldCategory);
|
||||
final MeasurementCategory tempNewCategory = oldCategory.copyWith(name: newName, unit: newUnit);
|
||||
|
||||
final Map<String, dynamic> response = await baseProvider.patch(
|
||||
@@ -126,7 +126,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
baseProvider.makeUrl(_categoryUrl, id: id),
|
||||
);
|
||||
final MeasurementCategory newCategory =
|
||||
(MeasurementCategory.fromJson(response)).copyWith(entries: oldCategory.entries);
|
||||
MeasurementCategory.fromJson(response).copyWith(entries: oldCategory.entries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, newCategory);
|
||||
notifyListeners();
|
||||
@@ -134,12 +134,12 @@ class MeasurementProvider with ChangeNotifier {
|
||||
|
||||
/// Adds a measurement entry
|
||||
Future<void> addEntry(MeasurementEntry entry) async {
|
||||
Uri postUri = baseProvider.makeUrl(_entryUrl);
|
||||
final Uri postUri = baseProvider.makeUrl(_entryUrl);
|
||||
|
||||
final Map<String, dynamic> newEntryMap = await baseProvider.post(entry.toJson(), postUri);
|
||||
final MeasurementEntry newEntry = MeasurementEntry.fromJson(newEntryMap);
|
||||
|
||||
MeasurementCategory category = findCategoryById(newEntry.category);
|
||||
final MeasurementCategory category = findCategoryById(newEntry.category);
|
||||
|
||||
category.entries.add(newEntry);
|
||||
category.entries.sort((a, b) => b.date.compareTo(a.date));
|
||||
@@ -158,10 +158,10 @@ class MeasurementProvider with ChangeNotifier {
|
||||
|
||||
try {
|
||||
await baseProvider.deleteRequest(_entryUrl, id);
|
||||
} on WgerHttpException catch (e) {
|
||||
} on WgerHttpException {
|
||||
category.entries.insert(entryIndex, entry);
|
||||
notifyListeners();
|
||||
throw e;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.dart';
|
||||
import 'package:wger/models/nutrition/log.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
@@ -46,7 +46,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
List<Ingredient> _ingredients = [];
|
||||
|
||||
NutritionPlansProvider(AuthProvider auth, List<NutritionalPlan> entries, [http.Client? client])
|
||||
: this._plans = entries,
|
||||
: _plans = entries,
|
||||
super(auth, client);
|
||||
|
||||
List<NutritionalPlan> get items {
|
||||
@@ -62,7 +62,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Returns the current active nutritional plan. At the moment this is just
|
||||
/// the latest, but this might change in the future.
|
||||
NutritionalPlan? get currentPlan {
|
||||
if (_plans.length > 0) {
|
||||
if (_plans.isNotEmpty) {
|
||||
return _plans.first;
|
||||
}
|
||||
}
|
||||
@@ -72,9 +72,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Meal? findMealById(int id) {
|
||||
for (var plan in _plans) {
|
||||
for (final plan in _plans) {
|
||||
try {
|
||||
var meal = plan.meals.firstWhere((plan) => plan.id == id);
|
||||
final meal = plan.meals.firstWhere((plan) => plan.id == id);
|
||||
return meal;
|
||||
} on StateError catch (e) {}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
NutritionalPlan plan;
|
||||
try {
|
||||
plan = findById(planId);
|
||||
} on StateError catch (e) {
|
||||
} on StateError {
|
||||
plan = await fetchAndSetPlanSparse(planId);
|
||||
}
|
||||
|
||||
@@ -128,12 +128,12 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
final fullPlanData = await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId));
|
||||
|
||||
// Meals
|
||||
List<Meal> meals = [];
|
||||
for (var mealData in fullPlanData['meals']) {
|
||||
List<MealItem> mealItems = [];
|
||||
final List<Meal> meals = [];
|
||||
for (final mealData in fullPlanData['meals']) {
|
||||
final List<MealItem> mealItems = [];
|
||||
final meal = Meal.fromJson(mealData);
|
||||
|
||||
for (var mealItemData in mealData['meal_items']) {
|
||||
for (final mealItemData in mealData['meal_items']) {
|
||||
final mealItem = MealItem.fromJson(mealItemData);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
mealItems.add(mealItem);
|
||||
@@ -167,7 +167,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> deletePlan(int id) async {
|
||||
final existingPlanIndex = _plans.indexWhere((element) => element.id == id);
|
||||
var existingPlan = _plans[existingPlanIndex];
|
||||
final existingPlan = _plans[existingPlanIndex];
|
||||
_plans.removeAt(existingPlanIndex);
|
||||
notifyListeners();
|
||||
|
||||
@@ -183,7 +183,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Adds a meal to a plan
|
||||
Future<Meal> addMeal(Meal meal, int planId) async {
|
||||
var plan = findById(planId);
|
||||
final plan = findById(planId);
|
||||
final data = await post(meal.toJson(), makeUrl(_mealPath));
|
||||
|
||||
meal = Meal.fromJson(data);
|
||||
@@ -205,9 +205,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Deletes a meal
|
||||
Future<void> deleteMeal(Meal meal) async {
|
||||
// Get the meal
|
||||
var plan = findById(meal.planId);
|
||||
final plan = findById(meal.planId);
|
||||
final mealIndex = plan.meals.indexWhere((e) => e.id == meal.id);
|
||||
var existingMeal = plan.meals[mealIndex];
|
||||
final existingMeal = plan.meals[mealIndex];
|
||||
plan.meals.removeAt(mealIndex);
|
||||
notifyListeners();
|
||||
|
||||
@@ -235,9 +235,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Deletes a meal
|
||||
Future<void> deleteMealItem(MealItem mealItem) async {
|
||||
// Get the meal
|
||||
var meal = findMealById(mealItem.mealId)!;
|
||||
final meal = findMealById(mealItem.mealId)!;
|
||||
final mealItemIndex = meal.mealItems.indexWhere((e) => e.id == mealItem.id);
|
||||
var existingMealItem = meal.mealItems[mealItemIndex];
|
||||
final existingMealItem = meal.mealItems[mealItemIndex];
|
||||
meal.mealItems.removeAt(mealItemIndex);
|
||||
notifyListeners();
|
||||
|
||||
@@ -261,7 +261,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
return ingredient;
|
||||
|
||||
// Get ingredient from the server and save to cache
|
||||
} on StateError catch (e) {
|
||||
} on StateError {
|
||||
final data = await fetch(makeUrl(_ingredientPath, id: ingredientId));
|
||||
ingredient = Ingredient.fromJson(data);
|
||||
_ingredients.add(ingredient);
|
||||
@@ -328,9 +328,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Log meal to nutrition diary
|
||||
Future<void> logMealToDiary(Meal meal) async {
|
||||
for (var item in meal.mealItems) {
|
||||
for (final item in meal.mealItems) {
|
||||
final plan = findById(meal.planId);
|
||||
Log log = Log.fromMealItem(item, plan.id!);
|
||||
final Log log = Log.fromMealItem(item, plan.id!);
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
log.id = data['id'];
|
||||
@@ -350,14 +350,14 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Load nutrition diary entries for plan
|
||||
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
|
||||
// TODO: update fetch to that it can use the pagination
|
||||
// TODO(x): update fetch to that it can use the pagination
|
||||
final data = await fetch(
|
||||
makeUrl(_nutritionDiaryPath, query: {'plan': plan.id.toString(), 'limit': '1000'}),
|
||||
);
|
||||
|
||||
plan.logs = [];
|
||||
for (var logData in data['results']) {
|
||||
var log = Log.fromJson(logData);
|
||||
for (final logData in data['results']) {
|
||||
final log = Log.fromJson(logData);
|
||||
final ingredient = await fetchIngredient(log.ingredientId);
|
||||
log.ingredientObj = ingredient;
|
||||
plan.logs.add(log);
|
||||
|
||||
@@ -22,9 +22,9 @@ import 'dart:developer' as dev;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/models/workouts/day.dart';
|
||||
import 'package:wger/models/workouts/log.dart';
|
||||
import 'package:wger/models/workouts/repetition_unit.dart';
|
||||
@@ -48,15 +48,15 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
static const _repetitionUnitUrlPath = 'setting-repetitionunit';
|
||||
|
||||
WorkoutPlan? _currentPlan;
|
||||
ExercisesProvider _exercises;
|
||||
final ExercisesProvider _exercises;
|
||||
List<WorkoutPlan> _workoutPlans = [];
|
||||
List<WeightUnit> _weightUnits = [];
|
||||
List<RepetitionUnit> _repetitionUnit = [];
|
||||
|
||||
WorkoutPlansProvider(AuthProvider auth, ExercisesProvider exercises, List<WorkoutPlan> entries,
|
||||
[http.Client? client])
|
||||
: this._exercises = exercises,
|
||||
this._workoutPlans = entries,
|
||||
: _exercises = exercises,
|
||||
_workoutPlans = entries,
|
||||
super(auth, client);
|
||||
|
||||
List<WorkoutPlan> get items {
|
||||
@@ -115,7 +115,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Returns the current active workout plan. At the moment this is just
|
||||
/// the latest, but this might change in the future.
|
||||
WorkoutPlan? get activePlan {
|
||||
if (_workoutPlans.length > 0) {
|
||||
if (_workoutPlans.isNotEmpty) {
|
||||
return _workoutPlans.first;
|
||||
}
|
||||
}
|
||||
@@ -182,13 +182,13 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Days
|
||||
List<Day> days = [];
|
||||
final List<Day> days = [];
|
||||
final daysData = await fetch(makeUrl(_daysUrlPath, query: {'training': plan.id.toString()}));
|
||||
for (final dayEntry in daysData['results']) {
|
||||
final day = Day.fromJson(dayEntry);
|
||||
|
||||
// Sets
|
||||
List<Set> sets = [];
|
||||
final List<Set> sets = [];
|
||||
final setData = await fetch(makeUrl(_setsUrlPath, query: {'exerciseday': day.id.toString()}));
|
||||
for (final setEntry in setData['results']) {
|
||||
final workoutSet = Set.fromJson(setEntry);
|
||||
@@ -196,7 +196,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
fetchComputedSettings(workoutSet); // request!
|
||||
|
||||
// Settings
|
||||
List<Setting> settings = [];
|
||||
final List<Setting> settings = [];
|
||||
final settingData = allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
|
||||
|
||||
for (final settingEntry in settingData) {
|
||||
@@ -225,7 +225,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Logs
|
||||
//
|
||||
// TODO: looping through all results in the pagination is something we will
|
||||
// TODO(x): looping through all results in the pagination is something we will
|
||||
// probably need in the future. We should put this in some function or something
|
||||
// so that we can reuse it.
|
||||
plan.logs = [];
|
||||
@@ -240,7 +240,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
for (final entry in logData['results']) {
|
||||
try {
|
||||
var log = Log.fromJson(entry);
|
||||
final log = Log.fromJson(entry);
|
||||
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);
|
||||
@@ -278,7 +278,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> deleteWorkout(int id) async {
|
||||
final existingWorkoutIndex = _workoutPlans.indexWhere((element) => element.id == id);
|
||||
var existingWorkout = _workoutPlans[existingWorkoutIndex];
|
||||
final existingWorkout = _workoutPlans[existingWorkoutIndex];
|
||||
_workoutPlans.removeAt(existingWorkoutIndex);
|
||||
notifyListeners();
|
||||
|
||||
@@ -312,7 +312,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_repetitionUnit.add(RepetitionUnit.fromJson(unit));
|
||||
}
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_weightUnits.add(WeightUnit.fromJson(unit));
|
||||
}
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> deleteDay(Day day) async {
|
||||
await deleteRequest(_daysUrlPath, day.id!);
|
||||
for (var workout in _workoutPlans) {
|
||||
for (final workout in _workoutPlans) {
|
||||
workout.days.removeWhere((element) => element.id == day.id);
|
||||
}
|
||||
notifyListeners();
|
||||
@@ -417,13 +417,13 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
Future<void> fetchComputedSettings(Set workoutSet) async {
|
||||
final data = await fetch(makeUrl(
|
||||
_setsUrlPath,
|
||||
id: workoutSet.id!,
|
||||
id: workoutSet.id,
|
||||
objectMethod: 'computed_settings',
|
||||
));
|
||||
|
||||
List<Setting> settings = [];
|
||||
final List<Setting> settings = [];
|
||||
data['results'].forEach((e) {
|
||||
Setting workoutSetting = Setting.fromJson(e);
|
||||
final Setting workoutSetting = Setting.fromJson(e);
|
||||
|
||||
workoutSetting.weightUnitObj = _weightUnits.firstWhere(
|
||||
(unit) => unit.id == workoutSetting.weightUnitId,
|
||||
@@ -442,7 +442,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
final data = await fetch(
|
||||
makeUrl(
|
||||
_setsUrlPath,
|
||||
id: workoutSet.id!,
|
||||
id: workoutSet.id,
|
||||
objectMethod: 'smart_text',
|
||||
query: {'exercise': exercise.id.toString()},
|
||||
),
|
||||
@@ -454,8 +454,8 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
Future<void> deleteSet(Set workoutSet) async {
|
||||
await deleteRequest(_setsUrlPath, workoutSet.id!);
|
||||
|
||||
for (var workout in _workoutPlans) {
|
||||
for (var day in workout.days) {
|
||||
for (final workout in _workoutPlans) {
|
||||
for (final day in workout.days) {
|
||||
day.sets.removeWhere((element) => element.id == workoutSet.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
|
||||
import '../providers/auth.dart';
|
||||
|
||||
@@ -42,7 +42,7 @@ class AuthScreen extends StatelessWidget {
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
SingleChildScrollView(
|
||||
child: Container(
|
||||
child: SizedBox(
|
||||
height: deviceSize.height,
|
||||
width: deviceSize.width,
|
||||
child: Column(
|
||||
@@ -92,7 +92,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey();
|
||||
AuthMode _authMode = AuthMode.Login;
|
||||
bool _hideCustomServer = true;
|
||||
Map<String, String> _authData = {
|
||||
final Map<String, String> _authData = {
|
||||
'username': '',
|
||||
'email': '',
|
||||
'password': '',
|
||||
@@ -187,7 +187,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
labelText: AppLocalizations.of(context).username,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
autofillHints: [AutofillHints.username],
|
||||
autofillHints: const [AutofillHints.username],
|
||||
controller: _usernameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
@@ -208,7 +208,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
TextFormField(
|
||||
key: Key('inputEmail'),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).email),
|
||||
autofillHints: [AutofillHints.email],
|
||||
autofillHints: const [AutofillHints.email],
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
@@ -225,9 +225,9 @@ class _AuthCardState extends State<AuthCard> {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
key: Key('inputPassword'),
|
||||
key: const Key('inputPassword'),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).password),
|
||||
autofillHints: [AutofillHints.password],
|
||||
autofillHints: const [AutofillHints.password],
|
||||
obscureText: true,
|
||||
controller: _passwordController,
|
||||
textInputAction: TextInputAction.next,
|
||||
|
||||
@@ -37,7 +37,7 @@ class GalleryScreen extends StatelessWidget {
|
||||
return Scaffold(
|
||||
appBar: WgerAppBar(AppLocalizations.of(context).gallery),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
|
||||
@@ -132,7 +132,7 @@ class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProvid
|
||||
AppLocalizations.of(context).loadingText,
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
Padding(padding: EdgeInsets.symmetric(vertical: 8)),
|
||||
const Padding(padding: EdgeInsets.symmetric(vertical: 8)),
|
||||
LinearProgressIndicator(
|
||||
backgroundColor: Theme.of(context).accentColor,
|
||||
),
|
||||
|
||||
@@ -42,7 +42,7 @@ class MeasurementEntriesScreen extends StatelessWidget {
|
||||
title: Text(category.name),
|
||||
actions: [
|
||||
PopupMenuButton<MeasurementOptions>(
|
||||
icon: Icon(Icons.more_vert),
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case MeasurementOptions.edit:
|
||||
|
||||
@@ -103,7 +103,7 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
? SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
Container(
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
|
||||
@@ -46,7 +46,7 @@ class WorkoutPlanScreen extends StatefulWidget {
|
||||
class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
WorkoutScreenMode _mode = WorkoutScreenMode.workout;
|
||||
|
||||
_changeMode(WorkoutScreenMode newMode) {
|
||||
void _changeMode(WorkoutScreenMode newMode) {
|
||||
setState(() {
|
||||
_mode = newMode;
|
||||
});
|
||||
@@ -61,10 +61,9 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
switch (_mode) {
|
||||
case WorkoutScreenMode.workout:
|
||||
return WorkoutPlanDetail(plan, _changeMode);
|
||||
break;
|
||||
|
||||
case WorkoutScreenMode.log:
|
||||
return WorkoutLogs(plan, _changeMode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,16 +129,17 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) => SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
snapshot.connectionState == ConnectionState.waiting
|
||||
? Container(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
: Consumer<WorkoutPlansProvider>(
|
||||
builder: (context, value, child) => getBody(workoutPlan),
|
||||
),
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else
|
||||
Consumer<WorkoutPlansProvider>(
|
||||
builder: (context, value, child) => getBody(workoutPlan),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -49,7 +49,6 @@ final ThemeData wgerTheme = ThemeData(
|
||||
* General stuff
|
||||
*/
|
||||
primaryColor: wgerPrimaryColor,
|
||||
accentColor: wgerSecondaryColor,
|
||||
scaffoldBackgroundColor: wgerBackground,
|
||||
|
||||
// This makes the visual density adapt to the platform that you run
|
||||
@@ -58,7 +57,7 @@ final ThemeData wgerTheme = ThemeData(
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
|
||||
// Show icons in the system's bar in light colors
|
||||
appBarTheme: AppBarTheme(
|
||||
appBarTheme: const AppBarTheme(
|
||||
brightness: Brightness.dark,
|
||||
systemOverlayStyle: SystemUiOverlayStyle.dark,
|
||||
),
|
||||
@@ -67,26 +66,26 @@ final ThemeData wgerTheme = ThemeData(
|
||||
* Text theme
|
||||
*/
|
||||
textTheme: TextTheme(
|
||||
headline1: TextStyle(fontFamily: "OpenSansLight", color: Colors.black),
|
||||
headline2: TextStyle(fontFamily: "OpenSansLight", color: Colors.black),
|
||||
headline1: TextStyle(fontFamily: 'OpenSansLight', color: Colors.black),
|
||||
headline2: TextStyle(fontFamily: 'OpenSansLight', color: Colors.black),
|
||||
headline3: TextStyle(
|
||||
fontSize: materialSizes['h3']! * 0.8,
|
||||
fontFamily: "OpenSansBold",
|
||||
fontFamily: 'OpenSansBold',
|
||||
color: Colors.black,
|
||||
),
|
||||
headline4: TextStyle(
|
||||
fontSize: materialSizes['h4']! * 0.8,
|
||||
fontFamily: "OpenSansBold",
|
||||
fontFamily: 'OpenSansBold',
|
||||
color: Colors.black,
|
||||
),
|
||||
headline5: TextStyle(
|
||||
fontSize: materialSizes['h5']!,
|
||||
fontFamily: "OpenSansBold",
|
||||
fontSize: materialSizes['h5'],
|
||||
fontFamily: 'OpenSansBold',
|
||||
color: Colors.black,
|
||||
),
|
||||
headline6: TextStyle(
|
||||
fontSize: materialSizes['h6']! * 0.8,
|
||||
fontFamily: "OpenSansBold",
|
||||
fontFamily: 'OpenSansBold',
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
@@ -118,32 +117,33 @@ final ThemeData wgerTheme = ThemeData(
|
||||
sliderTheme: SliderThemeData(
|
||||
activeTrackColor: wgerPrimaryButtonColor,
|
||||
thumbColor: wgerPrimaryColor,
|
||||
));
|
||||
),
|
||||
colorScheme: ColorScheme.fromSwatch().copyWith(secondary: wgerSecondaryColor));
|
||||
|
||||
const wgerCalendarStyle = CalendarStyle(
|
||||
// Use `CalendarStyle` to customize the UI
|
||||
outsideDaysVisible: false,
|
||||
todayDecoration: const BoxDecoration(
|
||||
todayDecoration: BoxDecoration(
|
||||
color: Colors.amber,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
|
||||
markerDecoration: const BoxDecoration(
|
||||
markerDecoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
selectedDecoration: const BoxDecoration(
|
||||
selectedDecoration: BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeStartDecoration: const BoxDecoration(
|
||||
rangeStartDecoration: BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeEndDecoration: const BoxDecoration(
|
||||
rangeEndDecoration: BoxDecoration(
|
||||
color: wgerSecondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
rangeHighlightColor: wgerSecondaryColorLight,
|
||||
weekendTextStyle: const TextStyle(color: wgerSecondaryColor),
|
||||
weekendTextStyle: TextStyle(color: wgerSecondaryColor),
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@ class WgerAboutListTile extends StatelessWidget {
|
||||
await canLaunch(url)
|
||||
? await launch(url)
|
||||
: ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Could not open $url.")),
|
||||
SnackBar(content: Text('Could not open $url.')),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,7 +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(
|
||||
|
||||
@@ -38,7 +38,7 @@ class MeasurementChartWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final unitTickFormatter =
|
||||
charts.BasicNumericTickFormatterSpec((num? value) => '$value ${this.unit}');
|
||||
charts.BasicNumericTickFormatterSpec((num? value) => '$value $unit');
|
||||
|
||||
return charts.TimeSeriesChart(
|
||||
[
|
||||
@@ -50,9 +50,9 @@ class MeasurementChartWidget extends StatelessWidget {
|
||||
data: _entries,
|
||||
)
|
||||
],
|
||||
defaultRenderer: new charts.LineRendererConfig(includePoints: true),
|
||||
primaryMeasureAxis: new charts.NumericAxisSpec(
|
||||
tickProviderSpec: new charts.BasicNumericTickProviderSpec(zeroBound: false),
|
||||
defaultRenderer: charts.LineRendererConfig(includePoints: true),
|
||||
primaryMeasureAxis: charts.NumericAxisSpec(
|
||||
tickProviderSpec: charts.BasicNumericTickProviderSpec(zeroBound: false),
|
||||
tickFormatterSpec: unitTickFormatter,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -20,7 +20,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
|
||||
class MutedText extends StatelessWidget {
|
||||
String _text;
|
||||
final String _text;
|
||||
TextAlign _textAlign = TextAlign.left;
|
||||
|
||||
MutedText(
|
||||
@@ -29,7 +29,7 @@ class MutedText extends StatelessWidget {
|
||||
TextAlign? textAlign,
|
||||
}) : super(key: key) {
|
||||
if (textAlign != null) {
|
||||
this._textAlign = textAlign;
|
||||
_textAlign = textAlign;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class Event {
|
||||
}
|
||||
|
||||
class DashboardCalendarWidget extends StatefulWidget {
|
||||
DashboardCalendarWidget();
|
||||
const DashboardCalendarWidget();
|
||||
|
||||
@override
|
||||
_DashboardCalendarWidgetState createState() => _DashboardCalendarWidgetState();
|
||||
@@ -85,8 +85,8 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
|
||||
void loadEvents() async {
|
||||
// Process weight entries
|
||||
BodyWeightProvider weightProvider = Provider.of<BodyWeightProvider>(context, listen: false);
|
||||
for (var entry in weightProvider.items) {
|
||||
final BodyWeightProvider weightProvider = Provider.of<BodyWeightProvider>(context, listen: false);
|
||||
for (final entry in weightProvider.items) {
|
||||
final date = DateFormatLists.format(entry.date);
|
||||
|
||||
if (!_events.containsKey(date)) {
|
||||
@@ -98,10 +98,10 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
}
|
||||
|
||||
// Process measurements
|
||||
MeasurementProvider measurementProvider =
|
||||
final MeasurementProvider measurementProvider =
|
||||
Provider.of<MeasurementProvider>(context, listen: false);
|
||||
for (var category in measurementProvider.categories) {
|
||||
for (var entry in category.entries) {
|
||||
for (final category in measurementProvider.categories) {
|
||||
for (final entry in category.entries) {
|
||||
final date = DateFormatLists.format(entry.date);
|
||||
|
||||
if (!_events.containsKey(date)) {
|
||||
@@ -114,9 +114,9 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
}
|
||||
|
||||
// Process workout sessions
|
||||
WorkoutPlansProvider plans = Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
final WorkoutPlansProvider plans = Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
await plans.fetchSessionData().then((entries) {
|
||||
for (var entry in entries['results']) {
|
||||
for (final entry in entries['results']) {
|
||||
final session = WorkoutSession.fromJson(entry);
|
||||
final date = DateFormatLists.format(session.date);
|
||||
if (!_events.containsKey(date)) {
|
||||
@@ -136,10 +136,10 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
});
|
||||
|
||||
// Process nutritional plans
|
||||
NutritionPlansProvider nutritionProvider =
|
||||
final NutritionPlansProvider nutritionProvider =
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false);
|
||||
for (var plan in nutritionProvider.items) {
|
||||
for (var entry in plan.logEntriesValues.entries) {
|
||||
for (final plan in nutritionProvider.items) {
|
||||
for (final entry in plan.logEntriesValues.entries) {
|
||||
final date = DateFormatLists.format(entry.key);
|
||||
if (!_events.containsKey(date)) {
|
||||
_events[date] = [];
|
||||
|
||||
@@ -58,13 +58,13 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
}
|
||||
|
||||
List<Widget> getContent() {
|
||||
List<Widget> out = [];
|
||||
final List<Widget> out = [];
|
||||
|
||||
if (!_hasContent) {
|
||||
return out;
|
||||
}
|
||||
|
||||
for (var meal in _plan!.meals) {
|
||||
for (final meal in _plan!.meals) {
|
||||
out.add(
|
||||
Row(
|
||||
children: [
|
||||
@@ -113,7 +113,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
out.add(SizedBox(height: 5));
|
||||
|
||||
if (_showDetail) {
|
||||
meal.mealItems.forEach((item) {
|
||||
for (final item in meal.mealItems) {
|
||||
out.add(
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@@ -133,7 +133,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
out.add(SizedBox(height: 10));
|
||||
}
|
||||
out.add(Divider());
|
||||
@@ -177,8 +177,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
});
|
||||
},
|
||||
),
|
||||
_hasContent
|
||||
? Container(
|
||||
if (_hasContent) Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -190,8 +189,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
: NothingFound(
|
||||
) else NothingFound(
|
||||
AppLocalizations.of(context).noNutritionalPlans,
|
||||
AppLocalizations.of(context).newNutritionalPlan,
|
||||
PlanForm(),
|
||||
@@ -255,8 +253,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
weightEntriesData.items.length > 0
|
||||
? Column(
|
||||
if (weightEntriesData.items.isNotEmpty) Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
@@ -276,8 +273,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: NothingFound(
|
||||
) else NothingFound(
|
||||
AppLocalizations.of(context).noWeightEntries,
|
||||
AppLocalizations.of(context).newEntry,
|
||||
WeightForm(),
|
||||
@@ -317,14 +313,14 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
}
|
||||
|
||||
List<Widget> getContent() {
|
||||
List<Widget> out = [];
|
||||
final List<Widget> out = [];
|
||||
|
||||
if (!_hasContent) {
|
||||
return out;
|
||||
}
|
||||
|
||||
for (var day in _workoutPlan!.days) {
|
||||
out.add(Container(
|
||||
for (final day in _workoutPlan!.days) {
|
||||
out.add(SizedBox(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -350,8 +346,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
),
|
||||
));
|
||||
|
||||
day.sets.forEach((set) {
|
||||
out.add(Container(
|
||||
for (final set in day.sets) {
|
||||
out.add(SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -376,7 +372,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
],
|
||||
),
|
||||
));
|
||||
});
|
||||
}
|
||||
out.add(Divider());
|
||||
}
|
||||
|
||||
@@ -410,16 +406,14 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
});
|
||||
},
|
||||
),
|
||||
_hasContent
|
||||
? Container(
|
||||
if (_hasContent) Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
...getContent(),
|
||||
],
|
||||
),
|
||||
)
|
||||
: NothingFound(
|
||||
) else NothingFound(
|
||||
AppLocalizations.of(context).noWorkoutPlans,
|
||||
AppLocalizations.of(context).newWorkout,
|
||||
WorkoutForm(WorkoutPlan.empty()),
|
||||
@@ -448,11 +442,11 @@ class NothingFound extends StatelessWidget {
|
||||
final String _titleForm;
|
||||
final Widget _form;
|
||||
|
||||
NothingFound(this._title, this._titleForm, this._form);
|
||||
const NothingFound(this._title, this._titleForm, this._form);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: 150,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
||||
@@ -25,7 +25,7 @@ import 'package:wger/models/exercises/exercise.dart';
|
||||
class ExerciseDetail extends StatelessWidget {
|
||||
final Exercise _exercise;
|
||||
|
||||
ExerciseDetail(this._exercise);
|
||||
const ExerciseDetail(this._exercise);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -47,9 +47,9 @@ class ExerciseDetail extends StatelessWidget {
|
||||
AppLocalizations.of(context).equipment,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
if (_exercise.equipment.length > 0)
|
||||
if (_exercise.equipment.isNotEmpty)
|
||||
Text(_exercise.equipment.map((e) => e.name).toList().join('\n')),
|
||||
if (_exercise.equipment.length == 0) Text('-/-'),
|
||||
if (_exercise.equipment.isEmpty) Text('-/-'),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Muscles
|
||||
@@ -57,9 +57,9 @@ class ExerciseDetail extends StatelessWidget {
|
||||
AppLocalizations.of(context).muscles,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
if (_exercise.muscles.length > 0)
|
||||
if (_exercise.muscles.isNotEmpty)
|
||||
Text(_exercise.muscles.map((e) => e.name).toList().join('\n')),
|
||||
if (_exercise.muscles.length == 0) Text('-/-'),
|
||||
if (_exercise.muscles.isEmpty) Text('-/-'),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Muscles secondary
|
||||
@@ -67,9 +67,9 @@ class ExerciseDetail extends StatelessWidget {
|
||||
AppLocalizations.of(context).musclesSecondary,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
if (_exercise.musclesSecondary.length > 0)
|
||||
if (_exercise.musclesSecondary.isNotEmpty)
|
||||
Text(_exercise.musclesSecondary.map((e) => e.name).toList().join('\n')),
|
||||
if (_exercise.musclesSecondary.length == 0) Text('-/-'),
|
||||
if (_exercise.musclesSecondary.isEmpty) Text('-/-'),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Description
|
||||
|
||||
@@ -31,7 +31,7 @@ class ImageForm extends StatefulWidget {
|
||||
late gallery.Image _image;
|
||||
|
||||
ImageForm([gallery.Image? image]) {
|
||||
this._image = image ?? gallery.Image.emtpy();
|
||||
_image = image ?? gallery.Image.emtpy();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -59,7 +59,7 @@ class _ImageFormState extends State<ImageForm> {
|
||||
final file = await picker.pickImage(source: source);
|
||||
|
||||
setState(() {
|
||||
_file = file!;
|
||||
_file = file;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class _ImageFormState extends State<ImageForm> {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: 150,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
@@ -141,10 +141,10 @@ class _ImageFormState extends State<ImageForm> {
|
||||
controller: dateController,
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
// Show Date Picker Here
|
||||
var pickedDate = await showDatePicker(
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: widget._image.date,
|
||||
firstDate: DateTime(DateTime.now().year - 10),
|
||||
|
||||
@@ -29,9 +29,9 @@ import 'package:wger/widgets/core/charts.dart';
|
||||
import 'forms.dart';
|
||||
|
||||
class EntriesList extends StatelessWidget {
|
||||
MeasurementCategory _category;
|
||||
final MeasurementCategory _category;
|
||||
|
||||
EntriesList(this._category);
|
||||
const EntriesList(this._category);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -42,7 +42,7 @@ class EntriesList extends StatelessWidget {
|
||||
height: 220,
|
||||
child: MeasurementChartWidget(
|
||||
_category.entries.map((e) => MeasurementChartEntry(e.value, e.date)).toList(),
|
||||
unit: this._category.unit,
|
||||
unit: _category.unit,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
|
||||
@@ -60,7 +60,7 @@ class MeasurementCategoryForm extends StatelessWidget {
|
||||
),
|
||||
controller: nameController,
|
||||
onSaved: (newValue) {
|
||||
categoryData['name'] = newValue!;
|
||||
categoryData['name'] = newValue;
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
@@ -78,7 +78,7 @@ class MeasurementCategoryForm extends StatelessWidget {
|
||||
),
|
||||
controller: unitController,
|
||||
onSaved: (newValue) {
|
||||
categoryData['unit'] = newValue!;
|
||||
categoryData['unit'] = newValue;
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
@@ -166,16 +166,16 @@ class MeasurementEntryForm extends StatelessWidget {
|
||||
controller: _dateController,
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
// Show Date Picker Here
|
||||
var pickedDate = await showDatePicker(
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _entryData['date'],
|
||||
firstDate: DateTime(DateTime.now().year - 10),
|
||||
lastDate: DateTime.now(),
|
||||
|
||||
// TODO: we need to filter out dates that already have an entry
|
||||
// TODO(x): we need to filter out dates that already have an entry
|
||||
selectableDayPredicate: (day) {
|
||||
// Always allow the current initial date
|
||||
if (day == _entryData['date']) {
|
||||
@@ -222,7 +222,7 @@ class MeasurementEntryForm extends StatelessWidget {
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).notes),
|
||||
controller: _notesController,
|
||||
onSaved: (newValue) {
|
||||
_entryData['notes'] = newValue!;
|
||||
_entryData['notes'] = newValue;
|
||||
},
|
||||
validator: (value) {
|
||||
const minLength = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
|
||||
|
||||
/// [_nutritionalValues] are the calculated [NutritionalValues] for the wanted
|
||||
/// plan.
|
||||
NutritionalPlanPieChartWidget(this._nutritionalValues);
|
||||
const NutritionalPlanPieChartWidget(this._nutritionalValues);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -67,8 +67,8 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
|
||||
'${row.name}\n${row.value.toStringAsFixed(0)}${AppLocalizations.of(context).g}',
|
||||
)
|
||||
],
|
||||
defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60, arcRendererDecorators: [
|
||||
new charts.ArcLabelDecorator(
|
||||
defaultRenderer: charts.ArcRendererConfig(arcWidth: 60, arcRendererDecorators: [
|
||||
charts.ArcLabelDecorator(
|
||||
labelPosition: charts.ArcLabelPosition.outside,
|
||||
)
|
||||
])
|
||||
@@ -84,14 +84,14 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
class NutritionalDiaryChartWidget extends StatelessWidget {
|
||||
late NutritionalPlan _nutritionalPlan;
|
||||
|
||||
NutritionalDiaryChartWidget({
|
||||
const NutritionalDiaryChartWidget({
|
||||
Key? key,
|
||||
required NutritionalPlan nutritionalPlan,
|
||||
}) : _nutritionalPlan = nutritionalPlan,
|
||||
super(key: key);
|
||||
|
||||
final NutritionalPlan _nutritionalPlan;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return charts.TimeSeriesChart(
|
||||
@@ -106,9 +106,9 @@ class NutritionalDiaryChartWidget extends StatelessWidget {
|
||||
.toList(),
|
||||
)
|
||||
],
|
||||
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
|
||||
defaultRenderer: charts.BarRendererConfig<DateTime>(),
|
||||
behaviors: [
|
||||
new charts.RangeAnnotation([
|
||||
charts.RangeAnnotation([
|
||||
charts.LineAnnotationSegment(
|
||||
_nutritionalPlan.nutritionalValues.energy,
|
||||
charts.RangeAnnotationAxisType.measure,
|
||||
|
||||
@@ -20,10 +20,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
@@ -32,13 +32,13 @@ import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
|
||||
class MealForm extends StatelessWidget {
|
||||
late Meal _meal;
|
||||
int _planId;
|
||||
final int _planId;
|
||||
|
||||
final _form = GlobalKey<FormState>();
|
||||
final _timeController = TextEditingController();
|
||||
|
||||
MealForm(this._planId, [meal]) {
|
||||
this._meal = meal ?? Meal(plan: _planId);
|
||||
_meal = meal ?? Meal(plan: _planId);
|
||||
_timeController.text = timeToString(_meal.time)!;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ class MealForm extends StatelessWidget {
|
||||
controller: _timeController,
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
// Open time picker
|
||||
var pickedTime = await showTimePicker(
|
||||
final pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: _meal.time!,
|
||||
);
|
||||
@@ -101,11 +101,11 @@ class MealForm extends StatelessWidget {
|
||||
}
|
||||
|
||||
class MealItemForm extends StatelessWidget {
|
||||
Meal _meal;
|
||||
final Meal _meal;
|
||||
late MealItem _mealItem;
|
||||
|
||||
MealItemForm(this._meal, [mealItem]) {
|
||||
this._mealItem = mealItem ?? MealItem.empty();
|
||||
_mealItem = mealItem ?? MealItem.empty();
|
||||
_mealItem.mealId = _meal.id!;
|
||||
}
|
||||
|
||||
@@ -123,12 +123,11 @@ class MealItemForm extends StatelessWidget {
|
||||
children: [
|
||||
TypeAheadFormField(
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: this._ingredientController,
|
||||
controller: _ingredientController,
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).ingredient),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return await Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.searchIngredient(
|
||||
return Provider.of<NutritionPlansProvider>(context, listen: false).searchIngredient(
|
||||
pattern,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
@@ -144,7 +143,7 @@ class MealItemForm extends StatelessWidget {
|
||||
},
|
||||
onSuggestionSelected: (dynamic suggestion) {
|
||||
_mealItem.ingredientId = suggestion['data']['id'];
|
||||
this._ingredientController.text = suggestion['value'];
|
||||
_ingredientController.text = suggestion['value'];
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
@@ -202,7 +201,7 @@ class PlanForm extends StatelessWidget {
|
||||
late NutritionalPlan _plan;
|
||||
|
||||
PlanForm([NutritionalPlan? plan]) {
|
||||
_plan = plan != null ? plan : NutritionalPlan.empty();
|
||||
_plan = plan ?? NutritionalPlan.empty();
|
||||
_descriptionController.text = _plan.description;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import 'package:wger/models/nutrition/nutritrional_values.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
|
||||
List<Widget> getMutedNutritionalValues(NutritionalValues values, BuildContext context) {
|
||||
List<Widget> out = [
|
||||
final List<Widget> out = [
|
||||
MutedText(
|
||||
'${AppLocalizations.of(context).energy}: '
|
||||
'${values.energy.toStringAsFixed(0)}'
|
||||
|
||||
@@ -31,7 +31,7 @@ import 'package:wger/widgets/nutrition/helpers.dart';
|
||||
class MealWidget extends StatefulWidget {
|
||||
final Meal _meal;
|
||||
|
||||
MealWidget(
|
||||
const MealWidget(
|
||||
this._meal,
|
||||
);
|
||||
|
||||
@@ -78,7 +78,7 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
},
|
||||
icon: Icon(Icons.delete),
|
||||
),
|
||||
if (widget._meal.mealItems.length > 0)
|
||||
if (widget._meal.mealItems.isNotEmpty)
|
||||
Ink(
|
||||
decoration: const ShapeDecoration(
|
||||
color: wgerPrimaryButtonColor,
|
||||
@@ -143,18 +143,18 @@ class MealItemWidget extends StatelessWidget {
|
||||
final bool _expanded;
|
||||
final MealItem _item;
|
||||
|
||||
MealItemWidget(this._item, this._expanded);
|
||||
const MealItemWidget(this._item, this._expanded);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// TODO: add real support for weight units
|
||||
// TODO(x): add real support for weight units
|
||||
/*
|
||||
String unit = _item.weightUnitId == null
|
||||
? AppLocalizations.of(context).g
|
||||
: _item.weightUnitObj!.weightUnit.name;
|
||||
|
||||
*/
|
||||
String unit = AppLocalizations.of(context).g;
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
final values = _item.nutritionalValues;
|
||||
|
||||
return Container(
|
||||
@@ -162,7 +162,7 @@ class MealItemWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
@@ -32,7 +32,7 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
|
||||
final NutritionalPlan _nutritionalPlan;
|
||||
final DateTime _date;
|
||||
static const double tablePadding = 7;
|
||||
NutritionalDiaryDetailWidget(this._nutritionalPlan, this._date);
|
||||
const NutritionalDiaryDetailWidget(this._nutritionalPlan, this._date);
|
||||
|
||||
Widget getTable(
|
||||
NutritionalValues valuesTotal,
|
||||
@@ -44,7 +44,7 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
|
||||
border: TableBorder(
|
||||
horizontalInside: BorderSide(width: 1, color: wgerTextMuted),
|
||||
),
|
||||
columnWidths: {0: FractionColumnWidth(0.4)},
|
||||
columnWidths: const {0: FractionColumnWidth(0.4)},
|
||||
children: [
|
||||
TableRow(
|
||||
children: [
|
||||
@@ -185,10 +185,7 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
log.amount.toStringAsFixed(0) +
|
||||
AppLocalizations.of(context).g +
|
||||
' ' +
|
||||
log.ingredientObj.name,
|
||||
'${log.amount.toStringAsFixed(0)}${AppLocalizations.of(context).g} ${log.ingredientObj.name}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
@@ -211,8 +208,8 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final valuesTotal = _nutritionalPlan.nutritionalValues;
|
||||
final valuesDate = _nutritionalPlan.getValuesForDate(this._date);
|
||||
final logs = _nutritionalPlan.getLogsForDate(this._date);
|
||||
final valuesDate = _nutritionalPlan.getValuesForDate(_date);
|
||||
final logs = _nutritionalPlan.getLogsForDate(_date);
|
||||
|
||||
if (valuesDate == null) {
|
||||
return Text('');
|
||||
|
||||
@@ -32,7 +32,7 @@ import 'package:wger/widgets/nutrition/meal.dart';
|
||||
|
||||
class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
final NutritionalPlan _nutritionalPlan;
|
||||
NutritionalPlanDetailWidget(this._nutritionalPlan);
|
||||
const NutritionalPlanDetailWidget(this._nutritionalPlan);
|
||||
static const double tablePadding = 7;
|
||||
|
||||
@override
|
||||
@@ -77,7 +77,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
border: TableBorder(
|
||||
horizontalInside: BorderSide(width: 1, color: wgerTextMuted),
|
||||
),
|
||||
columnWidths: {0: FractionColumnWidth(0.4)},
|
||||
columnWidths: const {0: FractionColumnWidth(0.4)},
|
||||
children: [
|
||||
TableRow(
|
||||
children: [
|
||||
@@ -213,7 +213,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
height: 220,
|
||||
child: NutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan),
|
||||
),
|
||||
Container(
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
@@ -223,7 +223,7 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(onPressed: () => null, child: Text('')),
|
||||
TextButton(onPressed: () {}, child: const Text('')),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).energy} (${AppLocalizations.of(context).kcal})'),
|
||||
Text(
|
||||
@@ -257,7 +257,7 @@ class NutritionDiaryEntry extends StatelessWidget {
|
||||
final NutritionalValues values;
|
||||
final NutritionalPlan plan;
|
||||
|
||||
NutritionDiaryEntry(
|
||||
const NutritionDiaryEntry(
|
||||
this.date,
|
||||
this.values,
|
||||
this.plan,
|
||||
|
||||
@@ -23,8 +23,8 @@ import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
|
||||
class NutritionalPlansList extends StatelessWidget {
|
||||
NutritionPlansProvider _nutritrionProvider;
|
||||
NutritionalPlansList(this._nutritrionProvider);
|
||||
final NutritionPlansProvider _nutritrionProvider;
|
||||
const NutritionalPlansList(this._nutritrionProvider);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -34,7 +34,7 @@ class WeightForm extends StatelessWidget {
|
||||
late WeightEntry _weightEntry;
|
||||
|
||||
WeightForm([WeightEntry? weightEntry]) {
|
||||
this._weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
|
||||
_weightEntry = weightEntry ?? WeightEntry(date: DateTime.now());
|
||||
weightController.text = _weightEntry.id == null ? '' : _weightEntry.weight.toString();
|
||||
dateController.text = toDate(_weightEntry.date)!;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class WeightForm extends StatelessWidget {
|
||||
controller: dateController,
|
||||
onTap: () async {
|
||||
// Show Date Picker Here
|
||||
var pickedDate = await showDatePicker(
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _weightEntry.date,
|
||||
firstDate: DateTime(DateTime.now().year - 10),
|
||||
@@ -69,9 +69,7 @@ class WeightForm extends StatelessWidget {
|
||||
|
||||
// if the date is known, don't allow it
|
||||
return Provider.of<BodyWeightProvider>(context, listen: false).findByDate(day) ==
|
||||
null
|
||||
? true
|
||||
: false;
|
||||
null;
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -55,14 +55,14 @@ class LogChartWidget extends StatelessWidget {
|
||||
);
|
||||
}),
|
||||
],
|
||||
primaryMeasureAxis: new charts.NumericAxisSpec(
|
||||
tickProviderSpec: new charts.BasicNumericTickProviderSpec(zeroBound: false),
|
||||
primaryMeasureAxis: charts.NumericAxisSpec(
|
||||
tickProviderSpec: charts.BasicNumericTickProviderSpec(zeroBound: false),
|
||||
),
|
||||
behaviors: [
|
||||
new charts.SeriesLegend(
|
||||
charts.SeriesLegend(
|
||||
position: charts.BehaviorPosition.bottom,
|
||||
),
|
||||
new charts.RangeAnnotation([
|
||||
charts.RangeAnnotation([
|
||||
charts.LineAnnotationSegment(
|
||||
_currentDate, charts.RangeAnnotationAxisType.domain,
|
||||
strokeWidthPx: 2,
|
||||
|
||||
@@ -49,7 +49,7 @@ class SettingWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: InkWell(
|
||||
child: Container(
|
||||
child: SizedBox(
|
||||
child: ExerciseImageWidget(image: setting.exerciseObj.getMainImage),
|
||||
width: 45,
|
||||
),
|
||||
@@ -87,7 +87,7 @@ class SettingWidget extends StatelessWidget {
|
||||
class WorkoutDayWidget extends StatefulWidget {
|
||||
final Day _day;
|
||||
|
||||
WorkoutDayWidget(this._day);
|
||||
const WorkoutDayWidget(this._day);
|
||||
|
||||
@override
|
||||
_WorkoutDayWidgetState createState() => _WorkoutDayWidgetState();
|
||||
@@ -97,6 +97,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
bool _expanded = false;
|
||||
late List<Set> _sets;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_sets = widget._day.sets;
|
||||
@@ -179,7 +180,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
},
|
||||
icon: Icon(Icons.delete),
|
||||
),
|
||||
if (widget._day.sets.length > 0)
|
||||
if (widget._day.sets.isNotEmpty)
|
||||
Ink(
|
||||
decoration: const ShapeDecoration(
|
||||
color: wgerPrimaryButtonColor,
|
||||
|
||||
@@ -122,10 +122,10 @@ class WorkoutForm extends StatelessWidget {
|
||||
}
|
||||
|
||||
class DayCheckbox extends StatefulWidget {
|
||||
Day _day;
|
||||
final Day _day;
|
||||
final int _dayNr;
|
||||
|
||||
DayCheckbox(this._dayNr, this._day);
|
||||
const DayCheckbox(this._dayNr, this._day);
|
||||
|
||||
@override
|
||||
_DayCheckboxState createState() => _DayCheckboxState();
|
||||
@@ -160,8 +160,8 @@ class DayFormWidget extends StatefulWidget {
|
||||
Day _day = Day();
|
||||
|
||||
DayFormWidget(this.workout, [Day? day]) {
|
||||
this._day = day ?? Day();
|
||||
_day.workoutId = this.workout.id!;
|
||||
_day = day ?? Day();
|
||||
_day.workoutId = workout.id!;
|
||||
if (_day.id != null) {
|
||||
dayController.text = day!.description;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
return AppLocalizations.of(context).enterCharacters(minLength, maxLength);
|
||||
}
|
||||
|
||||
if (widget._day.daysOfWeek.length == 0) {
|
||||
if (widget._day.daysOfWeek.isEmpty) {
|
||||
return 'You need to select at least one day';
|
||||
}
|
||||
return null;
|
||||
@@ -255,11 +255,11 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
}
|
||||
|
||||
class SetFormWidget extends StatefulWidget {
|
||||
Day _day;
|
||||
final Day _day;
|
||||
late Set _set;
|
||||
|
||||
SetFormWidget(this._day, [Set? set]) {
|
||||
this._set = set ?? Set.withData(day: _day.id, order: _day.sets.length, sets: 4);
|
||||
_set = set ?? Set.withData(day: _day.id, order: _day.sets.length, sets: 4);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -293,10 +293,10 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
void addSettings() {
|
||||
widget._set.settings = [];
|
||||
int order = 0;
|
||||
for (var exercise in widget._set.exercisesObj) {
|
||||
for (final exercise in widget._set.exercisesObj) {
|
||||
order++;
|
||||
for (int loop = 0; loop < widget._set.sets; loop++) {
|
||||
Setting setting = Setting.empty();
|
||||
final Setting setting = Setting.empty();
|
||||
setting.order = order;
|
||||
setting.exercise = exercise;
|
||||
setting.weightUnit =
|
||||
@@ -336,7 +336,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
});
|
||||
},
|
||||
),
|
||||
if (widget._set.settings.length > 0)
|
||||
if (widget._set.settings.isNotEmpty)
|
||||
SwitchListTile(
|
||||
title: Text(AppLocalizations.of(context).setUnitsAndRir),
|
||||
value: _detailed,
|
||||
@@ -357,7 +357,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
child: TypeAheadFormField(
|
||||
key: Key('field-typeahead'),
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: this._exercisesController,
|
||||
controller: _exercisesController,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).searchExercise,
|
||||
prefixIcon: Icon(Icons.search),
|
||||
@@ -403,7 +403,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
|
||||
.findById(result['data']['id']);
|
||||
return ListTile(
|
||||
leading: Container(
|
||||
leading: SizedBox(
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(image: exercise.getMainImage),
|
||||
),
|
||||
@@ -420,11 +420,11 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
final exercise = Provider.of<ExercisesProvider>(context, listen: false)
|
||||
.findById(result['data']['id']);
|
||||
addExercise(exercise);
|
||||
this._exercisesController.text = '';
|
||||
_exercisesController.text = '';
|
||||
},
|
||||
validator: (value) {
|
||||
// At least one exercise must be selected
|
||||
if (widget._set.exercisesIds.length == 0) {
|
||||
if (widget._set.exercisesIds.isEmpty) {
|
||||
return AppLocalizations.of(context).selectExercise;
|
||||
}
|
||||
|
||||
@@ -503,18 +503,18 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
|
||||
// Save set
|
||||
Set setDb = await workoutProvider.addSet(widget._set);
|
||||
final 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);
|
||||
|
||||
// Save remaining settings
|
||||
for (var setting in widget._set.settings) {
|
||||
for (final setting in widget._set.settings) {
|
||||
setting.setId = setDb.id!;
|
||||
setting.comment = '';
|
||||
|
||||
Setting settingDb = await workoutProvider.addSetting(setting);
|
||||
final Setting settingDb = await workoutProvider.addSetting(setting);
|
||||
setting.id = settingDb.id;
|
||||
}
|
||||
|
||||
@@ -538,9 +538,9 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
class ExerciseSetting extends StatelessWidget {
|
||||
final Exercise _exercise;
|
||||
int _numberOfSets = 4;
|
||||
bool _detailed;
|
||||
final bool _detailed;
|
||||
final Function removeExercise;
|
||||
List<Setting> _settings = [];
|
||||
final List<Setting> _settings;
|
||||
|
||||
ExerciseSetting(
|
||||
this._exercise,
|
||||
@@ -549,13 +549,13 @@ class ExerciseSetting extends StatelessWidget {
|
||||
double sliderValue,
|
||||
this.removeExercise,
|
||||
) {
|
||||
this._numberOfSets = sliderValue.round();
|
||||
_numberOfSets = sliderValue.round();
|
||||
}
|
||||
|
||||
Widget getRows(BuildContext context) {
|
||||
List<Widget> out = [];
|
||||
final List<Widget> out = [];
|
||||
for (var i = 0; i < _numberOfSets; i++) {
|
||||
var setting = _settings[i];
|
||||
final setting = _settings[i];
|
||||
|
||||
if (_detailed) {
|
||||
out.add(
|
||||
@@ -685,7 +685,7 @@ class RepsInputWidget extends StatelessWidget {
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
try {
|
||||
if (value != "") {
|
||||
if (value != '') {
|
||||
double.parse(value!);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -722,7 +722,7 @@ class WeightInputWidget extends StatelessWidget {
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
try {
|
||||
if (value != "") {
|
||||
if (value != '') {
|
||||
double.parse(value!);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -752,7 +752,7 @@ class RiRInputWidget extends StatefulWidget {
|
||||
static const SLIDER_START = -0.5;
|
||||
|
||||
RiRInputWidget(this._setting) {
|
||||
dropdownValue = _setting.rir != null ? _setting.rir : Setting.DEFAULT_RIR;
|
||||
dropdownValue = _setting.rir ?? Setting.DEFAULT_RIR;
|
||||
|
||||
// Read string RiR into a double
|
||||
if (_setting.rir != null) {
|
||||
@@ -824,7 +824,7 @@ class _RiRInputWidgetState extends State<RiRInputWidget> {
|
||||
class WeightUnitInputWidget extends StatefulWidget {
|
||||
final dynamic _setting;
|
||||
|
||||
WeightUnitInputWidget(this._setting, {Key? key}) : super(key: key);
|
||||
const WeightUnitInputWidget(this._setting, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_WeightUnitInputWidgetState createState() => _WeightUnitInputWidgetState();
|
||||
@@ -861,7 +861,7 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
/// Can be used with a Setting or a Log object
|
||||
class RepetitionUnitInputWidget extends StatefulWidget {
|
||||
final dynamic _setting;
|
||||
RepetitionUnitInputWidget(this._setting);
|
||||
const RepetitionUnitInputWidget(this._setting);
|
||||
|
||||
@override
|
||||
_RepetitionUnitInputWidgetState createState() => _RepetitionUnitInputWidgetState();
|
||||
|
||||
@@ -22,13 +22,13 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/gym_mode.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:wger/helpers/misc.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/models/workouts/day.dart';
|
||||
import 'package:wger/models/workouts/log.dart';
|
||||
import 'package:wger/models/workouts/session.dart';
|
||||
@@ -56,8 +56,8 @@ class _GymModeState extends State<GymMode> {
|
||||
var _totalElements = 1;
|
||||
|
||||
/// Map with the first (navigation) page for each exercise
|
||||
Map<String, int> _exercisePages = new Map();
|
||||
PageController _controller = PageController(
|
||||
final Map<String, int> _exercisePages = {};
|
||||
final PageController _controller = PageController(
|
||||
initialPage: 0,
|
||||
);
|
||||
@override
|
||||
@@ -70,7 +70,7 @@ class _GymModeState extends State<GymMode> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Calculate amount of elements for progress indicator
|
||||
for (var set in widget._workoutDay.sets) {
|
||||
for (final set in widget._workoutDay.sets) {
|
||||
_totalElements = _totalElements + set.settingsComputed.length;
|
||||
}
|
||||
// Calculate the pages for the navigation
|
||||
@@ -78,9 +78,9 @@ class _GymModeState extends State<GymMode> {
|
||||
// This duplicates the code below in the getContent method, but it seems to
|
||||
// be the easiest way
|
||||
var currentPage = 1;
|
||||
for (var set in widget._workoutDay.sets) {
|
||||
for (final set in widget._workoutDay.sets) {
|
||||
var firstPage = true;
|
||||
for (var setting in set.settingsComputed) {
|
||||
for (final setting in set.settingsComputed) {
|
||||
final exercise =
|
||||
Provider.of<ExercisesProvider>(context, listen: false).findById(setting.exerciseId);
|
||||
|
||||
@@ -104,12 +104,12 @@ class _GymModeState extends State<GymMode> {
|
||||
final exerciseProvider = Provider.of<ExercisesProvider>(context, listen: false);
|
||||
final workoutProvider = Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
var currentElement = 1;
|
||||
List<Widget> out = [];
|
||||
final List<Widget> out = [];
|
||||
|
||||
for (var set in widget._workoutDay.sets) {
|
||||
for (final set in widget._workoutDay.sets) {
|
||||
var firstPage = true;
|
||||
for (var setting in set.settingsComputed) {
|
||||
var ratioCompleted = currentElement / _totalElements;
|
||||
for (final setting in set.settingsComputed) {
|
||||
final ratioCompleted = currentElement / _totalElements;
|
||||
final exercise = exerciseProvider.findById(setting.exerciseId);
|
||||
currentElement++;
|
||||
|
||||
@@ -163,11 +163,11 @@ class _GymModeState extends State<GymMode> {
|
||||
}
|
||||
|
||||
class StartPage extends StatelessWidget {
|
||||
PageController _controller;
|
||||
final PageController _controller;
|
||||
final Day _day;
|
||||
Map<String, int> _exercisePages;
|
||||
final Map<String, int> _exercisePages;
|
||||
|
||||
StartPage(this._controller, this._day, this._exercisePages);
|
||||
const StartPage(this._controller, this._day, this._exercisePages);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -222,14 +222,14 @@ class StartPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
class LogPage extends StatefulWidget {
|
||||
PageController _controller;
|
||||
Setting _setting;
|
||||
Set _set;
|
||||
Exercise _exercise;
|
||||
WorkoutPlan _workoutPlan;
|
||||
final PageController _controller;
|
||||
final Setting _setting;
|
||||
final Set _set;
|
||||
final Exercise _exercise;
|
||||
final WorkoutPlan _workoutPlan;
|
||||
final double _ratioCompleted;
|
||||
Map<String, int> _exercisePages;
|
||||
Log _log = Log.empty();
|
||||
final Map<String, int> _exercisePages;
|
||||
final Log _log = Log.empty();
|
||||
|
||||
LogPage(
|
||||
this._controller,
|
||||
@@ -292,7 +292,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
int newValue = int.parse(_repsController.text) - 1;
|
||||
final int newValue = int.parse(_repsController.text) - 1;
|
||||
if (newValue > 0) {
|
||||
_repsController.text = newValue.toString();
|
||||
}
|
||||
@@ -330,7 +330,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
int newValue = int.parse(_repsController.text) + 1;
|
||||
final int newValue = int.parse(_repsController.text) + 1;
|
||||
_repsController.text = newValue.toString();
|
||||
} on FormatException catch (e) {}
|
||||
},
|
||||
@@ -340,7 +340,7 @@ class _LogPageState extends State<LogPage> {
|
||||
}
|
||||
|
||||
Widget getWeightWidget() {
|
||||
var minPlateWeight = 1.25;
|
||||
const minPlateWeight = 1.25;
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(
|
||||
@@ -350,7 +350,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
double newValue = double.parse(_weightController.text) - (2 * minPlateWeight);
|
||||
final double newValue = double.parse(_weightController.text) - (2 * minPlateWeight);
|
||||
if (newValue > 0) {
|
||||
setState(() {
|
||||
widget._log.weight = newValue;
|
||||
@@ -398,7 +398,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
double newValue = double.parse(_weightController.text) + (2 * minPlateWeight);
|
||||
final double newValue = double.parse(_weightController.text) + (2 * minPlateWeight);
|
||||
setState(() {
|
||||
widget._log.weight = newValue;
|
||||
_weightController.text = newValue.toString();
|
||||
@@ -544,7 +544,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
child: plates.length > 0
|
||||
child: plates.isNotEmpty
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -611,7 +611,7 @@ class _LogPageState extends State<LogPage> {
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: (widget._workoutPlan.filterLogsByExercise(widget._exercise).length > 0)
|
||||
child: (widget._workoutPlan.filterLogsByExercise(widget._exercise).isNotEmpty)
|
||||
? getPastLogs()
|
||||
: Container()),
|
||||
// Only show calculator for barbell
|
||||
@@ -634,9 +634,9 @@ class ExerciseOverview extends StatelessWidget {
|
||||
final PageController _controller;
|
||||
final Exercise _exercise;
|
||||
final double _ratioCompleted;
|
||||
Map<String, int> _exercisePages;
|
||||
final Map<String, int> _exercisePages;
|
||||
|
||||
ExerciseOverview(
|
||||
const ExerciseOverview(
|
||||
this._controller,
|
||||
this._exercise,
|
||||
this._ratioCompleted,
|
||||
@@ -669,8 +669,8 @@ class ExerciseOverview extends StatelessWidget {
|
||||
textAlign: TextAlign.center,
|
||||
))
|
||||
.toList(),
|
||||
if (_exercise.images.length > 0)
|
||||
Container(
|
||||
if (_exercise.images.isNotEmpty)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 200,
|
||||
child: ListView(
|
||||
@@ -691,12 +691,12 @@ class ExerciseOverview extends StatelessWidget {
|
||||
}
|
||||
|
||||
class SessionPage extends StatefulWidget {
|
||||
WorkoutPlan _workoutPlan;
|
||||
PageController _controller;
|
||||
TimeOfDay _start;
|
||||
Map<String, int> _exercisePages;
|
||||
final WorkoutPlan _workoutPlan;
|
||||
final PageController _controller;
|
||||
final TimeOfDay _start;
|
||||
final Map<String, int> _exercisePages;
|
||||
|
||||
SessionPage(
|
||||
const SessionPage(
|
||||
this._workoutPlan,
|
||||
this._controller,
|
||||
this._start,
|
||||
@@ -714,7 +714,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
final timeStartController = TextEditingController();
|
||||
final timeEndController = TextEditingController();
|
||||
|
||||
var _session = WorkoutSession();
|
||||
final _session = WorkoutSession();
|
||||
|
||||
/// Selected impression: bad, neutral, good
|
||||
var selectedImpression = [false, true, false];
|
||||
@@ -749,7 +749,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ToggleButtons(
|
||||
children: <Widget>[
|
||||
children: const <Widget>[
|
||||
Icon(
|
||||
Icons.sentiment_very_dissatisfied,
|
||||
),
|
||||
@@ -802,10 +802,10 @@ class _SessionPageState extends State<SessionPage> {
|
||||
onFieldSubmitted: (_) {},
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
// Open time picker
|
||||
var pickedTime = await showTimePicker(
|
||||
final pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: widget._start,
|
||||
);
|
||||
@@ -818,8 +818,8 @@ class _SessionPageState extends State<SessionPage> {
|
||||
_session.timeStart = stringToTime(newValue);
|
||||
},
|
||||
validator: (_) {
|
||||
TimeOfDay startTime = stringToTime(timeStartController.text);
|
||||
TimeOfDay endTime = stringToTime(timeEndController.text);
|
||||
final TimeOfDay startTime = stringToTime(timeStartController.text);
|
||||
final TimeOfDay endTime = stringToTime(timeEndController.text);
|
||||
if (startTime.isAfter(endTime)) {
|
||||
return AppLocalizations.of(context).timeStartAhead;
|
||||
}
|
||||
@@ -835,10 +835,10 @@ class _SessionPageState extends State<SessionPage> {
|
||||
onFieldSubmitted: (_) {},
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
|
||||
// Open time picker
|
||||
var pickedTime = await showTimePicker(
|
||||
final pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
@@ -891,9 +891,9 @@ class _SessionPageState extends State<SessionPage> {
|
||||
class TimerWidget extends StatefulWidget {
|
||||
final PageController _controller;
|
||||
final double _ratioCompleted;
|
||||
Map<String, int> _exercisePages;
|
||||
final Map<String, int> _exercisePages;
|
||||
|
||||
TimerWidget(this._controller, this._ratioCompleted, this._exercisePages);
|
||||
const TimerWidget(this._controller, this._ratioCompleted, this._exercisePages);
|
||||
|
||||
@override
|
||||
_TimerWidgetState createState() => _TimerWidgetState();
|
||||
@@ -905,7 +905,7 @@ class _TimerWidgetState extends State<TimerWidget> {
|
||||
Timer? _timer;
|
||||
int _seconds = 1;
|
||||
final _maxSeconds = 600;
|
||||
DateTime today = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||
DateTime today = DateTime(2000, 1, 1, 0, 0, 0);
|
||||
|
||||
void startTimer() {
|
||||
setState(() {
|
||||
@@ -914,8 +914,8 @@ class _TimerWidgetState extends State<TimerWidget> {
|
||||
|
||||
_timer?.cancel();
|
||||
|
||||
const oneSecond = const Duration(seconds: 1);
|
||||
_timer = new Timer.periodic(
|
||||
const oneSecond = Duration(seconds: 1);
|
||||
_timer = Timer.periodic(
|
||||
oneSecond,
|
||||
(Timer timer) {
|
||||
if (_seconds == _maxSeconds) {
|
||||
@@ -939,7 +939,6 @@ class _TimerWidgetState extends State<TimerWidget> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
startTimer();
|
||||
}
|
||||
@@ -973,24 +972,25 @@ class NavigationFooter extends StatelessWidget {
|
||||
final bool showPrevious;
|
||||
final bool showNext;
|
||||
|
||||
NavigationFooter(this._controller, this._ratioCompleted,
|
||||
const NavigationFooter(this._controller, this._ratioCompleted,
|
||||
{this.showPrevious = true, this.showNext = true});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
showPrevious
|
||||
? IconButton(
|
||||
icon: Icon(Icons.chevron_left),
|
||||
onPressed: () {
|
||||
_controller.previousPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
);
|
||||
},
|
||||
)
|
||||
: SizedBox(width: 48),
|
||||
if (showPrevious)
|
||||
IconButton(
|
||||
icon: Icon(Icons.chevron_left),
|
||||
onPressed: () {
|
||||
_controller.previousPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
SizedBox(width: 48),
|
||||
Expanded(
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: 1.5,
|
||||
@@ -998,17 +998,18 @@ class NavigationFooter extends StatelessWidget {
|
||||
valueColor: AlwaysStoppedAnimation<Color>(wgerPrimaryColor),
|
||||
),
|
||||
),
|
||||
showNext
|
||||
? IconButton(
|
||||
icon: Icon(Icons.chevron_right),
|
||||
onPressed: () {
|
||||
_controller.nextPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
);
|
||||
},
|
||||
)
|
||||
: SizedBox(width: 48),
|
||||
if (showNext)
|
||||
IconButton(
|
||||
icon: Icon(Icons.chevron_right),
|
||||
onPressed: () {
|
||||
_controller.nextPage(
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
curve: DEFAULT_ANIMATION_CURVE,
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
SizedBox(width: 48),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class ExerciseLogChart extends StatelessWidget {
|
||||
final Exercise _exercise;
|
||||
final DateTime _currentDate;
|
||||
|
||||
ExerciseLogChart(this._exercise, this._currentDate);
|
||||
const ExerciseLogChart(this._exercise, this._currentDate);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -38,12 +38,12 @@ class ExerciseLogChart extends StatelessWidget {
|
||||
final _workout = _workoutPlansData.currentPlan;
|
||||
|
||||
Future<Map<String, dynamic>> _getChartEntries(BuildContext context) async {
|
||||
return await _workoutPlansData.fetchLogData(_workout!, _exercise);
|
||||
return _workoutPlansData.fetchLogData(_workout!, _exercise);
|
||||
}
|
||||
|
||||
return FutureBuilder(
|
||||
future: _getChartEntries(context),
|
||||
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) => Container(
|
||||
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) => SizedBox(
|
||||
height: 150,
|
||||
child: snapshot.connectionState == ConnectionState.waiting
|
||||
? Center(child: CircularProgressIndicator())
|
||||
@@ -58,7 +58,7 @@ class DayLogWidget extends StatelessWidget {
|
||||
final WorkoutSession? _session;
|
||||
final Map<Exercise, List<Log>> _exerciseData;
|
||||
|
||||
DayLogWidget(this._date, this._exerciseData, this._session);
|
||||
const DayLogWidget(this._date, this._exerciseData, this._session);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import 'package:wger/widgets/workouts/log.dart';
|
||||
class WorkoutLogs extends StatefulWidget {
|
||||
final WorkoutPlan _workoutPlan;
|
||||
final _changeMode;
|
||||
WorkoutLogs(this._workoutPlan, this._changeMode);
|
||||
const WorkoutLogs(this._workoutPlan, this._changeMode);
|
||||
|
||||
@override
|
||||
_WorkoutLogsState createState() => _WorkoutLogsState();
|
||||
@@ -45,7 +45,7 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
return Column(
|
||||
children: [
|
||||
ToggleButtons(
|
||||
children: <Widget>[
|
||||
children: const <Widget>[
|
||||
Icon(
|
||||
Icons.table_chart_outlined,
|
||||
),
|
||||
@@ -59,7 +59,7 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
widget._changeMode(WorkoutScreenMode.workout);
|
||||
}
|
||||
},
|
||||
isSelected: [false, true],
|
||||
isSelected: const [false, true],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
@@ -82,7 +82,7 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
textAlign: TextAlign.justify,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: WorkoutLogCalendar(widget._workoutPlan),
|
||||
),
|
||||
@@ -103,7 +103,7 @@ class WorkoutLogEvent {
|
||||
class WorkoutLogCalendar extends StatefulWidget {
|
||||
final WorkoutPlan _workoutPlan;
|
||||
|
||||
WorkoutLogCalendar(this._workoutPlan);
|
||||
const WorkoutLogCalendar(this._workoutPlan);
|
||||
|
||||
@override
|
||||
_WorkoutLogCalendarState createState() => _WorkoutLogCalendarState();
|
||||
@@ -132,8 +132,8 @@ class _WorkoutLogCalendarState extends State<WorkoutLogCalendar> {
|
||||
}
|
||||
|
||||
void loadEvents() {
|
||||
for (var date in widget._workoutPlan.logData.keys) {
|
||||
var entry = widget._workoutPlan.logData[date]!;
|
||||
for (final date in widget._workoutPlan.logData.keys) {
|
||||
final entry = widget._workoutPlan.logData[date]!;
|
||||
_events[DateFormatLists.format(date)] = [
|
||||
WorkoutLogEvent(
|
||||
date,
|
||||
@@ -192,7 +192,7 @@ class _WorkoutLogCalendarState extends State<WorkoutLogCalendar> {
|
||||
valueListenable: _selectedEvents,
|
||||
builder: (context, logEvents, _) {
|
||||
// At the moment there is only one "event" per day
|
||||
return logEvents.length > 0
|
||||
return logEvents.isNotEmpty
|
||||
? DayLogWidget(
|
||||
logEvents.first.dateTime,
|
||||
logEvents.first.exercises,
|
||||
|
||||
@@ -27,7 +27,7 @@ import 'package:wger/widgets/workouts/forms.dart';
|
||||
class WorkoutPlanDetail extends StatefulWidget {
|
||||
final WorkoutPlan _workoutPlan;
|
||||
final _changeMode;
|
||||
WorkoutPlanDetail(this._workoutPlan, this._changeMode);
|
||||
const WorkoutPlanDetail(this._workoutPlan, this._changeMode);
|
||||
|
||||
@override
|
||||
_WorkoutPlanDetailState createState() => _WorkoutPlanDetailState();
|
||||
@@ -38,9 +38,9 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
if (widget._workoutPlan.days.length > 0)
|
||||
if (widget._workoutPlan.days.isNotEmpty)
|
||||
ToggleButtons(
|
||||
children: <Widget>[
|
||||
children: const <Widget>[
|
||||
Icon(Icons.table_chart_outlined),
|
||||
Icon(Icons.show_chart),
|
||||
],
|
||||
@@ -50,7 +50,7 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
|
||||
widget._changeMode(WorkoutScreenMode.log);
|
||||
}
|
||||
},
|
||||
isSelected: [true, false],
|
||||
isSelected: const [true, false],
|
||||
),
|
||||
if (widget._workoutPlan.description != '')
|
||||
Padding(
|
||||
|
||||
@@ -26,7 +26,7 @@ import 'package:wger/screens/workout_plan_screen.dart';
|
||||
class WorkoutPlansList extends StatelessWidget {
|
||||
final WorkoutPlansProvider _workoutProvider;
|
||||
|
||||
WorkoutPlansList(this._workoutProvider);
|
||||
const WorkoutPlansList(this._workoutProvider);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -76,7 +76,7 @@ void main() {
|
||||
expect(find.byKey(Key('actionButton')), findsOneWidget);
|
||||
expect(find.byKey(Key('toggleActionButton')), findsOneWidget);
|
||||
expect(find.byKey(Key('toggleCustomServerButton')), findsOneWidget);
|
||||
}, skip: true); // TODO: skipped because of technical problems:
|
||||
}, skip: true); // TODO(x): skipped because of technical problems:
|
||||
// either the provider wasn't found or, if the call was removed, the
|
||||
// localization data could not be loaded...
|
||||
|
||||
|
||||
@@ -80,6 +80,4 @@ class MockClient extends _i1.Mock implements _i4.Client {
|
||||
@override
|
||||
void close() =>
|
||||
super.noSuchMethod(Invocation.method(#close, []), returnValueForMissingStub: null);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import 'package:wger/widgets/exercises/exercises.dart';
|
||||
|
||||
import '../test_data/exercises.dart';
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
return MaterialApp(
|
||||
locale: Locale(locale),
|
||||
|
||||
@@ -25,7 +25,7 @@ void main() {
|
||||
final time1 = TimeOfDay(hour: 00, minute: 00);
|
||||
final time2 = TimeOfDay(hour: 23, minute: 59);
|
||||
|
||||
expect(time2.toMinutes(), (23 * 60 + 59));
|
||||
expect(time2.toMinutes(), 23 * 60 + 59);
|
||||
expect(time1.isAfter(time2), false);
|
||||
expect(time1.isBefore(time2), true);
|
||||
expect(time2.isAfter(time1), true);
|
||||
|
||||
@@ -32,7 +32,7 @@ import 'gallery_screen_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late gallery.Image image;
|
||||
var mockGalleryProvider = MockGalleryProvider();
|
||||
final mockGalleryProvider = MockGalleryProvider();
|
||||
|
||||
setUp(() {
|
||||
image = getTestImages()[0];
|
||||
|
||||
@@ -105,8 +105,6 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider {
|
||||
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: Future<_i3.Response>.value(_FakeResponse_3())) as _i6.Future<_i3.Response>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
@override
|
||||
void addListener(_i8.VoidCallback? listener) => super
|
||||
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -36,7 +36,7 @@ void main() {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final client = MockClient();
|
||||
|
||||
WorkoutPlan workoutPlan = getWorkout();
|
||||
final WorkoutPlan workoutPlan = getWorkout();
|
||||
|
||||
return ChangeNotifierProvider<WorkoutPlansProvider>(
|
||||
create: (context) => WorkoutPlansProvider(
|
||||
|
||||
@@ -97,8 +97,6 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide
|
||||
returnValue: Future<void>.value(),
|
||||
returnValueForMissingStub: Future<void>.value()) as _i5.Future<void>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) => super
|
||||
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:wger/models/measurements/measurement_category.dart';
|
||||
import 'package:wger/models/measurements/measurement_entry.dart';
|
||||
|
||||
void main() {
|
||||
List<MeasurementEntry> tMeasurementEntries = [
|
||||
final List<MeasurementEntry> tMeasurementEntries = [
|
||||
MeasurementEntry(
|
||||
id: 1234,
|
||||
category: 123,
|
||||
@@ -14,23 +14,23 @@ void main() {
|
||||
)
|
||||
];
|
||||
|
||||
MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
id: 1234,
|
||||
category: 123,
|
||||
date: DateTime(2021, 7, 22),
|
||||
value: 83,
|
||||
notes: 'notes',
|
||||
);
|
||||
int tMeasurementEntryId = 1234;
|
||||
const int tMeasurementEntryId = 1234;
|
||||
|
||||
MeasurementCategory tMeasurementCategory = MeasurementCategory(
|
||||
final MeasurementCategory tMeasurementCategory = MeasurementCategory(
|
||||
id: 123,
|
||||
name: 'Bizeps',
|
||||
unit: 'cm',
|
||||
entries: tMeasurementEntries,
|
||||
);
|
||||
|
||||
Map<String, dynamic> tMeasurementEntryMap = {
|
||||
final Map<String, dynamic> tMeasurementEntryMap = {
|
||||
'id': 1234,
|
||||
'category': 123,
|
||||
'date': '2021-07-22',
|
||||
@@ -38,14 +38,14 @@ void main() {
|
||||
'notes': 'notes'
|
||||
};
|
||||
|
||||
Map<String, dynamic> tMeasurementCategoryMap = {
|
||||
final Map<String, dynamic> tMeasurementCategoryMap = {
|
||||
'id': 123,
|
||||
'name': 'Bizeps',
|
||||
'unit': 'cm',
|
||||
'entries': [tMeasurementEntryMap],
|
||||
};
|
||||
|
||||
Map<String, dynamic> tMeasurementCategoryMaptoJson = {
|
||||
final Map<String, dynamic> tMeasurementCategoryMaptoJson = {
|
||||
'id': 123,
|
||||
'name': 'Bizeps',
|
||||
'unit': 'cm',
|
||||
@@ -76,7 +76,7 @@ void main() {
|
||||
test('should copyWith objects of this class', () {
|
||||
// arrange
|
||||
|
||||
MeasurementCategory tMeasurementCategoryCopied = MeasurementCategory(
|
||||
final MeasurementCategory tMeasurementCategoryCopied = MeasurementCategory(
|
||||
id: 1234,
|
||||
name: 'Coolness',
|
||||
unit: 'lp',
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/models/measurements/measurement_entry.dart';
|
||||
|
||||
void main() {
|
||||
MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
id: 1234,
|
||||
category: 123,
|
||||
date: DateTime(2021, 7, 22),
|
||||
@@ -10,7 +10,7 @@ void main() {
|
||||
notes: 'notes',
|
||||
);
|
||||
|
||||
Map<String, dynamic> tMeasurementEntryMap = {
|
||||
final Map<String, dynamic> tMeasurementEntryMap = {
|
||||
'id': 1234,
|
||||
'category': 123,
|
||||
'date': '2021-07-22',
|
||||
@@ -37,7 +37,7 @@ void main() {
|
||||
test('should copyWith objects of this class', () {
|
||||
// arrange
|
||||
|
||||
MeasurementEntry tMeasurementEntryCopied = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntryCopied = MeasurementEntry(
|
||||
id: 83,
|
||||
category: 17,
|
||||
date: DateTime(1960),
|
||||
|
||||
@@ -17,30 +17,30 @@ import 'measurement_provider_test.mocks.dart';
|
||||
// class MockWgerBaseProvider extends Mock implements WgerBaseProvider {}
|
||||
|
||||
@GenerateMocks([WgerBaseProvider])
|
||||
main() {
|
||||
void main() {
|
||||
late MeasurementProvider measurementProvider;
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
|
||||
String categoryUrl = 'measurement-category';
|
||||
String entryUrl = 'measurement';
|
||||
Uri tCategoryUri = Uri();
|
||||
Map<String, dynamic> tMeasurementCategoryMap =
|
||||
const String categoryUrl = 'measurement-category';
|
||||
const String entryUrl = 'measurement';
|
||||
final Uri tCategoryUri = Uri();
|
||||
final Map<String, dynamic> tMeasurementCategoryMap =
|
||||
jsonDecode(fixture('measurement_category_entries.json'));
|
||||
Uri tCategoryEntriesUri = Uri(
|
||||
final Uri tCategoryEntriesUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'tedmosbyisajerk.com',
|
||||
path: 'api/v2/' + entryUrl + '/',
|
||||
path: 'api/v2/$entryUrl/',
|
||||
query: 'category=1',
|
||||
);
|
||||
|
||||
int tCategoryId = 1;
|
||||
MeasurementCategory tMeasurementCategory =
|
||||
const int tCategoryId = 1;
|
||||
final MeasurementCategory tMeasurementCategory =
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN');
|
||||
List<MeasurementCategory> tMeasurementCategories = [
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm')
|
||||
];
|
||||
Map<String, dynamic> tMeasurementCategoriesMap =
|
||||
final Map<String, dynamic> tMeasurementCategoriesMap =
|
||||
jsonDecode(fixture('measurement_categories.json'));
|
||||
|
||||
setUp(() {
|
||||
@@ -143,7 +143,7 @@ main() {
|
||||
|
||||
test('should add entries to category in list', () async {
|
||||
// arrange
|
||||
List<MeasurementCategory> tMeasurementCategories = [
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
@@ -172,12 +172,13 @@ main() {
|
||||
});
|
||||
|
||||
group('addCategory()', () {
|
||||
MeasurementCategory tMeasurementCategoryWithoutId =
|
||||
final MeasurementCategory tMeasurementCategoryWithoutId =
|
||||
MeasurementCategory(id: null, name: 'Strength', unit: 'kN');
|
||||
Map<String, dynamic> tMeasurementCategoryMap = jsonDecode(fixture('measurement_category.json'));
|
||||
Map<String, dynamic> tMeasurementCategoryMapWithoutId =
|
||||
final Map<String, dynamic> tMeasurementCategoryMap =
|
||||
jsonDecode(fixture('measurement_category.json'));
|
||||
final Map<String, dynamic> tMeasurementCategoryMapWithoutId =
|
||||
jsonDecode(fixture('measurement_category_without_id_to_json.json'));
|
||||
List<MeasurementCategory> tMeasurementCategoriesAdded = [
|
||||
final List<MeasurementCategory> tMeasurementCategoriesAdded = [
|
||||
MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN'),
|
||||
@@ -187,7 +188,7 @@ main() {
|
||||
.thenAnswer((realInvocation) => Future.value(tMeasurementCategoryMap));
|
||||
});
|
||||
|
||||
test('should post the MeasurementCategorie\'s Map', () async {
|
||||
test("should post the MeasurementCategorie's Map", () async {
|
||||
// act
|
||||
await measurementProvider.addCategory(tMeasurementCategoryWithoutId);
|
||||
|
||||
@@ -220,7 +221,7 @@ main() {
|
||||
when(mockWgerBaseProvider.deleteRequest(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
|
||||
List<MeasurementCategory> tMeasurementCategoriesOneDeleted = [
|
||||
final List<MeasurementCategory> tMeasurementCategoriesOneDeleted = [
|
||||
MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm')
|
||||
];
|
||||
|
||||
@@ -252,11 +253,11 @@ main() {
|
||||
});
|
||||
|
||||
group('editCategory()', () {
|
||||
String tCategoryEditedName = 'Triceps';
|
||||
String tCategoryEditedUnit = 'm';
|
||||
Map<String, dynamic> tCategoryMapEditedToJson =
|
||||
const String tCategoryEditedName = 'Triceps';
|
||||
const String tCategoryEditedUnit = 'm';
|
||||
final Map<String, dynamic> tCategoryMapEditedToJson =
|
||||
jsonDecode(fixture('measurement_category_edited_to_json.json'));
|
||||
Map<String, dynamic> tCategoryMapEdited =
|
||||
final Map<String, dynamic> tCategoryMapEdited =
|
||||
jsonDecode(fixture('measurement_category_edited.json'));
|
||||
setUp(() async {
|
||||
when(mockWgerBaseProvider.patch(any, any))
|
||||
@@ -265,7 +266,7 @@ main() {
|
||||
});
|
||||
test('should add the new MeasurementCategory and remove the old one', () async {
|
||||
// arrange
|
||||
List<MeasurementCategory> tMeasurementCategoriesEdited = [
|
||||
final List<MeasurementCategory> tMeasurementCategoriesEdited = [
|
||||
MeasurementCategory(id: 1, name: 'Triceps', unit: 'm'),
|
||||
MeasurementCategory(id: 2, name: 'Biceps', unit: 'cm'),
|
||||
];
|
||||
@@ -277,11 +278,11 @@ main() {
|
||||
expect(measurementProvider.categories, tMeasurementCategoriesEdited);
|
||||
});
|
||||
|
||||
test('should throw a NoSuchEntryException if category doesn\'t exist', () {
|
||||
test("should throw a NoSuchEntryException if category doesn't exist", () {
|
||||
// act & assert
|
||||
expect(
|
||||
() async =>
|
||||
await measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit),
|
||||
measurementProvider.editCategory(83, tCategoryEditedName, tCategoryEditedUnit),
|
||||
throwsA(isA<NoSuchEntryException>()));
|
||||
});
|
||||
|
||||
@@ -307,7 +308,7 @@ main() {
|
||||
});
|
||||
|
||||
group('addEntry()', () {
|
||||
MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntry = MeasurementEntry(
|
||||
id: 3,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 9),
|
||||
@@ -315,7 +316,7 @@ main() {
|
||||
notes: '',
|
||||
);
|
||||
|
||||
MeasurementEntry tMeasurementEntryWithoutId = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntryWithoutId = MeasurementEntry(
|
||||
id: null,
|
||||
category: 1,
|
||||
date: DateTime(2021, 7, 9),
|
||||
@@ -323,7 +324,7 @@ main() {
|
||||
notes: '',
|
||||
);
|
||||
|
||||
List<MeasurementCategory> tMeasurementCategories = [
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
@@ -347,7 +348,8 @@ main() {
|
||||
setUp(() async {
|
||||
await measurementProvider.fetchAndSetCategories();
|
||||
|
||||
Map<String, dynamic> measurementEntryMap = jsonDecode(fixture('measurement_entry.json'));
|
||||
final Map<String, dynamic> measurementEntryMap =
|
||||
jsonDecode(fixture('measurement_entry.json'));
|
||||
when(mockWgerBaseProvider.post(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(measurementEntryMap));
|
||||
});
|
||||
@@ -362,7 +364,7 @@ main() {
|
||||
|
||||
test('should post the MeasurementEntryMap', () async {
|
||||
// arrange
|
||||
Map<String, dynamic> measurementEntryMapWithoutId =
|
||||
final Map<String, dynamic> measurementEntryMapWithoutId =
|
||||
jsonDecode(fixture('measurement_entry_without_id.json'));
|
||||
|
||||
// act
|
||||
@@ -373,7 +375,7 @@ main() {
|
||||
});
|
||||
|
||||
test(
|
||||
'should add MeasurementEntry to its MeasurementCategory in the categories List and sort the category\'s list by date',
|
||||
"should add MeasurementEntry to its MeasurementCategory in the categories List and sort the category's list by date",
|
||||
() async {
|
||||
// arrange
|
||||
await measurementProvider.fetchAndSetCategoryEntries(tCategoryId);
|
||||
@@ -387,14 +389,14 @@ main() {
|
||||
|
||||
test('should throw a NoSuchEntryException if no category is found', () {
|
||||
// arrange
|
||||
MeasurementEntry tMeasurementEntryWrongCategory = MeasurementEntry(
|
||||
final MeasurementEntry tMeasurementEntryWrongCategory = MeasurementEntry(
|
||||
id: 3,
|
||||
category: 83,
|
||||
date: DateTime(2021, 7, 9),
|
||||
value: 15.00,
|
||||
notes: '',
|
||||
);
|
||||
Map<String, dynamic> measurementEntryMapWrongCategory =
|
||||
final Map<String, dynamic> measurementEntryMapWrongCategory =
|
||||
jsonDecode(fixture('measurement_entry_wrong_category.json'));
|
||||
when(mockWgerBaseProvider.post(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(measurementEntryMapWrongCategory));
|
||||
@@ -406,8 +408,8 @@ main() {
|
||||
});
|
||||
|
||||
group('deleteEntry()', () {
|
||||
int tEntryId = 2;
|
||||
List<MeasurementCategory> tMeasurementCategories = [
|
||||
const int tEntryId = 2;
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
@@ -428,7 +430,7 @@ main() {
|
||||
.thenAnswer((realInvocation) => Future.value(Response('', 200)));
|
||||
});
|
||||
|
||||
test('should remove a MeasurementEntry from the category\'s entries List for an id', () async {
|
||||
test("should remove a MeasurementEntry from the category's entries List for an id", () async {
|
||||
// act
|
||||
await measurementProvider.deleteEntry(tEntryId, tCategoryId);
|
||||
|
||||
@@ -436,14 +438,14 @@ main() {
|
||||
expect(measurementProvider.categories, tMeasurementCategories);
|
||||
});
|
||||
|
||||
test('should throw a NoSuchEntryException if the category isn\'t found', () {
|
||||
test("should throw a NoSuchEntryException if the category isn't found", () {
|
||||
// act & assert
|
||||
expect(() async => await measurementProvider.deleteEntry(tEntryId, 83),
|
||||
throwsA(isA<NoSuchEntryException>()));
|
||||
});
|
||||
|
||||
test(
|
||||
'should throw a NoSuchEntryException if the entry in the categories entries List isn\'t found',
|
||||
"should throw a NoSuchEntryException if the entry in the categories entries List isn't found",
|
||||
() {
|
||||
// act & assert
|
||||
expect(() async => await measurementProvider.deleteEntry(83, tCategoryId),
|
||||
@@ -462,7 +464,7 @@ main() {
|
||||
'should re-add the "removed" MeasurementEntry and throw a WgerHttpException if the api call fails',
|
||||
() async {
|
||||
// arrange
|
||||
List<MeasurementCategory> tMeasurementCategories = [
|
||||
final List<MeasurementCategory> tMeasurementCategories = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
@@ -497,11 +499,12 @@ main() {
|
||||
// notifyListeners()
|
||||
// should re-add the old MeasurementEntry and remove the new one if call to api fails
|
||||
// notifyListeners()
|
||||
int tEntryId = 1;
|
||||
num tEntryEditedValue = 23;
|
||||
DateTime tEntryEditedDate = DateTime(2021, 07, 21);
|
||||
String tEntryEditedNote = 'I just wanted to edit this to see what happens';
|
||||
Map<String, dynamic> tEntryMapEdited = jsonDecode(fixture('measurement_entry_edited.json'));
|
||||
const int tEntryId = 1;
|
||||
const num tEntryEditedValue = 23;
|
||||
final DateTime tEntryEditedDate = DateTime(2021, 07, 21);
|
||||
const String tEntryEditedNote = 'I just wanted to edit this to see what happens';
|
||||
final Map<String, dynamic> tEntryMapEdited =
|
||||
jsonDecode(fixture('measurement_entry_edited.json'));
|
||||
setUp(() async {
|
||||
when(mockWgerBaseProvider.patch(any, any))
|
||||
.thenAnswer((realInvocation) => Future.value(tEntryMapEdited));
|
||||
@@ -510,7 +513,7 @@ main() {
|
||||
});
|
||||
test('should add the new MeasurementEntry and remove the old one', () async {
|
||||
// arrange
|
||||
List<MeasurementCategory> tMeasurementCategoriesEdited = [
|
||||
final List<MeasurementCategory> tMeasurementCategoriesEdited = [
|
||||
MeasurementCategory(id: 1, name: 'Strength', unit: 'kN', entries: [
|
||||
MeasurementEntry(
|
||||
id: 1,
|
||||
|
||||
@@ -71,6 +71,4 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider {
|
||||
_i5.Future<_i3.Response> deleteRequest(String? url, int? id) =>
|
||||
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: Future<_i3.Response>.value(_FakeResponse_3())) as _i5.Future<_i3.Response>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ void main() {
|
||||
|
||||
var plan1 = NutritionalPlan.empty();
|
||||
var meal1 = Meal();
|
||||
var meal2 = Meal();
|
||||
final meal2 = Meal();
|
||||
|
||||
when(mockNutrition.editMeal(any)).thenAnswer((_) => Future.value(Meal()));
|
||||
when(mockNutrition.addMeal(any, any)).thenAnswer((_) => Future.value(Meal()));
|
||||
@@ -82,7 +82,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(('17:00')),
|
||||
find.text('17:00'),
|
||||
findsOneWidget,
|
||||
reason: 'Time of existing meal is filled in',
|
||||
);
|
||||
|
||||
@@ -82,7 +82,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(('test plan 1')),
|
||||
find.text('test plan 1'),
|
||||
findsOneWidget,
|
||||
reason: 'Description of existing nutritional plan is filled in',
|
||||
);
|
||||
@@ -93,7 +93,7 @@ void main() {
|
||||
verify(mockNutrition.editPlan(any));
|
||||
verifyNever(mockNutrition.addPlan(any));
|
||||
|
||||
// TODO: edit calls Navigator.pop(), since the form can only be reached from the
|
||||
// TODO(x): edit calls Navigator.pop(), since the form can only be reached from the
|
||||
// detail page. The test needs to add the detail page to the stack so that
|
||||
// this can be checked.
|
||||
// https://stackoverflow.com/questions/50704647/how-to-test-navigation-via-navigator-in-flutter
|
||||
@@ -111,7 +111,7 @@ void main() {
|
||||
await tester.pumpWidget(createHomeScreen(plan2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(('')), findsOneWidget, reason: 'New nutritional plan has no description');
|
||||
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)));
|
||||
|
||||
@@ -121,6 +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');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,8 +184,6 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
|
||||
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: Future<_i3.Response>.value(_FakeResponse_7())) as _i9.Future<_i3.Response>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) => super
|
||||
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
final repUnit = RepetitionUnit(id: 1, name: 'mol');
|
||||
final weightUnit = WeightUnit(id: 1, name: 'mg');
|
||||
|
||||
var setting = Setting.empty();
|
||||
final setting = Setting.empty();
|
||||
setting.reps = 2;
|
||||
setting.weight = 30;
|
||||
setting.rir = '';
|
||||
@@ -40,7 +40,7 @@ void main() {
|
||||
final repUnit = RepetitionUnit(id: 1, name: 'mol');
|
||||
final weightUnit = WeightUnit(id: 1, name: 'mg');
|
||||
|
||||
var setting = Setting.empty();
|
||||
final setting = Setting.empty();
|
||||
setting.reps = 2;
|
||||
setting.weight = 30;
|
||||
setting.rir = '1.5';
|
||||
@@ -53,7 +53,7 @@ void main() {
|
||||
final repUnit = RepetitionUnit(id: 1, name: 'mol');
|
||||
final weightUnit = WeightUnit(id: 1, name: 'mg');
|
||||
|
||||
var setting = Setting.empty();
|
||||
final setting = Setting.empty();
|
||||
setting.reps = 2;
|
||||
setting.weight = null;
|
||||
setting.rir = '1.5';
|
||||
@@ -66,7 +66,7 @@ void main() {
|
||||
final repUnit = RepetitionUnit(id: 2, name: 'mol');
|
||||
final weightUnit = WeightUnit(id: 2, name: 'mg');
|
||||
|
||||
var setting = Setting.empty();
|
||||
final setting = Setting.empty();
|
||||
setting.reps = 2;
|
||||
setting.weight = 30;
|
||||
setting.rir = '';
|
||||
@@ -79,7 +79,7 @@ void main() {
|
||||
final repUnit = RepetitionUnit(id: 2, name: 'mol');
|
||||
final weightUnit = WeightUnit(id: 2, name: 'mg');
|
||||
|
||||
var setting = Setting.empty();
|
||||
final setting = Setting.empty();
|
||||
setting.reps = 2;
|
||||
setting.weight = 30;
|
||||
setting.rir = '3';
|
||||
|
||||
@@ -30,8 +30,8 @@ void main() {
|
||||
});
|
||||
|
||||
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({
|
||||
final WeightEntry weightEntryObj = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31));
|
||||
final WeightEntry weightEntry = WeightEntry.fromJson({
|
||||
'id': 1,
|
||||
'weight': '80',
|
||||
'date': '2020-12-31',
|
||||
|
||||
@@ -41,7 +41,7 @@ void main() {
|
||||
200));
|
||||
|
||||
// Load the entries
|
||||
BodyWeightProvider provider = BodyWeightProvider(testAuthProvider, [], client);
|
||||
final BodyWeightProvider provider = BodyWeightProvider(testAuthProvider, [], client);
|
||||
await provider.fetchAndSetEntries();
|
||||
|
||||
// Check that everything is ok
|
||||
|
||||
@@ -71,7 +71,7 @@ void main() {
|
||||
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)));
|
||||
|
||||
@@ -82,12 +82,12 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(('test 1')),
|
||||
find.text('test 1'),
|
||||
findsOneWidget,
|
||||
reason: 'Name of existing workout plan',
|
||||
);
|
||||
expect(
|
||||
find.text(('description 1')),
|
||||
find.text('description 1'),
|
||||
findsOneWidget,
|
||||
reason: 'Description of existing workout plan',
|
||||
);
|
||||
@@ -98,7 +98,7 @@ void main() {
|
||||
verify(mockWorkoutPlans.editWorkout(any));
|
||||
verifyNever(mockWorkoutPlans.addWorkout(any));
|
||||
|
||||
// TODO: edit calls Navigator.pop(), since the form can only be reached from the
|
||||
// TODO(x): edit calls Navigator.pop(), since the form can only be reached from the
|
||||
// detail page. The test needs to add the detail page to the stack so that
|
||||
// this can be checked.
|
||||
// https://stackoverflow.com/questions/50704647/how-to-test-navigation-via-navigator-in-flutter
|
||||
@@ -119,7 +119,7 @@ void main() {
|
||||
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)));
|
||||
|
||||
@@ -128,7 +128,7 @@ 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 {
|
||||
@@ -139,7 +139,7 @@ void main() {
|
||||
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.tap(find.byKey(Key(SUBMIT_BUTTON_KEY_NAME)));
|
||||
@@ -149,6 +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');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -247,8 +247,6 @@ class MockWorkoutPlansProvider extends _i1.Mock implements _i12.WorkoutPlansProv
|
||||
Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: Future<_i5.Response>.value(_FakeResponse_11())) as _i13.Future<_i5.Response>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
@override
|
||||
void addListener(_i15.VoidCallback? listener) => super
|
||||
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -41,13 +41,13 @@ import 'workout_set_form_test.mocks.dart';
|
||||
@GenerateMocks([ExercisesProvider])
|
||||
void main() {
|
||||
var mockWorkoutPlans = MockWorkoutPlansProvider();
|
||||
MockExercisesProvider mockExercises = MockExercisesProvider();
|
||||
WorkoutPlan workoutPlan = getWorkout();
|
||||
final MockExercisesProvider mockExercises = MockExercisesProvider();
|
||||
final WorkoutPlan workoutPlan = getWorkout();
|
||||
final client = MockClient();
|
||||
Day day = Day();
|
||||
|
||||
setUp(() {
|
||||
WorkoutPlan workoutPlan = getWorkout();
|
||||
final WorkoutPlan workoutPlan = getWorkout();
|
||||
day = workoutPlan.days.first;
|
||||
mockWorkoutPlans = MockWorkoutPlansProvider();
|
||||
});
|
||||
|
||||
@@ -115,8 +115,6 @@ class MockExercisesProvider extends _i1.Mock implements _i5.ExercisesProvider {
|
||||
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: Future<_i3.Response>.value(_FakeResponse_4())) as _i6.Future<_i3.Response>);
|
||||
@override
|
||||
String toString() => super.toString();
|
||||
@override
|
||||
void addListener(_i7.VoidCallback? listener) => super
|
||||
.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -33,7 +33,7 @@ const RepetitionUnit repetitionUnit1 = RepetitionUnit(id: 1, name: 'Repetitions'
|
||||
const RepetitionUnit repetitionUnit2 = RepetitionUnit(id: 2, name: 'Hours');
|
||||
|
||||
WorkoutPlan getWorkout() {
|
||||
var setting1 = Setting(
|
||||
final setting1 = Setting(
|
||||
setId: 1,
|
||||
order: 1,
|
||||
exerciseId: 1,
|
||||
@@ -48,7 +48,7 @@ WorkoutPlan getWorkout() {
|
||||
setting1.exercise = exercise1;
|
||||
setting1.weight = 10;
|
||||
|
||||
var log1 = Log.empty()
|
||||
final log1 = Log.empty()
|
||||
..id = 1
|
||||
..weight = 10
|
||||
..rir = '1.5'
|
||||
@@ -59,7 +59,7 @@ WorkoutPlan getWorkout() {
|
||||
log1.weightUnit = weightUnit1;
|
||||
log1.repetitionUnit = repetitionUnit1;
|
||||
|
||||
var log2 = Log.empty()
|
||||
final log2 = Log.empty()
|
||||
..id = 2
|
||||
..weight = 10
|
||||
..rir = '2'
|
||||
@@ -70,7 +70,7 @@ WorkoutPlan getWorkout() {
|
||||
log2.weightUnit = weightUnit1;
|
||||
log2.repetitionUnit = repetitionUnit1;
|
||||
|
||||
var log3 = Log.empty()
|
||||
final log3 = Log.empty()
|
||||
..id = 3
|
||||
..weight = 50
|
||||
..rir = ''
|
||||
@@ -81,7 +81,7 @@ WorkoutPlan getWorkout() {
|
||||
log3.weightUnit = weightUnit1;
|
||||
log3.repetitionUnit = repetitionUnit1;
|
||||
|
||||
var set1 = Set.withData(
|
||||
final set1 = Set.withData(
|
||||
id: 1,
|
||||
day: 1,
|
||||
sets: 3,
|
||||
@@ -92,20 +92,20 @@ WorkoutPlan getWorkout() {
|
||||
set1.settings.add(setting1);
|
||||
set1.settingsComputed = [setting1, setting1];
|
||||
|
||||
var day1 = Day()
|
||||
final day1 = Day()
|
||||
..id = 1
|
||||
..workoutId = 1
|
||||
..description = 'test day 1'
|
||||
..daysOfWeek = [1, 2];
|
||||
day1.sets.add(set1);
|
||||
|
||||
var day2 = Day()
|
||||
final day2 = Day()
|
||||
..id = 2
|
||||
..workoutId = 1
|
||||
..description = 'test day 2'
|
||||
..daysOfWeek = [4];
|
||||
|
||||
var workout = WorkoutPlan(
|
||||
final workout = WorkoutPlan(
|
||||
id: 1,
|
||||
creationDate: DateTime(2021, 01, 01),
|
||||
name: 'test workout 1',
|
||||
|
||||
Reference in New Issue
Block a user