mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 01:41:05 +01:00
Upgrade packages and move application to null safety
This commit is contained in:
@@ -24,11 +24,11 @@ fastlane playstore
|
||||
----
|
||||
|
||||
## Android
|
||||
### android updateclosed_beta
|
||||
### android updateclosed_alpha
|
||||
```
|
||||
fastlane android updateclosed_beta
|
||||
fastlane android updateclosed_alpha
|
||||
```
|
||||
Update store entry
|
||||
Upload closed alpha app and update store entry
|
||||
### android test
|
||||
```
|
||||
fastlane android test
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
|
||||
|
||||
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.0021915">
|
||||
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.0022505">
|
||||
|
||||
</testcase>
|
||||
|
||||
|
||||
<testcase classname="fastlane.lanes" name="1: upload_to_play_store" time="69.5044726">
|
||||
<testcase classname="fastlane.lanes" name="1: upload_to_play_store" time="44.4966676">
|
||||
|
||||
</testcase>
|
||||
|
||||
|
||||
@@ -21,5 +21,11 @@
|
||||
const double ICON_SIZE_SMALL = 20;
|
||||
|
||||
/// Default wger server during login
|
||||
final DEFAULT_SERVER = 'https://wger.rge.uber.space';
|
||||
const DEFAULT_SERVER = 'https://wger.rge.uber.space';
|
||||
//final DEFAULT_SERVER = 'http://localhost:8000';
|
||||
|
||||
/// Default weight unit is "kg"
|
||||
const DEFAULT_WEIGHT_UNIT = 1;
|
||||
|
||||
/// Default weight unit is "repetition"
|
||||
const DEFAULT_REPETITION_UNIT = 1;
|
||||
|
||||
@@ -19,14 +19,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
num toNum(String e) {
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
return num.parse(e);
|
||||
num toNum(String? e) {
|
||||
return e == null ? 0 : num.parse(e);
|
||||
}
|
||||
|
||||
String toString(num e) {
|
||||
String? toString(num? e) {
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -38,7 +35,7 @@ String toString(num e) {
|
||||
* Converts a datetime to ISO8601 date format, but only the date.
|
||||
* Needed e.g. when the wger api only expects a date and no time information.
|
||||
*/
|
||||
String toDate(DateTime dateTime) {
|
||||
String? toDate(DateTime? dateTime) {
|
||||
if (dateTime == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -49,19 +46,17 @@ String toDate(DateTime dateTime) {
|
||||
* Converts a time to a date object.
|
||||
* Needed e.g. when the wger api only sends a time but no date information.
|
||||
*/
|
||||
TimeOfDay stringToTime(String time) {
|
||||
if (time == null) {
|
||||
return null;
|
||||
}
|
||||
TimeOfDay stringToTime(String? time) {
|
||||
String out = time ?? '00:00';
|
||||
return TimeOfDay.fromDateTime(
|
||||
DateTime.parse('2020-01-01 $time'),
|
||||
DateTime.parse('2020-01-01 $out'),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a datetime to time.
|
||||
*/
|
||||
String timeToString(TimeOfDay time) {
|
||||
String? timeToString(TimeOfDay? time) {
|
||||
if (time == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ void showErrorDialog(dynamic exception, BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(AppLocalizations.of(context).anErrorOccurred),
|
||||
title: Text(AppLocalizations.of(context)!.anErrorOccurred),
|
||||
content: Text(exception.toString()),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).dismiss),
|
||||
child: Text(AppLocalizations.of(context)!.dismiss),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
@@ -50,15 +50,15 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
log('-------------------');
|
||||
|
||||
List<Widget> errorList = [];
|
||||
for (var key in exception.errors.keys) {
|
||||
for (var key in exception.errors!.keys) {
|
||||
// Error headers
|
||||
errorList.add(Text(key, style: TextStyle(fontWeight: FontWeight.bold)));
|
||||
|
||||
// Error messages
|
||||
if (exception.errors[key] is String) {
|
||||
errorList.add(Text(exception.errors[key]));
|
||||
if (exception.errors![key] is String) {
|
||||
errorList.add(Text(exception.errors![key]));
|
||||
} else {
|
||||
for (var value in exception.errors[key]) {
|
||||
for (var value in exception.errors![key]) {
|
||||
errorList.add(Text(value));
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(AppLocalizations.of(context).anErrorOccurred),
|
||||
title: Text(AppLocalizations.of(context)!.anErrorOccurred),
|
||||
content: Container(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -76,7 +76,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).dismiss),
|
||||
child: Text(AppLocalizations.of(context)!.dismiss),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
|
||||
@@ -51,28 +51,28 @@ class MyApp extends StatelessWidget {
|
||||
create: (ctx) => Auth(),
|
||||
),
|
||||
ChangeNotifierProxyProvider<Auth, WorkoutPlans>(
|
||||
create: null, // TODO: Create is required but it can be null??
|
||||
create: (context) => WorkoutPlans(Auth(), []),
|
||||
update: (context, auth, previous) => WorkoutPlans(
|
||||
auth,
|
||||
previous == null ? [] : previous.items,
|
||||
),
|
||||
),
|
||||
ChangeNotifierProxyProvider<Auth, Exercises>(
|
||||
create: null, // TODO: Create is required but it can be null??
|
||||
create: (context) => Exercises(Auth(), []),
|
||||
update: (context, auth, previous) => Exercises(
|
||||
auth,
|
||||
previous == null ? [] : previous.items,
|
||||
),
|
||||
),
|
||||
ChangeNotifierProxyProvider<Auth, Nutrition>(
|
||||
create: null, // TODO: Create is required but it can be null??
|
||||
create: (context) => Nutrition(Auth(), []),
|
||||
update: (context, auth, previous) => Nutrition(
|
||||
auth,
|
||||
previous == null ? [] : previous.items,
|
||||
),
|
||||
),
|
||||
ChangeNotifierProxyProvider<Auth, BodyWeight>(
|
||||
create: null, // TODO: Create is required but it can be null??
|
||||
create: (context) => BodyWeight(Auth(), []),
|
||||
update: (context, auth, previous) => BodyWeight(
|
||||
auth,
|
||||
previous == null ? [] : previous.items,
|
||||
|
||||
@@ -24,19 +24,25 @@ part 'weight_entry.g.dart';
|
||||
@JsonSerializable()
|
||||
class WeightEntry {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum, toJson: toString)
|
||||
num weight;
|
||||
late num weight;
|
||||
|
||||
@JsonKey(required: true, toJson: toDate)
|
||||
DateTime date;
|
||||
late DateTime date;
|
||||
|
||||
WeightEntry({
|
||||
this.id,
|
||||
this.weight,
|
||||
this.date,
|
||||
});
|
||||
weight,
|
||||
DateTime? date,
|
||||
}) {
|
||||
this.date = date ?? DateTime.now();
|
||||
|
||||
if (weight != null) {
|
||||
this.weight = weight;
|
||||
}
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory WeightEntry.fromJson(Map<String, dynamic> json) => _$WeightEntryFromJson(json);
|
||||
|
||||
@@ -9,9 +9,9 @@ part of 'weight_entry.dart';
|
||||
WeightEntry _$WeightEntryFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'weight', 'date']);
|
||||
return WeightEntry(
|
||||
id: json['id'] as int,
|
||||
weight: toNum(json['weight'] as String),
|
||||
date: json['date'] == null ? null : DateTime.parse(json['date'] as String),
|
||||
id: json['id'] as int?,
|
||||
weight: toNum(json['weight'] as String?),
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ class ExerciseCategory {
|
||||
final String name;
|
||||
|
||||
ExerciseCategory({
|
||||
this.id,
|
||||
this.name,
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -29,8 +29,8 @@ class Comment {
|
||||
final String comment;
|
||||
|
||||
Comment({
|
||||
this.id,
|
||||
this.comment,
|
||||
required this.id,
|
||||
required this.comment,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'equipment.g.dart';
|
||||
@@ -30,8 +29,8 @@ class Equipment {
|
||||
final String name;
|
||||
|
||||
Equipment({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -42,8 +42,11 @@ class Exercise {
|
||||
@JsonKey(required: true)
|
||||
final String description;
|
||||
|
||||
@JsonKey(required: true)
|
||||
final ExerciseCategory category;
|
||||
@JsonKey(required: false)
|
||||
final int categoryId;
|
||||
|
||||
@JsonKey(required: true, name: 'category')
|
||||
late final ExerciseCategory categoryObj;
|
||||
|
||||
@JsonKey(required: true)
|
||||
List<Muscle> muscles = [];
|
||||
@@ -61,18 +64,24 @@ class Exercise {
|
||||
List<Comment> tips = [];
|
||||
|
||||
Exercise({
|
||||
this.id,
|
||||
this.uuid,
|
||||
this.creationDate,
|
||||
this.name,
|
||||
this.description,
|
||||
this.category,
|
||||
this.muscles,
|
||||
this.musclesSecondary,
|
||||
this.equipment,
|
||||
this.images,
|
||||
this.tips,
|
||||
});
|
||||
required this.id,
|
||||
required this.uuid,
|
||||
required this.creationDate,
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.categoryId,
|
||||
List<Muscle>? muscles,
|
||||
List<Muscle>? musclesSecondary,
|
||||
List<Equipment>? equipment,
|
||||
List<ExerciseImage>? images,
|
||||
List<Comment>? tips,
|
||||
}) {
|
||||
this.tips = tips ?? [];
|
||||
this.images = images ?? [];
|
||||
this.equipment = equipment ?? [];
|
||||
this.musclesSecondary = musclesSecondary ?? [];
|
||||
this.muscles = muscles ?? [];
|
||||
}
|
||||
|
||||
ExerciseImage get getMainImage {
|
||||
return images.firstWhere((image) => image.isMain);
|
||||
|
||||
@@ -23,49 +23,41 @@ Exercise _$ExerciseFromJson(Map<String, dynamic> json) {
|
||||
return Exercise(
|
||||
id: json['id'] as int,
|
||||
uuid: json['uuid'] as String,
|
||||
creationDate: json['creation_date'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creation_date'] as String),
|
||||
creationDate: DateTime.parse(json['creation_date'] as String),
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
category: json['category'] == null
|
||||
? null
|
||||
: ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>),
|
||||
muscles: (json['muscles'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Muscle.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
musclesSecondary: (json['muscles_secondary'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Muscle.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
equipment: (json['equipment'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Equipment.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
images: (json['images'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: ExerciseImage.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
tips: (json['comments'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Comment.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
);
|
||||
categoryId: json['categoryId'] as int,
|
||||
muscles: (json['muscles'] as List<dynamic>?)
|
||||
?.map((e) => Muscle.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
musclesSecondary: (json['muscles_secondary'] as List<dynamic>?)
|
||||
?.map((e) => Muscle.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
equipment: (json['equipment'] as List<dynamic>?)
|
||||
?.map((e) => Equipment.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
images: (json['images'] as List<dynamic>?)
|
||||
?.map((e) => ExerciseImage.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
tips: (json['comments'] as List<dynamic>?)
|
||||
?.map((e) => Comment.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
)..categoryObj =
|
||||
ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ExerciseToJson(Exercise instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'creation_date': instance.creationDate?.toIso8601String(),
|
||||
'creation_date': instance.creationDate.toIso8601String(),
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'category': instance.category?.toJson(),
|
||||
'muscles': instance.muscles?.map((e) => e?.toJson())?.toList(),
|
||||
'categoryId': instance.categoryId,
|
||||
'category': instance.categoryObj.toJson(),
|
||||
'muscles': instance.muscles.map((e) => e.toJson()).toList(),
|
||||
'muscles_secondary':
|
||||
instance.musclesSecondary?.map((e) => e?.toJson())?.toList(),
|
||||
'equipment': instance.equipment?.map((e) => e?.toJson())?.toList(),
|
||||
'images': instance.images?.map((e) => e?.toJson())?.toList(),
|
||||
'comments': instance.tips?.map((e) => e?.toJson())?.toList(),
|
||||
instance.musclesSecondary.map((e) => e.toJson()).toList(),
|
||||
'equipment': instance.equipment.map((e) => e.toJson()).toList(),
|
||||
'images': instance.images.map((e) => e.toJson()).toList(),
|
||||
'comments': instance.tips.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
@@ -29,8 +29,8 @@ class ExerciseImage {
|
||||
final bool isMain;
|
||||
|
||||
ExerciseImage({
|
||||
this.url,
|
||||
this.isMain,
|
||||
required this.url,
|
||||
required this.isMain,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -10,7 +10,7 @@ ExerciseImage _$ExerciseImageFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['image']);
|
||||
return ExerciseImage(
|
||||
url: json['image'] as String,
|
||||
isMain: json['is_main'] as bool ?? false,
|
||||
isMain: json['is_main'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ class Muscle {
|
||||
final bool isFront;
|
||||
|
||||
Muscle({
|
||||
this.id,
|
||||
this.name,
|
||||
this.isFront,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.isFront,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class WgerHttpException implements Exception {
|
||||
Map<String, dynamic> errors;
|
||||
Map<String, dynamic>? errors;
|
||||
|
||||
/// Custom http exception.
|
||||
/// Expects the response body of the REST call and will try to parse it to
|
||||
@@ -39,6 +39,6 @@ class WgerHttpException implements Exception {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return errors.values.toList().join(', ');
|
||||
return errors!.values.toList().join(', ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
|
||||
@@ -58,17 +57,17 @@ class Ingredient {
|
||||
final num sodium;
|
||||
|
||||
Ingredient({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
@required this.creationDate,
|
||||
@required this.energy,
|
||||
@required this.carbohydrates,
|
||||
@required this.carbohydratesSugar,
|
||||
@required this.protein,
|
||||
@required this.fat,
|
||||
@required this.fatSaturated,
|
||||
@required this.fibres,
|
||||
@required this.sodium,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.creationDate,
|
||||
required this.energy,
|
||||
required this.carbohydrates,
|
||||
required this.carbohydratesSugar,
|
||||
required this.protein,
|
||||
required this.fat,
|
||||
required this.fatSaturated,
|
||||
required this.fibres,
|
||||
required this.sodium,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -23,17 +23,15 @@ Ingredient _$IngredientFromJson(Map<String, dynamic> json) {
|
||||
return Ingredient(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
creationDate: json['creation_date'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creation_date'] as String),
|
||||
creationDate: DateTime.parse(json['creation_date'] as String),
|
||||
energy: json['energy'] as int,
|
||||
carbohydrates: toNum(json['carbohydrates'] as String),
|
||||
carbohydratesSugar: toNum(json['carbohydrates_sugar'] as String),
|
||||
protein: toNum(json['protein'] as String),
|
||||
fat: toNum(json['fat'] as String),
|
||||
fatSaturated: toNum(json['fat_saturated'] as String),
|
||||
fibres: toNum(json['fibres'] as String),
|
||||
sodium: toNum(json['sodium'] as String),
|
||||
carbohydrates: toNum(json['carbohydrates'] as String?),
|
||||
carbohydratesSugar: toNum(json['carbohydrates_sugar'] as String?),
|
||||
protein: toNum(json['protein'] as String?),
|
||||
fat: toNum(json['fat'] as String?),
|
||||
fatSaturated: toNum(json['fat_saturated'] as String?),
|
||||
fibres: toNum(json['fibres'] as String?),
|
||||
sodium: toNum(json['sodium'] as String?),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.dart';
|
||||
import 'package:wger/models/nutrition/weight_unit.dart';
|
||||
@@ -41,11 +40,11 @@ class IngredientWeightUnit {
|
||||
final double amount;
|
||||
|
||||
IngredientWeightUnit({
|
||||
@required this.id,
|
||||
@required this.weightUnit,
|
||||
@required this.ingredient,
|
||||
@required this.grams,
|
||||
@required this.amount,
|
||||
required this.id,
|
||||
required this.weightUnit,
|
||||
required this.ingredient,
|
||||
required this.grams,
|
||||
required this.amount,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -16,14 +16,11 @@ IngredientWeightUnit _$IngredientWeightUnitFromJson(Map<String, dynamic> json) {
|
||||
]);
|
||||
return IngredientWeightUnit(
|
||||
id: json['id'] as int,
|
||||
weightUnit: json['weight_unit'] == null
|
||||
? null
|
||||
: WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
|
||||
ingredient: json['ingredient'] == null
|
||||
? null
|
||||
: Ingredient.fromJson(json['ingredient'] as Map<String, dynamic>),
|
||||
weightUnit:
|
||||
WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
|
||||
ingredient: Ingredient.fromJson(json['ingredient'] as Map<String, dynamic>),
|
||||
grams: json['grams'] as int,
|
||||
amount: (json['amount'] as num)?.toDouble(),
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,45 +29,48 @@ part 'log.g.dart';
|
||||
@JsonSerializable()
|
||||
class Log {
|
||||
@JsonKey(required: true)
|
||||
int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true, name: 'plan')
|
||||
int planId;
|
||||
late int planId;
|
||||
|
||||
@JsonKey(required: true)
|
||||
DateTime datetime;
|
||||
late DateTime datetime;
|
||||
|
||||
String comment;
|
||||
String? comment;
|
||||
|
||||
@JsonKey(required: true, name: 'ingredient')
|
||||
int ingredientId;
|
||||
late int ingredientId;
|
||||
|
||||
Ingredient ingredientObj;
|
||||
@JsonKey(ignore: true)
|
||||
late Ingredient ingredientObj;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
int weightUnit;
|
||||
late int weightUnit;
|
||||
|
||||
IngredientWeightUnit weightUnitObj;
|
||||
IngredientWeightUnit? weightUnitObj;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum)
|
||||
num amount;
|
||||
late num amount;
|
||||
|
||||
Log({
|
||||
this.id,
|
||||
this.ingredientId,
|
||||
this.ingredientObj,
|
||||
this.weightUnit,
|
||||
required this.ingredientId,
|
||||
//this.ingredientObj,
|
||||
required this.weightUnit,
|
||||
this.weightUnitObj,
|
||||
this.amount,
|
||||
this.planId,
|
||||
this.datetime,
|
||||
required this.amount,
|
||||
required this.planId,
|
||||
required this.datetime,
|
||||
this.comment,
|
||||
});
|
||||
|
||||
Log.fromMealItem(MealItem mealItem) {
|
||||
this.ingredientId = mealItem.ingredientId;
|
||||
Log.fromMealItem(MealItem mealItem, int planId, [DateTime? dateTime]) {
|
||||
this.ingredientId = mealItem.ingredientId!;
|
||||
this.ingredientObj = mealItem.ingredientObj;
|
||||
this.weightUnit = null;
|
||||
this.weightUnit = mealItem.weightUnit!.id;
|
||||
this.planId = planId;
|
||||
this.datetime = dateTime ?? DateTime.now();
|
||||
this.amount = mealItem.amount;
|
||||
}
|
||||
|
||||
@@ -80,8 +83,9 @@ class Log {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
|
||||
final weight =
|
||||
this.weightUnitObj == null ? amount : amount * weightUnitObj.amount * weightUnitObj.grams;
|
||||
final weight = amount;
|
||||
// final weight =
|
||||
// this.weightUnitObj == null ? amount : amount * weightUnitObj.amount * weightUnitObj.grams;
|
||||
|
||||
out.energy = ingredientObj.energy * weight / 100;
|
||||
out.protein = ingredientObj.protein * weight / 100;
|
||||
|
||||
@@ -16,32 +16,26 @@ Log _$LogFromJson(Map<String, dynamic> json) {
|
||||
'amount'
|
||||
]);
|
||||
return Log(
|
||||
id: json['id'] as int,
|
||||
id: json['id'] as int?,
|
||||
ingredientId: json['ingredient'] as int,
|
||||
ingredientObj: json['ingredientObj'] == null
|
||||
? null
|
||||
: Ingredient.fromJson(json['ingredientObj'] as Map<String, dynamic>),
|
||||
weightUnit: json['weight_unit'] as int,
|
||||
weightUnitObj: json['weightUnitObj'] == null
|
||||
? null
|
||||
: IngredientWeightUnit.fromJson(
|
||||
json['weightUnitObj'] as Map<String, dynamic>),
|
||||
amount: toNum(json['amount'] as String),
|
||||
amount: toNum(json['amount'] as String?),
|
||||
planId: json['plan'] as int,
|
||||
datetime: json['datetime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['datetime'] as String),
|
||||
comment: json['comment'] as String,
|
||||
datetime: DateTime.parse(json['datetime'] as String),
|
||||
comment: json['comment'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$LogToJson(Log instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'plan': instance.planId,
|
||||
'datetime': instance.datetime?.toIso8601String(),
|
||||
'datetime': instance.datetime.toIso8601String(),
|
||||
'comment': instance.comment,
|
||||
'ingredient': instance.ingredientId,
|
||||
'ingredientObj': instance.ingredientObj,
|
||||
'weight_unit': instance.weightUnit,
|
||||
'weightUnitObj': instance.weightUnitObj,
|
||||
'amount': instance.amount,
|
||||
|
||||
@@ -28,23 +28,31 @@ part 'meal.g.dart';
|
||||
@JsonSerializable()
|
||||
class Meal {
|
||||
@JsonKey(required: false)
|
||||
final int id;
|
||||
late int? id;
|
||||
|
||||
@JsonKey(required: false)
|
||||
int plan;
|
||||
late int plan;
|
||||
|
||||
@JsonKey(required: true, toJson: timeToString, fromJson: stringToTime)
|
||||
TimeOfDay time;
|
||||
late TimeOfDay time;
|
||||
|
||||
@JsonKey(required: false, name: 'meal_items', defaultValue: [])
|
||||
List<MealItem> mealItems = [];
|
||||
|
||||
Meal({
|
||||
this.id,
|
||||
this.plan,
|
||||
this.time,
|
||||
this.mealItems,
|
||||
});
|
||||
int? plan,
|
||||
TimeOfDay? time,
|
||||
//List<MealItem>? mealItems,
|
||||
}) {
|
||||
if (plan != null) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
this.time = time ?? TimeOfDay.now();
|
||||
|
||||
this.mealItems = [];
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory Meal.fromJson(Map<String, dynamic> json) => _$MealFromJson(json);
|
||||
|
||||
@@ -9,15 +9,13 @@ part of 'meal.dart';
|
||||
Meal _$MealFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['time']);
|
||||
return Meal(
|
||||
id: json['id'] as int,
|
||||
plan: json['plan'] as int,
|
||||
time: stringToTime(json['time'] as String),
|
||||
mealItems: (json['meal_items'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : MealItem.fromJson(e as Map<String, dynamic>))
|
||||
?.toList() ??
|
||||
[],
|
||||
);
|
||||
id: json['id'] as int?,
|
||||
plan: json['plan'] as int?,
|
||||
time: stringToTime(json['time'] as String?),
|
||||
)..mealItems = (json['meal_items'] as List<dynamic>?)
|
||||
?.map((e) => MealItem.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MealToJson(Meal instance) => <String, dynamic>{
|
||||
|
||||
@@ -28,29 +28,42 @@ part 'meal_item.g.dart';
|
||||
@JsonSerializable()
|
||||
class MealItem {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: false, name: 'ingredient')
|
||||
int ingredientId;
|
||||
int? ingredientId;
|
||||
|
||||
@JsonKey(required: false, name: 'ingredient_obj')
|
||||
Ingredient ingredientObj;
|
||||
late Ingredient ingredientObj;
|
||||
|
||||
@JsonKey(required: false)
|
||||
int meal;
|
||||
late int meal;
|
||||
|
||||
@JsonKey(required: false, name: 'weight_unit')
|
||||
IngredientWeightUnit weightUnit;
|
||||
IngredientWeightUnit? weightUnit;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum, toJson: toString)
|
||||
num amount;
|
||||
late num amount;
|
||||
|
||||
MealItem({
|
||||
this.id,
|
||||
this.ingredientObj,
|
||||
int? meal,
|
||||
//this.ingredientObj,
|
||||
ingredientId,
|
||||
this.weightUnit,
|
||||
this.amount,
|
||||
});
|
||||
num? amount,
|
||||
}) {
|
||||
if (meal != null) {
|
||||
this.meal = meal;
|
||||
}
|
||||
|
||||
if (ingredientId != null) {
|
||||
this.ingredientId = ingredientId;
|
||||
}
|
||||
if (amount != null) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory MealItem.fromJson(Map<String, dynamic> json) => _$MealItemFromJson(json);
|
||||
@@ -62,24 +75,16 @@ class MealItem {
|
||||
// This is already done on the server. It might be better to read it from there.
|
||||
var out = NutritionalValues();
|
||||
|
||||
final weight = this.weightUnit == null ? amount : amount * weightUnit.amount * weightUnit.grams;
|
||||
//final weight = this.weightUnit == null ? amount : amount * weightUnit.amount * weightUnit.grams;
|
||||
final weight = amount;
|
||||
|
||||
out.energy = ingredientObj.energy * weight / 100;
|
||||
out.protein = ingredientObj.protein * weight / 100;
|
||||
out.carbohydrates = ingredientObj.carbohydrates * weight / 100;
|
||||
out.fat = ingredientObj.fat * weight / 100;
|
||||
|
||||
if (ingredientObj.fatSaturated != null) {
|
||||
out.fatSaturated = ingredientObj.fatSaturated * weight / 100;
|
||||
}
|
||||
|
||||
if (ingredientObj.fibres != null) {
|
||||
out.fibres = ingredientObj.fibres * weight / 100;
|
||||
}
|
||||
|
||||
if (ingredientObj.sodium != null) {
|
||||
out.sodium = ingredientObj.sodium * weight / 100;
|
||||
}
|
||||
out.fatSaturated = ingredientObj.fatSaturated * weight / 100;
|
||||
out.fibres = ingredientObj.fibres * weight / 100;
|
||||
out.sodium = ingredientObj.sodium * weight / 100;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -9,18 +9,16 @@ part of 'meal_item.dart';
|
||||
MealItem _$MealItemFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'amount']);
|
||||
return MealItem(
|
||||
id: json['id'] as int,
|
||||
ingredientObj: json['ingredient_obj'] == null
|
||||
? null
|
||||
: Ingredient.fromJson(json['ingredient_obj'] as Map<String, dynamic>),
|
||||
id: json['id'] as int?,
|
||||
meal: json['meal'] as int,
|
||||
ingredientId: json['ingredient'] as int,
|
||||
weightUnit: json['weight_unit'] == null
|
||||
? null
|
||||
: IngredientWeightUnit.fromJson(
|
||||
json['weight_unit'] as Map<String, dynamic>),
|
||||
amount: toNum(json['amount'] as String),
|
||||
)
|
||||
..ingredientId = json['ingredient'] as int
|
||||
..meal = json['meal'] as int;
|
||||
amount: toNum(json['amount'] as String?),
|
||||
)..ingredientObj =
|
||||
Ingredient.fromJson(json['ingredient_obj'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MealItemToJson(MealItem instance) => <String, dynamic>{
|
||||
|
||||
@@ -28,7 +28,7 @@ part 'nutritional_plan.g.dart';
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class NutritionalPlan {
|
||||
@JsonKey(required: true)
|
||||
int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true)
|
||||
String description;
|
||||
@@ -44,12 +44,15 @@ class NutritionalPlan {
|
||||
|
||||
NutritionalPlan({
|
||||
this.id,
|
||||
this.description,
|
||||
this.creationDate,
|
||||
this.meals,
|
||||
//this.logs,
|
||||
required this.description,
|
||||
required this.creationDate,
|
||||
//List<Meal>? meals,
|
||||
//logs,
|
||||
}) {
|
||||
this.meals = meals ?? [];
|
||||
//this.meals = meals as List<Meal> ?? [];
|
||||
this.meals = [];
|
||||
//this.logs = logs ?? [];
|
||||
this.logs = [];
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
@@ -78,7 +81,7 @@ class NutritionalPlan {
|
||||
out[date] = NutritionalValues();
|
||||
}
|
||||
|
||||
out[date].add(log.nutritionalValues);
|
||||
out[date]!.add(log.nutritionalValues);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
@@ -9,17 +9,13 @@ part of 'nutritional_plan.dart';
|
||||
NutritionalPlan _$NutritionalPlanFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'description', 'creation_date']);
|
||||
return NutritionalPlan(
|
||||
id: json['id'] as int,
|
||||
id: json['id'] as int?,
|
||||
description: json['description'] as String,
|
||||
creationDate: json['creation_date'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creation_date'] as String),
|
||||
meals: (json['meals'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Meal.fromJson(e as Map<String, dynamic>))
|
||||
?.toList() ??
|
||||
[],
|
||||
);
|
||||
creationDate: DateTime.parse(json['creation_date'] as String),
|
||||
)..meals = (json['meals'] as List<dynamic>?)
|
||||
?.map((e) => Meal.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) =>
|
||||
@@ -27,5 +23,5 @@ Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) =>
|
||||
'id': instance.id,
|
||||
'description': instance.description,
|
||||
'creation_date': toDate(instance.creationDate),
|
||||
'meals': instance.meals?.map((e) => e?.toJson())?.toList(),
|
||||
'meals': instance.meals.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'weight_unit.g.dart';
|
||||
@@ -30,8 +29,8 @@ class WeightUnit {
|
||||
final String name;
|
||||
|
||||
WeightUnit({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -7,10 +7,10 @@ part 'day.g.dart';
|
||||
@JsonSerializable()
|
||||
class Day {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true)
|
||||
String description;
|
||||
late String description;
|
||||
|
||||
@JsonKey(required: false, name: 'day', defaultValue: [])
|
||||
List<int> daysOfWeek = [];
|
||||
@@ -19,19 +19,25 @@ class Day {
|
||||
List<Set> sets = [];
|
||||
|
||||
@JsonKey(required: true, name: 'training')
|
||||
int workoutId;
|
||||
late int workoutId;
|
||||
|
||||
//@JsonKey(required: true, name: 'training')
|
||||
WorkoutPlan workout;
|
||||
late WorkoutPlan workout;
|
||||
|
||||
Day({
|
||||
this.id,
|
||||
this.workoutId,
|
||||
this.description,
|
||||
this.daysOfWeek,
|
||||
this.sets,
|
||||
Day() {
|
||||
this.daysOfWeek = [];
|
||||
this.sets = [];
|
||||
}
|
||||
|
||||
Day.withData({
|
||||
required this.id,
|
||||
required this.workoutId,
|
||||
required this.description,
|
||||
List<int>? daysOfWeek,
|
||||
List<Set>? sets,
|
||||
}) {
|
||||
this.daysOfWeek = daysOfWeek ?? [];
|
||||
this.sets = sets ?? [];
|
||||
}
|
||||
|
||||
static const Map<int, String> weekdays = {
|
||||
@@ -45,7 +51,7 @@ class Day {
|
||||
};
|
||||
|
||||
String getDayName(int weekDay) {
|
||||
return weekdays[weekDay];
|
||||
return weekdays[weekDay]!;
|
||||
}
|
||||
|
||||
String get getDaysText {
|
||||
|
||||
@@ -8,18 +8,16 @@ part of 'day.dart';
|
||||
|
||||
Day _$DayFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'description', 'training']);
|
||||
return Day(
|
||||
id: json['id'] as int,
|
||||
description: json['description'] as String,
|
||||
daysOfWeek: (json['day'] as List)?.map((e) => e as int)?.toList() ?? [],
|
||||
sets: (json['sets'] as List)
|
||||
?.map((e) => e == null ? null : Set.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
)
|
||||
return Day()
|
||||
..id = json['id'] as int?
|
||||
..description = json['description'] as String
|
||||
..daysOfWeek =
|
||||
(json['day'] as List<dynamic>?)?.map((e) => e as int).toList() ?? []
|
||||
..sets = (json['sets'] as List<dynamic>)
|
||||
.map((e) => Set.fromJson(e as Map<String, dynamic>))
|
||||
.toList()
|
||||
..workoutId = json['training'] as int
|
||||
..workout = json['workout'] == null
|
||||
? null
|
||||
: WorkoutPlan.fromJson(json['workout'] as Map<String, dynamic>);
|
||||
..workout = WorkoutPlan.fromJson(json['workout'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$DayToJson(Day instance) => <String, dynamic>{
|
||||
|
||||
@@ -6,45 +6,47 @@ part 'log.g.dart';
|
||||
@JsonSerializable()
|
||||
class Log {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int exercise;
|
||||
late int exercise;
|
||||
|
||||
@JsonKey(required: true, name: 'workout')
|
||||
int workoutPlan;
|
||||
late int workoutPlan;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int reps;
|
||||
late int reps;
|
||||
|
||||
@JsonKey(required: false)
|
||||
double rir;
|
||||
late String rir;
|
||||
|
||||
@JsonKey(required: true, name: 'repetition_unit')
|
||||
int repetitionUnit;
|
||||
late int repetitionUnit;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum, toJson: toString)
|
||||
num weight;
|
||||
late num weight;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
int weightUnit;
|
||||
late int weightUnit;
|
||||
|
||||
@JsonKey(required: true, toJson: toDate)
|
||||
DateTime date;
|
||||
late DateTime date;
|
||||
|
||||
//@JsonKey(required: true)
|
||||
//String comment;
|
||||
|
||||
Log({
|
||||
Log();
|
||||
|
||||
Log.withData({
|
||||
this.id,
|
||||
this.exercise,
|
||||
this.workoutPlan,
|
||||
this.repetitionUnit,
|
||||
this.reps,
|
||||
this.rir,
|
||||
this.weight,
|
||||
this.weightUnit,
|
||||
this.date,
|
||||
required this.exercise,
|
||||
required this.workoutPlan,
|
||||
required this.repetitionUnit,
|
||||
required this.reps,
|
||||
required this.rir,
|
||||
required this.weight,
|
||||
required this.weightUnit,
|
||||
required this.date,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -17,17 +17,16 @@ Log _$LogFromJson(Map<String, dynamic> json) {
|
||||
'weight_unit',
|
||||
'date'
|
||||
]);
|
||||
return Log(
|
||||
id: json['id'] as int,
|
||||
exercise: json['exercise'] as int,
|
||||
workoutPlan: json['workout'] as int,
|
||||
repetitionUnit: json['repetition_unit'] as int,
|
||||
reps: json['reps'] as int,
|
||||
rir: (json['rir'] as num)?.toDouble(),
|
||||
weight: toNum(json['weight'] as String),
|
||||
weightUnit: json['weight_unit'] as int,
|
||||
date: json['date'] == null ? null : DateTime.parse(json['date'] as String),
|
||||
);
|
||||
return Log()
|
||||
..id = json['id'] as int?
|
||||
..exercise = json['exercise'] as int
|
||||
..workoutPlan = json['workout'] as int
|
||||
..reps = json['reps'] as int
|
||||
..rir = json['rir'] as String
|
||||
..repetitionUnit = json['repetition_unit'] as int
|
||||
..weight = toNum(json['weight'] as String?)
|
||||
..weightUnit = json['weight_unit'] as int
|
||||
..date = DateTime.parse(json['date'] as String);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$LogToJson(Log instance) => <String, dynamic>{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'repetition_unit.g.dart';
|
||||
@@ -12,8 +11,8 @@ class RepetitionUnit {
|
||||
final String name;
|
||||
|
||||
RepetitionUnit({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -9,34 +9,36 @@ const ImpressionMap = {1: 'bad', 2: 'neutral', 3: 'good'};
|
||||
@JsonSerializable()
|
||||
class WorkoutSession {
|
||||
@JsonKey(required: true)
|
||||
int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true, name: 'workout')
|
||||
int workoutId;
|
||||
late int workoutId;
|
||||
|
||||
@JsonKey(required: true, toJson: toDate)
|
||||
DateTime date;
|
||||
late DateTime date;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum, toJson: toString)
|
||||
num impression;
|
||||
late num impression;
|
||||
|
||||
@JsonKey(required: false, defaultValue: '')
|
||||
String notes;
|
||||
late String notes;
|
||||
|
||||
@JsonKey(required: true, name: 'time_start', toJson: timeToString, fromJson: stringToTime)
|
||||
TimeOfDay timeStart;
|
||||
late TimeOfDay timeStart;
|
||||
|
||||
@JsonKey(required: true, name: 'time_end', toJson: timeToString, fromJson: stringToTime)
|
||||
TimeOfDay timeEnd;
|
||||
late TimeOfDay timeEnd;
|
||||
|
||||
WorkoutSession({
|
||||
this.id,
|
||||
this.workoutId,
|
||||
this.date,
|
||||
this.impression,
|
||||
this.notes,
|
||||
this.timeStart,
|
||||
this.timeEnd,
|
||||
WorkoutSession();
|
||||
|
||||
WorkoutSession.withData({
|
||||
required this.id,
|
||||
required this.workoutId,
|
||||
required this.date,
|
||||
required this.impression,
|
||||
required this.notes,
|
||||
required this.timeStart,
|
||||
required this.timeEnd,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -15,15 +15,14 @@ WorkoutSession _$WorkoutSessionFromJson(Map<String, dynamic> json) {
|
||||
'time_start',
|
||||
'time_end'
|
||||
]);
|
||||
return WorkoutSession(
|
||||
id: json['id'] as int,
|
||||
workoutId: json['workout'] as int,
|
||||
date: json['date'] == null ? null : DateTime.parse(json['date'] as String),
|
||||
impression: toNum(json['impression'] as String),
|
||||
notes: json['notes'] as String ?? '',
|
||||
timeStart: stringToTime(json['time_start'] as String),
|
||||
timeEnd: stringToTime(json['time_end'] as String),
|
||||
);
|
||||
return WorkoutSession()
|
||||
..id = json['id'] as int?
|
||||
..workoutId = json['workout'] as int
|
||||
..date = DateTime.parse(json['date'] as String)
|
||||
..impression = toNum(json['impression'] as String?)
|
||||
..notes = json['notes'] as String? ?? ''
|
||||
..timeStart = stringToTime(json['time_start'] as String?)
|
||||
..timeEnd = stringToTime(json['time_end'] as String?);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WorkoutSessionToJson(WorkoutSession instance) =>
|
||||
|
||||
@@ -9,16 +9,16 @@ class Set {
|
||||
static const DEFAULT_NR_SETS = 4;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int sets;
|
||||
late int sets;
|
||||
|
||||
@JsonKey(required: false, name: 'exerciseday')
|
||||
int day;
|
||||
late int day;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int order;
|
||||
late int order;
|
||||
|
||||
//@JsonKey(required: true)
|
||||
List<Exercise> exercisesObj = [];
|
||||
@@ -33,20 +33,32 @@ class Set {
|
||||
@JsonKey(required: false)
|
||||
List<Setting> settingsComputed = [];
|
||||
|
||||
Set({
|
||||
Set() {
|
||||
this.sets = sets;
|
||||
this.exercisesObj = [];
|
||||
this.exercisesIds = exercisesObj.map((e) => e.id).toList();
|
||||
this.settings;
|
||||
this.settingsComputed;
|
||||
}
|
||||
|
||||
Set.withData({
|
||||
this.id,
|
||||
sets,
|
||||
this.day,
|
||||
this.order,
|
||||
day,
|
||||
order,
|
||||
exercises,
|
||||
settings,
|
||||
settingsComputed,
|
||||
}) {
|
||||
this.sets = sets ?? DEFAULT_NR_SETS;
|
||||
this.order = order ?? 1;
|
||||
this.exercisesObj = exercises ?? [];
|
||||
this.exercisesIds = exercisesObj.map((e) => e.id).toList();
|
||||
this.settings = settings ?? [];
|
||||
this.settingsComputed = settingsComputed ?? [];
|
||||
if (day != null) {
|
||||
this.day = day;
|
||||
}
|
||||
}
|
||||
|
||||
void addExercise(Exercise exercise) {
|
||||
|
||||
@@ -8,20 +8,22 @@ part of 'set.dart';
|
||||
|
||||
Set _$SetFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'sets', 'order']);
|
||||
return Set(
|
||||
id: json['id'] as int,
|
||||
sets: json['sets'],
|
||||
day: json['exerciseday'] as int,
|
||||
order: json['order'] as int,
|
||||
settings: json['settings'],
|
||||
settingsComputed: json['settingsComputed'],
|
||||
)
|
||||
..exercisesObj = (json['exercisesObj'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Exercise.fromJson(e as Map<String, dynamic>))
|
||||
?.toList()
|
||||
return Set()
|
||||
..id = json['id'] as int?
|
||||
..sets = json['sets'] as int
|
||||
..day = json['exerciseday'] as int
|
||||
..order = json['order'] as int
|
||||
..exercisesObj = (json['exercisesObj'] as List<dynamic>)
|
||||
.map((e) => Exercise.fromJson(e as Map<String, dynamic>))
|
||||
.toList()
|
||||
..exercisesIds =
|
||||
(json['exercises'] as List)?.map((e) => e as int)?.toList();
|
||||
(json['exercises'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..settings = (json['settings'] as List<dynamic>)
|
||||
.map((e) => Setting.fromJson(e as Map<String, dynamic>))
|
||||
.toList()
|
||||
..settingsComputed = (json['settingsComputed'] as List<dynamic>)
|
||||
.map((e) => Setting.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$SetToJson(Set instance) => <String, dynamic>{
|
||||
|
||||
@@ -7,53 +7,62 @@ part 'setting.g.dart';
|
||||
@JsonSerializable()
|
||||
class Setting {
|
||||
@JsonKey(required: true)
|
||||
int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true, name: 'set')
|
||||
int setId;
|
||||
late int setId;
|
||||
|
||||
@JsonKey(required: false)
|
||||
Exercise exerciseObj;
|
||||
@JsonKey(ignore: true)
|
||||
late Exercise exerciseObj;
|
||||
|
||||
@JsonKey(required: true, name: 'exercise')
|
||||
int exerciseId;
|
||||
late int exerciseId;
|
||||
|
||||
@JsonKey(required: true, name: 'repetition_unit')
|
||||
int repetitionUnit;
|
||||
late int repetitionUnitId;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
late int repetitionUnitObj;
|
||||
|
||||
@JsonKey(required: true)
|
||||
int reps;
|
||||
late int reps;
|
||||
|
||||
@JsonKey(required: true, fromJson: toNum, toJson: toString)
|
||||
num weight;
|
||||
late num weight;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
int weightUnit;
|
||||
late int weightUnitId;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
late int weightUnitObj;
|
||||
|
||||
@JsonKey(required: true, defaultValue: '')
|
||||
String comment = '';
|
||||
late String comment = '';
|
||||
|
||||
@JsonKey(required: false, defaultValue: '')
|
||||
String rir = '';
|
||||
late String rir = '';
|
||||
|
||||
// Generated by Server
|
||||
@JsonKey(required: false)
|
||||
String repsText;
|
||||
late String repsText;
|
||||
|
||||
Setting({
|
||||
Setting();
|
||||
|
||||
Setting.withData({
|
||||
this.id,
|
||||
this.setId,
|
||||
this.exerciseObj,
|
||||
this.repetitionUnit,
|
||||
this.reps,
|
||||
this.weight,
|
||||
this.weightUnit,
|
||||
this.comment,
|
||||
this.rir,
|
||||
this.repsText,
|
||||
required this.setId,
|
||||
Exercise? exerciseObj,
|
||||
required this.repetitionUnitId,
|
||||
required this.reps,
|
||||
required this.weight,
|
||||
required this.weightUnitId,
|
||||
required this.comment,
|
||||
this.rir = '',
|
||||
required this.repsText,
|
||||
}) {
|
||||
if (exerciseObj != null) {
|
||||
this.exerciseId = exerciseObj.id;
|
||||
this.exerciseObj = exerciseObj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,31 +17,27 @@ Setting _$SettingFromJson(Map<String, dynamic> json) {
|
||||
'weight_unit',
|
||||
'comment'
|
||||
]);
|
||||
return Setting(
|
||||
id: json['id'] as int,
|
||||
setId: json['set'] as int,
|
||||
exerciseObj: json['exerciseObj'] == null
|
||||
? null
|
||||
: Exercise.fromJson(json['exerciseObj'] as Map<String, dynamic>),
|
||||
repetitionUnit: json['repetition_unit'] as int,
|
||||
reps: json['reps'] as int,
|
||||
weight: toNum(json['weight'] as String),
|
||||
weightUnit: json['weight_unit'] as int,
|
||||
comment: json['comment'] as String ?? '',
|
||||
rir: json['rir'] as String ?? '',
|
||||
repsText: json['repsText'] as String,
|
||||
)..exerciseId = json['exercise'] as int;
|
||||
return Setting()
|
||||
..id = json['id'] as int?
|
||||
..setId = json['set'] as int
|
||||
..exerciseId = json['exercise'] as int
|
||||
..repetitionUnitId = json['repetition_unit'] as int
|
||||
..reps = json['reps'] as int
|
||||
..weight = toNum(json['weight'] as String?)
|
||||
..weightUnitId = json['weight_unit'] as int
|
||||
..comment = json['comment'] as String? ?? ''
|
||||
..rir = json['rir'] as String? ?? ''
|
||||
..repsText = json['repsText'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$SettingToJson(Setting instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'set': instance.setId,
|
||||
'exerciseObj': instance.exerciseObj,
|
||||
'exercise': instance.exerciseId,
|
||||
'repetition_unit': instance.repetitionUnit,
|
||||
'repetition_unit': instance.repetitionUnitId,
|
||||
'reps': instance.reps,
|
||||
'weight': toString(instance.weight),
|
||||
'weight_unit': instance.weightUnit,
|
||||
'weight_unit': instance.weightUnitId,
|
||||
'comment': instance.comment,
|
||||
'rir': instance.rir,
|
||||
'repsText': instance.repsText,
|
||||
|
||||
@@ -11,8 +11,8 @@ class WeightUnit {
|
||||
final String name;
|
||||
|
||||
WeightUnit({
|
||||
this.id,
|
||||
this.name,
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -26,27 +26,31 @@ part 'workout_plan.g.dart';
|
||||
@JsonSerializable()
|
||||
class WorkoutPlan {
|
||||
@JsonKey(required: true)
|
||||
final int id;
|
||||
int? id;
|
||||
|
||||
@JsonKey(required: true, name: 'creation_date')
|
||||
DateTime creationDate;
|
||||
late DateTime creationDate;
|
||||
|
||||
@JsonKey(required: true, name: 'comment')
|
||||
String description;
|
||||
late String description;
|
||||
|
||||
@JsonKey(required: false, defaultValue: [], name: 'days')
|
||||
List<Day> days = [];
|
||||
late List<Day> days = [];
|
||||
|
||||
@JsonKey(ignore: true, defaultValue: [])
|
||||
List<Log> logs = [];
|
||||
late List<Log> logs = [];
|
||||
|
||||
WorkoutPlan({
|
||||
WorkoutPlan();
|
||||
|
||||
WorkoutPlan.withData({
|
||||
this.id,
|
||||
this.creationDate,
|
||||
this.description,
|
||||
this.days,
|
||||
required this.creationDate,
|
||||
required this.description,
|
||||
days,
|
||||
logs,
|
||||
}) {
|
||||
this.days = days ?? [];
|
||||
this.logs = logs ?? [];
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -8,24 +8,20 @@ part of 'workout_plan.dart';
|
||||
|
||||
WorkoutPlan _$WorkoutPlanFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(json, requiredKeys: const ['id', 'creation_date', 'comment']);
|
||||
return WorkoutPlan(
|
||||
id: json['id'] as int,
|
||||
creationDate: json['creation_date'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creation_date'] as String),
|
||||
description: json['comment'] as String,
|
||||
days: (json['days'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : Day.fromJson(e as Map<String, dynamic>))
|
||||
?.toList() ??
|
||||
[],
|
||||
);
|
||||
return WorkoutPlan()
|
||||
..id = json['id'] as int?
|
||||
..creationDate = DateTime.parse(json['creation_date'] as String)
|
||||
..description = json['comment'] as String
|
||||
..days = (json['days'] as List<dynamic>?)
|
||||
?.map((e) => Day.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WorkoutPlanToJson(WorkoutPlan instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'creation_date': instance.creationDate?.toIso8601String(),
|
||||
'creation_date': instance.creationDate.toIso8601String(),
|
||||
'comment': instance.description,
|
||||
'days': instance.days,
|
||||
};
|
||||
|
||||
@@ -34,10 +34,10 @@ import 'package:wger/models/http_exception.dart';
|
||||
import 'helpers.dart';
|
||||
|
||||
class Auth with ChangeNotifier {
|
||||
String token;
|
||||
String serverUrl;
|
||||
String serverVersion;
|
||||
PackageInfo applicationVersion;
|
||||
String? token;
|
||||
String? serverUrl;
|
||||
String? serverVersion;
|
||||
PackageInfo? applicationVersion;
|
||||
|
||||
/// flag to indicate that the application has successfully loaded all initial data
|
||||
bool dataInit = false;
|
||||
@@ -50,7 +50,7 @@ class Auth with ChangeNotifier {
|
||||
return token != null;
|
||||
}
|
||||
|
||||
String get token2 {
|
||||
String? get token2 {
|
||||
// if (_expiryDate != null &&
|
||||
// _expiryDate.isAfter(DateTime.now()) &&
|
||||
// _token != null) {
|
||||
@@ -65,7 +65,7 @@ class Auth with ChangeNotifier {
|
||||
|
||||
/// Server application version
|
||||
Future<void> setServerVersion() async {
|
||||
final response = await http.get(makeUri(serverUrl, 'version'));
|
||||
final response = await http.get(makeUri(serverUrl!, 'version'));
|
||||
final responseData = json.decode(response.body);
|
||||
serverVersion = responseData;
|
||||
}
|
||||
@@ -77,7 +77,12 @@ class Auth with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Registers a new user
|
||||
Future<void> register({String username, String password, String email, String serverUrl}) async {
|
||||
Future<void> register({
|
||||
required String username,
|
||||
required String password,
|
||||
required String email,
|
||||
required String serverUrl,
|
||||
}) async {
|
||||
final uri = Uri.parse(serverUrl + '/api/v2/register/');
|
||||
Map<String, String> metadata = Map();
|
||||
|
||||
@@ -134,7 +139,7 @@ class Auth with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Log user in
|
||||
this.serverUrl = serverUrl ?? '';
|
||||
this.serverUrl = serverUrl;
|
||||
token = responseData['token'];
|
||||
|
||||
// _userId = responseData['localId'];
|
||||
@@ -173,8 +178,8 @@ class Auth with ChangeNotifier {
|
||||
return DEFAULT_SERVER;
|
||||
}
|
||||
|
||||
final userData = json.decode(prefs.getString('lastServer')) as Map<String, Object>;
|
||||
return userData['serverUrl'];
|
||||
final userData = json.decode(prefs.getString('lastServer')!);
|
||||
return userData['serverUrl'] as String;
|
||||
}
|
||||
|
||||
Future<bool> tryAutoLogin() async {
|
||||
@@ -183,16 +188,15 @@ class Auth with ChangeNotifier {
|
||||
log('autologin failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
final extractedUserData = json.decode(prefs.getString('userData')) as Map<String, Object>;
|
||||
final extractedUserData = json.decode(prefs.getString('userData')!);
|
||||
// final expiryDate = DateTime.parse(extractedUserData['expiryDate']);
|
||||
|
||||
// if (expiryDate.isBefore(DateTime.now())) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
token = extractedUserData['token'];
|
||||
serverUrl = extractedUserData['serverUrl'];
|
||||
token = extractedUserData['token']!;
|
||||
serverUrl = extractedUserData['serverUrl']!;
|
||||
// _userId = extractedUserData['userId'];
|
||||
// _expiryDate = expiryDate;
|
||||
|
||||
|
||||
@@ -30,20 +30,20 @@ import 'package:wger/providers/helpers.dart';
|
||||
/// Provides a couple of comfort functions so we avoid a bit of boilerplate.
|
||||
class WgerBaseProvider {
|
||||
Auth auth;
|
||||
http.Client client;
|
||||
late http.Client client;
|
||||
|
||||
WgerBaseProvider(auth, [client]) {
|
||||
WgerBaseProvider(this.auth, [http.Client? client]) {
|
||||
this.auth = auth;
|
||||
this.client = client ?? http.Client();
|
||||
}
|
||||
|
||||
/// Helper function to make a URL.
|
||||
makeUrl(String path, {int id, String objectMethod, Map<String, dynamic> query}) {
|
||||
return makeUri(auth.serverUrl, path, id, objectMethod, query);
|
||||
makeUrl(String path, {int? id, String? objectMethod, Map<String, dynamic>? query}) {
|
||||
return makeUri(auth.serverUrl!, path, id, objectMethod, query);
|
||||
}
|
||||
|
||||
/// Fetch and retrieve the overview list of objects, returns the JSON parsed response
|
||||
Future<Map<String, dynamic>> fetch([Uri uri]) async {
|
||||
Future<Map<String, dynamic>> fetch(Uri uri) async {
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
uri,
|
||||
|
||||
@@ -27,7 +27,7 @@ class BodyWeight extends WgerBaseProvider with ChangeNotifier {
|
||||
static const bodyWeightUrl = 'weightentry';
|
||||
|
||||
List<WeightEntry> _entries = [];
|
||||
BodyWeight(Auth auth, List<WeightEntry> entries, [http.Client client])
|
||||
BodyWeight(Auth auth, List<WeightEntry> entries, [http.Client? client])
|
||||
: this._entries = entries,
|
||||
super(auth, client);
|
||||
|
||||
@@ -86,6 +86,5 @@ class BodyWeight extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
existingWeightEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Exercises extends WgerBaseProvider with ChangeNotifier {
|
||||
List<Muscle> _muscles = [];
|
||||
List<Equipment> _equipment = [];
|
||||
|
||||
Exercises(Auth auth, List<Exercise> entries, [http.Client client])
|
||||
Exercises(Auth auth, List<Exercise> entries, [http.Client? client])
|
||||
: this._exercises = entries,
|
||||
super(auth, client);
|
||||
|
||||
@@ -57,10 +57,7 @@ class Exercises extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Exercise findById(int id) {
|
||||
return _exercises.firstWhere((exercise) => exercise.id == id, orElse: () {
|
||||
log('Could not find exercise with ID $id');
|
||||
return null;
|
||||
});
|
||||
return _exercises.firstWhere((exercise) => exercise.id == id);
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetCategories() async {
|
||||
@@ -103,7 +100,7 @@ class Exercises extends WgerBaseProvider with ChangeNotifier {
|
||||
// Load exercises from cache, if available
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.containsKey('exerciseData')) {
|
||||
final exerciseData = json.decode(prefs.getString('exerciseData'));
|
||||
final exerciseData = json.decode(prefs.getString('exerciseData')!);
|
||||
if (DateTime.parse(exerciseData['expiresIn']).isAfter(DateTime.now())) {
|
||||
exerciseData['exercises'].forEach((e) => _exercises.add(Exercise.fromJson(e)));
|
||||
exerciseData['equipment'].forEach((e) => _equipment.add(Equipment.fromJson(e)));
|
||||
|
||||
@@ -17,7 +17,13 @@
|
||||
*/
|
||||
|
||||
/// Helper function to make a URL.
|
||||
makeUri(String serverUrl, String path, [int id, String objectMethod, Map<String, dynamic> query]) {
|
||||
makeUri(
|
||||
String serverUrl,
|
||||
String path, [
|
||||
int? id,
|
||||
String? objectMethod,
|
||||
Map<String, dynamic>? query,
|
||||
]) {
|
||||
Uri uriServer = Uri.parse(serverUrl);
|
||||
|
||||
var pathList = ['api', 'v2', path];
|
||||
|
||||
@@ -46,7 +46,7 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
List<NutritionalPlan> _plans = [];
|
||||
List<Ingredient> _ingredients = [];
|
||||
|
||||
Nutrition(Auth auth, List<NutritionalPlan> entries, [http.Client client])
|
||||
Nutrition(Auth auth, List<NutritionalPlan> entries, [http.Client? client])
|
||||
: this._plans = entries,
|
||||
super(auth, client);
|
||||
|
||||
@@ -56,7 +56,7 @@ class Nutrition 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 {
|
||||
NutritionalPlan? get currentPlan {
|
||||
if (_plans.length > 0) {
|
||||
return _plans.first;
|
||||
}
|
||||
@@ -66,9 +66,9 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
return _plans.firstWhere((plan) => plan.id == id);
|
||||
}
|
||||
|
||||
Meal findMealById(int id) {
|
||||
Meal? findMealById(int id) {
|
||||
for (var plan in _plans) {
|
||||
var meal = plan.meals.firstWhere((plan) => plan.id == id, orElse: () {});
|
||||
var meal = plan.meals.firstWhere((plan) => plan.id == id);
|
||||
if (meal != null) {
|
||||
return meal;
|
||||
}
|
||||
@@ -81,7 +81,13 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
await fetch(makeUrl(_nutritionalPlansInfoPath, query: {'ordering': '-creation_date'}));
|
||||
final List<NutritionalPlan> loadedPlans = [];
|
||||
for (final entry in data['results']) {
|
||||
loadedPlans.add(NutritionalPlan.fromJson(entry));
|
||||
try {
|
||||
//log(entry.toString());
|
||||
loadedPlans.add(NutritionalPlan.fromJson(entry));
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
//log();
|
||||
}
|
||||
}
|
||||
|
||||
_plans = loadedPlans;
|
||||
@@ -124,7 +130,7 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
existingPlan = null;
|
||||
//existingPlan = null;
|
||||
}
|
||||
|
||||
/// Adds a meal to a plan
|
||||
@@ -158,22 +164,21 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealPath, meal.id);
|
||||
final response = await deleteRequest(_mealPath, meal.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
plan.meals.insert(mealIndex, existingMeal);
|
||||
notifyListeners();
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
existingMeal = null;
|
||||
}
|
||||
|
||||
/// Adds a meal item to a meal
|
||||
Future<MealItem> addMealItem(MealItem mealItem, int mealId) async {
|
||||
var meal = findMealById(mealId);
|
||||
var meal = findMealById(mealId)!;
|
||||
final data = await post(mealItem.toJson(), makeUrl(_mealItemPath));
|
||||
|
||||
mealItem = MealItem.fromJson(data);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId!);
|
||||
meal.mealItems.add(mealItem);
|
||||
notifyListeners();
|
||||
|
||||
@@ -183,27 +188,26 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Deletes a meal
|
||||
Future<void> deleteMealItem(MealItem mealItem) async {
|
||||
// Get the meal
|
||||
var meal = findMealById(mealItem.meal);
|
||||
var meal = findMealById(mealItem.meal)!;
|
||||
final mealItemIndex = meal.mealItems.indexWhere((e) => e.id == mealItem.id);
|
||||
var existingMealItem = meal.mealItems[mealItemIndex];
|
||||
meal.mealItems.removeAt(mealItemIndex);
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealItemPath, mealItem.id);
|
||||
final response = await deleteRequest(_mealItemPath, mealItem.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
meal.mealItems.insert(mealItemIndex, existingMealItem);
|
||||
notifyListeners();
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
existingMealItem = null;
|
||||
}
|
||||
|
||||
/// Fetch and return an ingredient
|
||||
///
|
||||
/// If the ingredient is not known locally, it is fetched from the server
|
||||
Future<Ingredient> fetchIngredient(int ingredientId) async {
|
||||
var ingredient = _ingredients.firstWhere((e) => e.id == ingredientId, orElse: () => null);
|
||||
var ingredient = _ingredients.firstWhere((e) => e.id == ingredientId);
|
||||
if (ingredient != null) {
|
||||
return ingredient;
|
||||
}
|
||||
@@ -214,7 +218,7 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
_ingredients.add(ingredient);
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final ingredientData = json.decode(prefs.getString('ingredientData'));
|
||||
final ingredientData = json.decode(prefs.getString('ingredientData')!);
|
||||
ingredientData['ingredients'].add(ingredient.toJson());
|
||||
prefs.setString('ingredientData', json.encode(ingredientData));
|
||||
log("Saved ingredient '${ingredient.name}' to cache.");
|
||||
@@ -227,7 +231,7 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
// Load exercises from cache, if available
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.containsKey('ingredientData')) {
|
||||
final ingredientData = json.decode(prefs.getString('ingredientData'));
|
||||
final ingredientData = json.decode(prefs.getString('ingredientData')!);
|
||||
if (DateTime.parse(ingredientData['expiresIn']).isAfter(DateTime.now())) {
|
||||
ingredientData['ingredients'].forEach((e) => _ingredients.add(Ingredient.fromJson(e)));
|
||||
log("Read ${ingredientData['ingredients'].length} ingredients from cache. Valid till ${ingredientData['expiresIn']}");
|
||||
@@ -247,6 +251,10 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Searches for an ingredient
|
||||
Future<List> searchIngredient(String name) async {
|
||||
if (name.length <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
makeUrl(_ingredientSearchPath, query: {'term': name}),
|
||||
@@ -269,10 +277,10 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
Future<void> logMealToDiary(Meal meal) async {
|
||||
//var meal = findMealById(mealId);
|
||||
for (var item in meal.mealItems) {
|
||||
Log log = Log.fromMealItem(item);
|
||||
final plan = findById(meal.plan);
|
||||
log.planId = plan.id;
|
||||
log.datetime = DateTime.now();
|
||||
Log log = Log.fromMealItem(item, plan.id!);
|
||||
//log.planId = plan.id;
|
||||
//log.datetime = DateTime.now();
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
log.id = data['id'];
|
||||
|
||||
@@ -22,6 +22,7 @@ import 'dart:developer';
|
||||
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/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/exercises/image.dart';
|
||||
import 'package:wger/models/http_exception.dart';
|
||||
@@ -48,12 +49,12 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
static const _weightUnitUrlPath = 'setting-weightunit';
|
||||
static const _repetitionUnitUrlPath = 'setting-repetitionunit';
|
||||
|
||||
WorkoutPlan _currentPlan;
|
||||
WorkoutPlan? _currentPlan;
|
||||
List<WorkoutPlan> _workoutPlans = [];
|
||||
List<WeightUnit> _weightUnits = [];
|
||||
List<RepetitionUnit> _repetitionUnit = [];
|
||||
|
||||
WorkoutPlans(Auth auth, List<WorkoutPlan> entries, [http.Client client])
|
||||
WorkoutPlans(Auth auth, List<WorkoutPlan> entries, [http.Client? client])
|
||||
: this._workoutPlans = entries,
|
||||
super(auth, client);
|
||||
|
||||
@@ -67,7 +68,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (kg)
|
||||
WeightUnit get defaultWeightUnit {
|
||||
return _weightUnits.firstWhere((element) => element.id == 1);
|
||||
return _weightUnits.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
|
||||
}
|
||||
|
||||
List<RepetitionUnit> get repetitionUnits {
|
||||
@@ -76,7 +77,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (reps)
|
||||
RepetitionUnit get defaultRepetitionUnit {
|
||||
return _repetitionUnit.firstWhere((element) => element.id == 1);
|
||||
return _repetitionUnit.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT);
|
||||
}
|
||||
|
||||
WorkoutPlan findById(int id) {
|
||||
@@ -93,7 +94,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Returns the currently "active" workout plan
|
||||
WorkoutPlan get currentPlan {
|
||||
WorkoutPlan? get currentPlan {
|
||||
return _currentPlan;
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ class WorkoutPlans 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 {
|
||||
WorkoutPlan? get activePlan {
|
||||
if (_workoutPlans.length > 0) {
|
||||
return _workoutPlans.first;
|
||||
}
|
||||
@@ -127,7 +128,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> setAllFullWorkouts() async {
|
||||
for (var plan in _workoutPlans) {
|
||||
setFullWorkout(plan.id);
|
||||
setFullWorkout(plan.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,97 +139,102 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
objectMethod: 'canonical_representation',
|
||||
));
|
||||
|
||||
try {
|
||||
WorkoutPlan workout = _workoutPlans.firstWhere((element) => element.id == workoutId);
|
||||
//try {
|
||||
WorkoutPlan workout = _workoutPlans.firstWhere((element) => element.id == workoutId);
|
||||
|
||||
List<Day> days = [];
|
||||
for (final entry in data['day_list']) {
|
||||
List<Set> sets = [];
|
||||
List<Setting> settingsComputed = [];
|
||||
List<Day> days = [];
|
||||
for (final entry in data['day_list']) {
|
||||
List<Set> sets = [];
|
||||
List<Setting> settingsComputed = [];
|
||||
|
||||
for (final set in entry['set_list']) {
|
||||
List<Setting> settings = [];
|
||||
List<Exercise> exercises = [];
|
||||
for (final set in entry['set_list']) {
|
||||
List<Setting> settings = [];
|
||||
List<Exercise> exercises = [];
|
||||
|
||||
for (final exerciseData in set['exercise_list']) {
|
||||
List<ExerciseImage> images = [];
|
||||
for (final exerciseData in set['exercise_list']) {
|
||||
List<ExerciseImage> images = [];
|
||||
|
||||
for (final image in exerciseData['image_list']) {
|
||||
images.add(
|
||||
ExerciseImage(
|
||||
url: auth.serverUrl + image["image"],
|
||||
isMain: image['is_main'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Exercise exercise = Exercise(
|
||||
id: exerciseData['obj']['id'],
|
||||
uuid: exerciseData['obj']['uuid'],
|
||||
creationDate: DateTime.parse(exerciseData['obj']['creation_date']),
|
||||
name: exerciseData['obj']['name'],
|
||||
description: exerciseData['obj']['description'],
|
||||
images: images,
|
||||
for (final image in exerciseData['image_list']) {
|
||||
images.add(
|
||||
ExerciseImage(
|
||||
url: auth.serverUrl! + image["image"],
|
||||
isMain: image['is_main'],
|
||||
),
|
||||
);
|
||||
exercises.add(exercise);
|
||||
|
||||
// Settings
|
||||
if (exerciseData['setting_obj_list'].length > 0) {
|
||||
settings.add(
|
||||
Setting(
|
||||
id: exerciseData['setting_obj_list'][0]['id'],
|
||||
setId: exerciseData['setting_obj_list'][0]['set'],
|
||||
comment: exerciseData['setting_obj_list'][0]['comment'],
|
||||
reps: exerciseData['setting_obj_list'][0]['reps'],
|
||||
//weight: setting['setting_obj_list'][0]['weight'] == null
|
||||
// ? ''
|
||||
// : setting['setting_obj_list'][0]['weight'],
|
||||
repsText: exerciseData['setting_text'],
|
||||
exerciseObj: exercise,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Computed settings
|
||||
for (var setting in set['settings_computed']) {
|
||||
settingsComputed.add(Setting.fromJson(setting));
|
||||
}
|
||||
//TODO: read exercise data from cache from Exercises provider
|
||||
Exercise exercise = Exercise(
|
||||
id: exerciseData['obj']['id'],
|
||||
uuid: exerciseData['obj']['uuid'],
|
||||
creationDate: DateTime.parse(exerciseData['obj']['creation_date']),
|
||||
name: exerciseData['obj']['name'],
|
||||
description: exerciseData['obj']['description'],
|
||||
categoryId: exerciseData['obj']['category'],
|
||||
images: images,
|
||||
);
|
||||
exercises.add(exercise);
|
||||
|
||||
// Sets
|
||||
sets.add(Set(
|
||||
id: set['obj']['id'],
|
||||
sets: set['obj']['sets'],
|
||||
order: set['obj']['order'],
|
||||
settings: settings,
|
||||
settingsComputed: settingsComputed,
|
||||
exercises: exercises,
|
||||
));
|
||||
// Settings
|
||||
if (exerciseData['setting_obj_list'].length > 0) {
|
||||
settings.add(
|
||||
Setting.withData(
|
||||
id: exerciseData['setting_obj_list'][0]['id'],
|
||||
setId: exerciseData['setting_obj_list'][0]['set'],
|
||||
comment: exerciseData['setting_obj_list'][0]['comment'],
|
||||
reps: exerciseData['setting_obj_list'][0]['reps'],
|
||||
weight: 10,
|
||||
repetitionUnitId: DEFAULT_REPETITION_UNIT,
|
||||
weightUnitId: DEFAULT_WEIGHT_UNIT,
|
||||
//weight: setting['setting_obj_list'][0]['weight'] == null
|
||||
// ? ''
|
||||
// : setting['setting_obj_list'][0]['weight'],
|
||||
repsText: exerciseData['setting_text'],
|
||||
exerciseObj: exercise,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Days
|
||||
days.add(Day(
|
||||
id: entry['obj']['id'],
|
||||
workoutId: workoutId,
|
||||
description: entry['obj']['description'],
|
||||
sets: sets,
|
||||
daysOfWeek: [1, 3]
|
||||
//daysOfWeek: entry['obj']['day'],
|
||||
));
|
||||
}
|
||||
workout.days = days;
|
||||
// Computed settings
|
||||
for (var setting in set['settings_computed']) {
|
||||
settingsComputed.add(Setting.fromJson(setting));
|
||||
}
|
||||
|
||||
// Logs
|
||||
final logData = await fetch(makeUrl(_logsUrlPath, query: {'workout': workoutId.toString()}));
|
||||
for (final entry in logData['results']) {
|
||||
workout.logs.add(Log.fromJson(entry));
|
||||
// Sets
|
||||
sets.add(Set.withData(
|
||||
id: set['obj']['id'],
|
||||
sets: set['obj']['sets'],
|
||||
order: set['obj']['order'],
|
||||
settings: settings,
|
||||
settingsComputed: settingsComputed,
|
||||
exercises: exercises,
|
||||
));
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
return workout;
|
||||
} catch (error) {
|
||||
throw (error);
|
||||
// Days
|
||||
days.add(Day.withData(
|
||||
id: entry['obj']['id'],
|
||||
workoutId: workoutId,
|
||||
description: entry['obj']['description'],
|
||||
sets: sets,
|
||||
daysOfWeek: [1, 3]
|
||||
//daysOfWeek: entry['obj']['day'],
|
||||
));
|
||||
}
|
||||
workout.days = days;
|
||||
|
||||
// Logs
|
||||
final logData = await fetch(makeUrl(_logsUrlPath, query: {'workout': workoutId.toString()}));
|
||||
for (final entry in logData['results']) {
|
||||
workout.logs.add(Log.fromJson(entry));
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
return workout;
|
||||
//} catch (error) {
|
||||
// throw (error);
|
||||
//}
|
||||
}
|
||||
|
||||
Future<WorkoutPlan> postWorkout(WorkoutPlan workout) async {
|
||||
@@ -242,7 +248,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
Future<WorkoutPlan> patchWorkout(WorkoutPlan workout) async {
|
||||
final data = await patch(workout.toJson(), makeUrl(_workoutPlansUrlPath, id: workout.id));
|
||||
final plan = WorkoutPlan.fromJson(data);
|
||||
_workoutPlans[findIndexById(plan.id)] = plan;
|
||||
_workoutPlans[findIndexById(plan.id!)] = plan;
|
||||
notifyListeners();
|
||||
return plan;
|
||||
}
|
||||
@@ -260,10 +266,9 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
existingWorkout = null;
|
||||
}
|
||||
|
||||
Future<dynamic> fetchLogData(WorkoutPlan workout, Exercise exercise) async {
|
||||
Future<Map<String, dynamic>> fetchLogData(WorkoutPlan workout, Exercise exercise) async {
|
||||
final data = await fetch(
|
||||
makeUrl(
|
||||
_workoutPlansUrlPath,
|
||||
@@ -305,7 +310,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
// Load units from cache, if available
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.containsKey('workoutUnits')) {
|
||||
final workoutData = json.decode(prefs.getString('workoutUnits'));
|
||||
final workoutData = json.decode(prefs.getString('workoutUnits')!);
|
||||
if (DateTime.parse(workoutData['expiresIn']).isAfter(DateTime.now())) {
|
||||
workoutData['repetitionUnits'].forEach(
|
||||
(e) => _repetitionUnit.add(RepetitionUnit.fromJson(e)),
|
||||
@@ -340,7 +345,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
/*
|
||||
* Saves a new day instance to the DB and adds it to the given workout
|
||||
*/
|
||||
day.workoutId = workout.id;
|
||||
day.workoutId = workout.id!;
|
||||
final data = await post(day.toJson(), makeUrl(_daysUrlPath));
|
||||
day = Day.fromJson(data);
|
||||
day.sets = [];
|
||||
@@ -350,7 +355,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> deleteDay(Day day) async {
|
||||
await deleteRequest(_daysUrlPath, day.id);
|
||||
await deleteRequest(_daysUrlPath, day.id!);
|
||||
for (var workout in _workoutPlans) {
|
||||
workout.days.removeWhere((element) => element.id == day.id);
|
||||
}
|
||||
@@ -368,7 +373,7 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> deleteSet(Set workoutSet) async {
|
||||
await deleteRequest(_setsUrlPath, workoutSet.id);
|
||||
await deleteRequest(_setsUrlPath, workoutSet.id!);
|
||||
|
||||
for (var workout in _workoutPlans) {
|
||||
for (var day in workout.days) {
|
||||
|
||||
@@ -84,9 +84,7 @@ class AuthScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
class AuthCard extends StatefulWidget {
|
||||
const AuthCard({
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
const AuthCard();
|
||||
|
||||
@override
|
||||
_AuthCardState createState() => _AuthCardState();
|
||||
@@ -119,11 +117,11 @@ class _AuthCardState extends State<AuthCard> {
|
||||
}
|
||||
|
||||
void _submit(BuildContext context) async {
|
||||
if (!_formKey.currentState.validate()) {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
// Invalid!
|
||||
return;
|
||||
}
|
||||
_formKey.currentState.save();
|
||||
_formKey.currentState!.save();
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -131,18 +129,18 @@ class _AuthCardState extends State<AuthCard> {
|
||||
// Login existing user
|
||||
if (_authMode == AuthMode.Login) {
|
||||
await Provider.of<Auth>(context, listen: false).login(
|
||||
_authData['username'],
|
||||
_authData['password'],
|
||||
_authData['serverUrl'],
|
||||
_authData['username']!,
|
||||
_authData['password']!,
|
||||
_authData['serverUrl']!,
|
||||
);
|
||||
|
||||
// Register new user
|
||||
} else {
|
||||
await Provider.of<Auth>(context, listen: false).register(
|
||||
username: _authData['username'],
|
||||
password: _authData['password'],
|
||||
email: _authData['email'],
|
||||
serverUrl: _authData['serverUrl'],
|
||||
username: _authData['username']!,
|
||||
password: _authData['password']!,
|
||||
email: _authData['email']!,
|
||||
serverUrl: _authData['serverUrl']!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -190,25 +188,25 @@ class _AuthCardState extends State<AuthCard> {
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
key: Key('inputUsername'),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).username),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.username),
|
||||
autofillHints: [AutofillHints.username],
|
||||
controller: _usernameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return AppLocalizations.of(context).invalidUsername;
|
||||
if (value!.isEmpty) {
|
||||
return AppLocalizations.of(context)!.invalidUsername;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_authData['username'] = value;
|
||||
_authData['username'] = value!;
|
||||
},
|
||||
),
|
||||
if (_authMode == AuthMode.Signup)
|
||||
TextFormField(
|
||||
key: Key('inputEmail'),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).email),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.email),
|
||||
autofillHints: [AutofillHints.email],
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
@@ -216,44 +214,44 @@ class _AuthCardState extends State<AuthCard> {
|
||||
|
||||
// Email is not required
|
||||
validator: (value) {
|
||||
if (value.isNotEmpty && !value.contains('@')) {
|
||||
return AppLocalizations.of(context).invalidEmail;
|
||||
if (value!.isNotEmpty && !value.contains('@')) {
|
||||
return AppLocalizations.of(context)!.invalidEmail;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_authData['email'] = value;
|
||||
_authData['email'] = value!;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
key: Key('inputPassword'),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).password),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.password),
|
||||
autofillHints: [AutofillHints.password],
|
||||
obscureText: true,
|
||||
controller: _passwordController,
|
||||
textInputAction: TextInputAction.next,
|
||||
validator: (value) {
|
||||
if (value.isEmpty || value.length < 8) {
|
||||
return AppLocalizations.of(context).passwordTooShort;
|
||||
if (value!.isEmpty || value.length < 8) {
|
||||
return AppLocalizations.of(context)!.passwordTooShort;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_authData['password'] = value;
|
||||
_authData['password'] = value!;
|
||||
},
|
||||
),
|
||||
if (_authMode == AuthMode.Signup)
|
||||
TextFormField(
|
||||
key: Key('inputPassword2'),
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).confirmPassword),
|
||||
InputDecoration(labelText: AppLocalizations.of(context)!.confirmPassword),
|
||||
controller: _password2Controller,
|
||||
enabled: _authMode == AuthMode.Signup,
|
||||
obscureText: true,
|
||||
validator: _authMode == AuthMode.Signup
|
||||
? (value) {
|
||||
if (value != _passwordController.text) {
|
||||
return AppLocalizations.of(context).passwordsDontMatch;
|
||||
return AppLocalizations.of(context)!.passwordsDontMatch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -270,22 +268,22 @@ class _AuthCardState extends State<AuthCard> {
|
||||
child: TextFormField(
|
||||
key: Key('inputServer'),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).customServerUrl,
|
||||
helperText: AppLocalizations.of(context).customServerHint,
|
||||
labelText: AppLocalizations.of(context)!.customServerUrl,
|
||||
helperText: AppLocalizations.of(context)!.customServerHint,
|
||||
helperMaxLines: 4),
|
||||
controller: _serverUrlController,
|
||||
validator: (value) {
|
||||
if (Uri.tryParse(value) == null) {
|
||||
return AppLocalizations.of(context).invalidUrl;
|
||||
if (Uri.tryParse(value!) == null) {
|
||||
return AppLocalizations.of(context)!.invalidUrl;
|
||||
}
|
||||
|
||||
if (value.isEmpty || !value.contains('http')) {
|
||||
return AppLocalizations.of(context).invalidUrl;
|
||||
return AppLocalizations.of(context)!.invalidUrl;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
_authData['serverUrl'] = value;
|
||||
_authData['serverUrl'] = value!;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -301,7 +299,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
_serverUrlController.text = DEFAULT_SERVER;
|
||||
},
|
||||
),
|
||||
Text(AppLocalizations.of(context).reset)
|
||||
Text(AppLocalizations.of(context)!.reset)
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -316,8 +314,8 @@ class _AuthCardState extends State<AuthCard> {
|
||||
ElevatedButton(
|
||||
key: Key('actionButton'),
|
||||
child: Text(_authMode == AuthMode.Login
|
||||
? AppLocalizations.of(context).login
|
||||
: AppLocalizations.of(context).register),
|
||||
? AppLocalizations.of(context)!.login
|
||||
: AppLocalizations.of(context)!.register),
|
||||
onPressed: () {
|
||||
return _submit(context);
|
||||
},
|
||||
@@ -326,15 +324,15 @@ class _AuthCardState extends State<AuthCard> {
|
||||
key: Key('toggleActionButton'),
|
||||
child: Text(
|
||||
_authMode == AuthMode.Login
|
||||
? AppLocalizations.of(context).registerInstead.toUpperCase()
|
||||
: AppLocalizations.of(context).loginInstead.toUpperCase(),
|
||||
? AppLocalizations.of(context)!.registerInstead.toUpperCase()
|
||||
: AppLocalizations.of(context)!.loginInstead.toUpperCase(),
|
||||
),
|
||||
onPressed: _switchAuthMode,
|
||||
),
|
||||
TextButton(
|
||||
child: Text(_hideCustomServer
|
||||
? AppLocalizations.of(context).useCustomServer
|
||||
: AppLocalizations.of(context).useDefaultServer),
|
||||
? AppLocalizations.of(context)!.useCustomServer
|
||||
: AppLocalizations.of(context)!.useDefaultServer),
|
||||
key: Key('toggleCustomServerButton'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
|
||||
@@ -39,7 +39,7 @@ class DashboardScreen extends StatefulWidget {
|
||||
class _DashboardScreenState extends State<DashboardScreen> {
|
||||
Widget getAppBar() {
|
||||
return AppBar(
|
||||
title: Text(AppLocalizations.of(context).labelDashboard),
|
||||
title: Text(AppLocalizations.of(context)!.labelDashboard),
|
||||
actions: [],
|
||||
);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
await workoutProvider.fetchAndSetWorkouts();
|
||||
await workoutProvider.setAllFullWorkouts();
|
||||
if (workoutProvider.activePlan != null) {
|
||||
workoutProvider.setCurrentPlan(workoutProvider.activePlan.id);
|
||||
workoutProvider.setCurrentPlan(workoutProvider.activePlan!.id!);
|
||||
}
|
||||
|
||||
// Weight
|
||||
@@ -76,7 +76,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: getAppBar(),
|
||||
appBar: getAppBar() as PreferredSizeWidget?,
|
||||
drawer: AppDrawer(),
|
||||
body: FutureBuilder(
|
||||
future: _loadEntries(context),
|
||||
@@ -86,7 +86,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).loadingText,
|
||||
AppLocalizations.of(context)!.loadingText,
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
Padding(padding: EdgeInsets.symmetric(vertical: 8)),
|
||||
|
||||
@@ -32,7 +32,7 @@ class GymModeScreen extends StatefulWidget {
|
||||
class _GymModeScreenState extends State<GymModeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _day = ModalRoute.of(context).settings.arguments as Day;
|
||||
final _day = ModalRoute.of(context)!.settings.arguments as Day;
|
||||
|
||||
return Scaffold(
|
||||
body: Consumer<WorkoutPlans>(
|
||||
|
||||
@@ -31,7 +31,7 @@ class HomeTabsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProviderStateMixin {
|
||||
TabController controller;
|
||||
TabController? controller;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
|
||||
@@ -36,7 +36,7 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _nutritionalPlan = ModalRoute.of(context).settings.arguments as NutritionalPlan;
|
||||
final _nutritionalPlan = ModalRoute.of(context)!.settings.arguments as NutritionalPlan /*!*/;
|
||||
|
||||
return Scaffold(
|
||||
//appBar: getAppBar(nutritionalPlan),
|
||||
@@ -55,14 +55,14 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
if (value == NutritionalPlanOptions.edit) {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
AppLocalizations.of(context)!.edit,
|
||||
PlanForm(_nutritionalPlan),
|
||||
);
|
||||
|
||||
// Delete
|
||||
} else if (value == NutritionalPlanOptions.delete) {
|
||||
Provider.of<Nutrition>(context, listen: false)
|
||||
.deletePlan(_nutritionalPlan.id);
|
||||
.deletePlan(_nutritionalPlan.id!);
|
||||
Navigator.of(context).pushNamed(NutritionalPlanScreen.routeName);
|
||||
}
|
||||
},
|
||||
@@ -70,12 +70,12 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
return [
|
||||
PopupMenuItem<NutritionalPlanOptions>(
|
||||
value: NutritionalPlanOptions.edit,
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
child: Text(AppLocalizations.of(context)!.edit),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem<NutritionalPlanOptions>(
|
||||
value: NutritionalPlanOptions.delete,
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
child: Text(AppLocalizations.of(context)!.delete),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/widgets/app_drawer.dart';
|
||||
import 'package:wger/widgets/core/bottom_sheet.dart';
|
||||
@@ -36,22 +35,22 @@ class NutritionScreen extends StatefulWidget {
|
||||
class _NutritionScreenState extends State<NutritionScreen> {
|
||||
Widget getAppBar() {
|
||||
return AppBar(
|
||||
title: Text(AppLocalizations.of(context).nutritionalPlans),
|
||||
title: Text(AppLocalizations.of(context)!.nutritionalPlans),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: getAppBar(),
|
||||
appBar: getAppBar() as PreferredSizeWidget?,
|
||||
drawer: AppDrawer(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newNutritionalPlan,
|
||||
PlanForm(NutritionalPlan()),
|
||||
AppLocalizations.of(context)!.newNutritionalPlan,
|
||||
PlanForm(),
|
||||
);
|
||||
//await showNutritionalPlanSheet(context, nutritionalPlan);
|
||||
},
|
||||
|
||||
@@ -33,21 +33,21 @@ class WeightScreen extends StatefulWidget {
|
||||
class _WeightScreenState extends State<WeightScreen> {
|
||||
Widget getAppBar() {
|
||||
return AppBar(
|
||||
title: Text(AppLocalizations.of(context).weight),
|
||||
title: Text(AppLocalizations.of(context)!.weight),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: getAppBar(),
|
||||
appBar: getAppBar() as PreferredSizeWidget?,
|
||||
drawer: AppDrawer(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newEntry,
|
||||
AppLocalizations.of(context)!.newEntry,
|
||||
WeightForm(),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -64,14 +64,14 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
return WorkoutLogs(plan, _changeMode);
|
||||
break;
|
||||
case WorkoutScreenMode.gym:
|
||||
return Text(AppLocalizations.of(context).gymMode);
|
||||
return Text(AppLocalizations.of(context)!.gymMode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final workoutPlan = ModalRoute.of(context).settings.arguments as WorkoutPlan;
|
||||
final workoutPlan = ModalRoute.of(context)!.settings.arguments as WorkoutPlan;
|
||||
|
||||
return Scaffold(
|
||||
//appBar: getAppBar(workoutPlan),
|
||||
@@ -96,14 +96,14 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
if (value == WorkoutOptions.edit) {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
AppLocalizations.of(context)!.edit,
|
||||
WorkoutForm(workoutPlan),
|
||||
);
|
||||
|
||||
// Delete
|
||||
} else if (value == WorkoutOptions.delete) {
|
||||
Provider.of<WorkoutPlans>(context, listen: false)
|
||||
.deleteWorkout(workoutPlan.id);
|
||||
.deleteWorkout(workoutPlan.id!);
|
||||
Navigator.of(context).pushNamed(WorkoutPlansScreen.routeName);
|
||||
|
||||
// Toggle Mode
|
||||
@@ -119,7 +119,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
return [
|
||||
PopupMenuItem<WorkoutOptions>(
|
||||
value: WorkoutOptions.edit,
|
||||
child: Text(AppLocalizations.of(context).edit),
|
||||
child: Text(AppLocalizations.of(context)!.edit),
|
||||
),
|
||||
PopupMenuItem<WorkoutOptions>(
|
||||
child: _mode == WorkoutScreenMode.log
|
||||
@@ -130,7 +130,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem<WorkoutOptions>(
|
||||
value: WorkoutOptions.delete,
|
||||
child: Text(AppLocalizations.of(context).delete),
|
||||
child: Text(AppLocalizations.of(context)!.delete),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
@@ -24,6 +24,7 @@ import 'package:wger/models/workouts/workout_plan.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/widgets/app_drawer.dart';
|
||||
import 'package:wger/widgets/core/bottom_sheet.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
import 'package:wger/widgets/workouts/forms.dart';
|
||||
import 'package:wger/widgets/workouts/workout_plans_list.dart';
|
||||
|
||||
@@ -35,23 +36,17 @@ class WorkoutPlansScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _WorkoutPlansScreenState extends State<WorkoutPlansScreen> {
|
||||
Widget getAppBar() {
|
||||
return AppBar(
|
||||
title: Text(AppLocalizations.of(context).labelWorkoutPlans),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: getAppBar(),
|
||||
appBar: WgerAppBar(AppLocalizations.of(context)!.labelWorkoutPlans),
|
||||
drawer: AppDrawer(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newWorkout,
|
||||
AppLocalizations.of(context)!.newWorkout,
|
||||
WorkoutForm(WorkoutPlan()),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -38,7 +38,7 @@ class AppDrawer extends StatelessWidget {
|
||||
/*
|
||||
ListTile(
|
||||
leading: Icon(Icons.home),
|
||||
title: Text(AppLocalizations.of(context).labelDashboard),
|
||||
title: Text(AppLocalizations.of(context)!.labelDashboard),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushReplacementNamed(DashboardScreen.routeName);
|
||||
@@ -114,7 +114,7 @@ class AppDrawer extends StatelessWidget {
|
||||
//dense: true,
|
||||
icon: Icon(Icons.info),
|
||||
applicationName: 'wger',
|
||||
applicationVersion: '${authProvider.applicationVersion.version} '
|
||||
applicationVersion: '${authProvider.applicationVersion!.version} '
|
||||
'(server: ${authProvider.serverVersion})',
|
||||
applicationLegalese: '\u{a9} 2020 - 2021 contributors',
|
||||
applicationIcon: Padding(
|
||||
@@ -133,7 +133,7 @@ class AppDrawer extends StatelessWidget {
|
||||
style: TextStyle(fontSize: 16, color: Colors.black),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: AppLocalizations.of(context).aboutText,
|
||||
text: AppLocalizations.of(context)!.aboutText,
|
||||
),
|
||||
TextSpan(
|
||||
text: 'https://github.com/wger-project',
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<Widget> showFormBottomSheet(BuildContext context, String header, Widget form,
|
||||
Future<Widget?> showFormBottomSheet(BuildContext context, String header, Widget form,
|
||||
{bool scrollControlled: false}) async {
|
||||
return showModalBottomSheet(
|
||||
isScrollControlled: scrollControlled,
|
||||
|
||||
@@ -23,7 +23,7 @@ class MutedText extends StatelessWidget {
|
||||
String _text;
|
||||
MutedText(
|
||||
this._text, {
|
||||
Key key,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -31,3 +31,20 @@ class MutedText extends StatelessWidget {
|
||||
return Text(_text, style: TextStyle(color: wgerTextMuted));
|
||||
}
|
||||
}
|
||||
|
||||
/// Appbar that extends [PreferredSizeWidget]
|
||||
class WgerAppBar extends StatelessWidget with PreferredSizeWidget {
|
||||
String _title;
|
||||
|
||||
WgerAppBar(this._title);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppBar(
|
||||
title: Text(_title),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Size get preferredSize => Size.fromHeight(kToolbarHeight);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class Event {
|
||||
}
|
||||
|
||||
class DashboardCalendarWidget extends StatefulWidget {
|
||||
DashboardCalendarWidget({Key key}) : super(key: key);
|
||||
DashboardCalendarWidget();
|
||||
|
||||
@override
|
||||
_DashboardCalendarWidgetState createState() => _DashboardCalendarWidgetState();
|
||||
@@ -72,10 +72,10 @@ class DashboardCalendarWidget extends StatefulWidget {
|
||||
|
||||
class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
with TickerProviderStateMixin {
|
||||
Map<DateTime, List> _events;
|
||||
List _selectedEvents;
|
||||
AnimationController _animationController;
|
||||
CalendarController _calendarController;
|
||||
late Map<DateTime, List> _events;
|
||||
late List _selectedEvents;
|
||||
late AnimationController _animationController;
|
||||
late CalendarController _calendarController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -115,7 +115,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
}
|
||||
|
||||
// Add events to lists
|
||||
_events[date].add(Event(EventType.weight, '${entry.weight} kg'));
|
||||
_events[date]!.add(Event(EventType.weight, '${entry.weight} kg'));
|
||||
}
|
||||
|
||||
// Process workout sessions
|
||||
@@ -134,9 +134,9 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
}
|
||||
|
||||
// Add events to lists
|
||||
_events[date].add(Event(
|
||||
_events[date]!.add(Event(
|
||||
EventType.session,
|
||||
'${AppLocalizations.of(context).impression}: ${session.impressionAsString} $time',
|
||||
'${AppLocalizations.of(context)!.impression}: ${session.impressionAsString} $time',
|
||||
));
|
||||
}
|
||||
});
|
||||
@@ -151,7 +151,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
}
|
||||
|
||||
// Add events to lists
|
||||
_events[date].add(Event(
|
||||
_events[date]!.add(Event(
|
||||
EventType.caloriesDiary,
|
||||
'${entry.value.energy.toStringAsFixed(0)} kcal',
|
||||
));
|
||||
@@ -186,7 +186,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
children: [
|
||||
const SizedBox(height: 8.0),
|
||||
Text(
|
||||
AppLocalizations.of(context).calendar,
|
||||
AppLocalizations.of(context)!.calendar,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
|
||||
@@ -361,7 +361,7 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).goToToday),
|
||||
child: Text(AppLocalizations.of(context)!.goToToday),
|
||||
onPressed: () async {
|
||||
final today = DateTime.now();
|
||||
_calendarController.setSelectedDay(
|
||||
@@ -399,13 +399,13 @@ class _DashboardCalendarWidgetState extends State<DashboardCalendarWidget>
|
||||
title: Text((() {
|
||||
switch (event.type) {
|
||||
case EventType.caloriesDiary:
|
||||
return AppLocalizations.of(context).nutritionalDiary;
|
||||
return AppLocalizations.of(context)!.nutritionalDiary;
|
||||
|
||||
case EventType.session:
|
||||
return AppLocalizations.of(context).workoutSession;
|
||||
return AppLocalizations.of(context)!.workoutSession;
|
||||
|
||||
case EventType.weight:
|
||||
return AppLocalizations.of(context).weight;
|
||||
return AppLocalizations.of(context)!.weight;
|
||||
}
|
||||
return event.description.toString();
|
||||
})()),
|
||||
|
||||
@@ -38,9 +38,8 @@ import 'package:wger/widgets/workouts/forms.dart';
|
||||
|
||||
class DashboardNutritionWidget extends StatefulWidget {
|
||||
const DashboardNutritionWidget({
|
||||
Key key,
|
||||
@required this.context,
|
||||
}) : super(key: key);
|
||||
required this.context,
|
||||
});
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
@@ -49,13 +48,13 @@ class DashboardNutritionWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
Nutrition nutrition;
|
||||
NutritionalPlan plan;
|
||||
//Nutrition nutrition;
|
||||
late NutritionalPlan plan;
|
||||
var showDetail = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
plan = Provider.of<Nutrition>(context, listen: false).currentPlan;
|
||||
NutritionalPlan? plan = Provider.of<Nutrition>(context, listen: false).currentPlan;
|
||||
final bool hasContent = plan != null;
|
||||
|
||||
List<Widget> out = [];
|
||||
@@ -70,16 +69,16 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${meal.nutritionalValues.energy.toStringAsFixed(0)}${AppLocalizations.of(context).kcal}'),
|
||||
'${meal.nutritionalValues.energy.toStringAsFixed(0)}${AppLocalizations.of(context)!.kcal}'),
|
||||
Text(' / '),
|
||||
Text(
|
||||
'${meal.nutritionalValues.protein.toStringAsFixed(0)}${AppLocalizations.of(context).g}'),
|
||||
'${meal.nutritionalValues.protein.toStringAsFixed(0)}${AppLocalizations.of(context)!.g}'),
|
||||
Text(' / '),
|
||||
Text(
|
||||
'${meal.nutritionalValues.carbohydrates.toStringAsFixed(0)}${AppLocalizations.of(context).g}'),
|
||||
'${meal.nutritionalValues.carbohydrates.toStringAsFixed(0)}${AppLocalizations.of(context)!.g}'),
|
||||
Text(' / '),
|
||||
Text(
|
||||
'${meal.nutritionalValues.fat.toStringAsFixed(0)}${AppLocalizations.of(context).g} '),
|
||||
'${meal.nutritionalValues.fat.toStringAsFixed(0)}${AppLocalizations.of(context)!.g} '),
|
||||
],
|
||||
));
|
||||
out.add(SizedBox(height: 5));
|
||||
@@ -93,7 +92,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
children: [
|
||||
Text(item.ingredientObj.name),
|
||||
SizedBox(width: 5),
|
||||
Text('${item.amount.toString()} ${AppLocalizations.of(context).g}'),
|
||||
Text('${item.amount.toString()} ${AppLocalizations.of(context)!.g}'),
|
||||
],
|
||||
),
|
||||
]),
|
||||
@@ -110,7 +109,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).nutritionalPlan,
|
||||
AppLocalizations.of(context)!.nutritionalPlan,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
hasContent
|
||||
@@ -127,7 +126,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
onPressed: () {
|
||||
return Navigator.of(context)
|
||||
Navigator.of(context)
|
||||
.pushNamed(NutritionalPlanScreen.routeName, arguments: plan);
|
||||
},
|
||||
),
|
||||
@@ -140,15 +139,15 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
],
|
||||
)
|
||||
: NothingFound(
|
||||
AppLocalizations.of(context).noNutritionalPlans,
|
||||
AppLocalizations.of(context).newNutritionalPlan,
|
||||
PlanForm(NutritionalPlan()),
|
||||
AppLocalizations.of(context)!.noNutritionalPlans,
|
||||
AppLocalizations.of(context)!.newNutritionalPlan,
|
||||
PlanForm(),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).toggleDetails),
|
||||
child: Text(AppLocalizations.of(context)!.toggleDetails),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showDetail = !showDetail;
|
||||
@@ -165,9 +164,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
|
||||
|
||||
class DashboardWeightWidget extends StatefulWidget {
|
||||
const DashboardWeightWidget({
|
||||
Key key,
|
||||
@required this.context,
|
||||
}) : super(key: key);
|
||||
required this.context,
|
||||
});
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
@@ -176,7 +174,7 @@ class DashboardWeightWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
BodyWeight weightEntriesData;
|
||||
late BodyWeight weightEntriesData;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -187,7 +185,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).weight,
|
||||
AppLocalizations.of(context)!.weight,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
Column(
|
||||
@@ -199,19 +197,19 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
child: WeightChartWidget(weightEntriesData.items),
|
||||
)
|
||||
: NothingFound(
|
||||
AppLocalizations.of(context).noWeightEntries,
|
||||
AppLocalizations.of(context).newEntry,
|
||||
AppLocalizations.of(context)!.noWeightEntries,
|
||||
AppLocalizations.of(context)!.newEntry,
|
||||
WeightForm(),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).newEntry),
|
||||
child: Text(AppLocalizations.of(context)!.newEntry),
|
||||
onPressed: () async {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newEntry,
|
||||
AppLocalizations.of(context)!.newEntry,
|
||||
WeightForm(),
|
||||
);
|
||||
},
|
||||
@@ -228,9 +226,8 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
|
||||
|
||||
class DashboardWorkoutWidget extends StatefulWidget {
|
||||
DashboardWorkoutWidget({
|
||||
Key key,
|
||||
@required this.context,
|
||||
}) : super(key: key);
|
||||
required this.context,
|
||||
});
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
@@ -239,7 +236,7 @@ class DashboardWorkoutWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
WorkoutPlan _workoutPlan;
|
||||
late WorkoutPlan _workoutPlan;
|
||||
var showDetail = false;
|
||||
|
||||
@override
|
||||
@@ -250,7 +247,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_workoutPlan = Provider.of<WorkoutPlans>(context, listen: false).activePlan;
|
||||
WorkoutPlan? _workoutPlan = Provider.of<WorkoutPlans>(context, listen: false).activePlan;
|
||||
final bool hasContent = _workoutPlan != null;
|
||||
|
||||
List<Widget> out = [];
|
||||
@@ -286,7 +283,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).labelWorkoutPlan,
|
||||
AppLocalizations.of(context)!.labelWorkoutPlan,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
hasContent
|
||||
@@ -303,7 +300,7 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
onPressed: () {
|
||||
return Navigator.of(context)
|
||||
Navigator.of(context)
|
||||
.pushNamed(WorkoutPlanScreen.routeName, arguments: _workoutPlan);
|
||||
},
|
||||
),
|
||||
@@ -311,15 +308,15 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
],
|
||||
)
|
||||
: NothingFound(
|
||||
AppLocalizations.of(context).noWorkoutPlans,
|
||||
AppLocalizations.of(context).newWorkout,
|
||||
AppLocalizations.of(context)!.noWorkoutPlans,
|
||||
AppLocalizations.of(context)!.newWorkout,
|
||||
WorkoutForm(WorkoutPlan()),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).toggleDetails),
|
||||
child: Text(AppLocalizations.of(context)!.toggleDetails),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showDetail = !showDetail;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import 'package:charts_flutter/flutter.dart' as charts;
|
||||
import 'package:charts_flutter/flutter.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
@@ -44,12 +45,12 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
|
||||
domainFn: (datum, index) => datum[0],
|
||||
measureFn: (datum, index) => datum[1],
|
||||
data: [
|
||||
[AppLocalizations.of(context).protein, _nutritionalValues.protein],
|
||||
[AppLocalizations.of(context).fat, _nutritionalValues.fat],
|
||||
[AppLocalizations.of(context).carbohydrates, _nutritionalValues.carbohydrates],
|
||||
[AppLocalizations.of(context)!.protein, _nutritionalValues.protein],
|
||||
[AppLocalizations.of(context)!.fat, _nutritionalValues.fat],
|
||||
[AppLocalizations.of(context)!.carbohydrates, _nutritionalValues.carbohydrates],
|
||||
],
|
||||
labelAccessorFn: (List<dynamic> row, _) =>
|
||||
'${row[0]}, ${row[1].toStringAsFixed(0)}${AppLocalizations.of(context).g}',
|
||||
'${row[0]}, ${row[1].toStringAsFixed(0)}${AppLocalizations.of(context)!.g}',
|
||||
)
|
||||
],
|
||||
defaultRenderer: new charts.ArcRendererConfig(
|
||||
@@ -62,26 +63,26 @@ class NutritionalPlanPieChartWidget extends StatelessWidget {
|
||||
|
||||
class NutritionalDiaryChartWidget extends StatelessWidget {
|
||||
const NutritionalDiaryChartWidget({
|
||||
Key key,
|
||||
@required NutritionalPlan nutritionalPlan,
|
||||
}) : _nutritionalPlan = nutritionalPlan,
|
||||
Key? key,
|
||||
required NutritionalPlan? nutritionalPlan,
|
||||
}) : _nutritionalPlan = nutritionalPlan,
|
||||
super(key: key);
|
||||
|
||||
final NutritionalPlan _nutritionalPlan;
|
||||
final NutritionalPlan? _nutritionalPlan;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return charts.TimeSeriesChart(
|
||||
[
|
||||
charts.Series<List<dynamic>, DateTime>(
|
||||
charts.Series<List<dynamic>, DateTime?>(
|
||||
id: 'NutritionDiary',
|
||||
colorFn: (datum, index) => wgerChartSecondaryColor,
|
||||
domainFn: (datum, index) => datum[1],
|
||||
measureFn: (datum, index) => datum[0].energy,
|
||||
data: _nutritionalPlan.logEntriesValues.keys
|
||||
.map((e) => [_nutritionalPlan.logEntriesValues[e], e])
|
||||
data: _nutritionalPlan!.logEntriesValues.keys
|
||||
.map((e) => [_nutritionalPlan!.logEntriesValues[e], e])
|
||||
.toList(),
|
||||
)
|
||||
) as Series<dynamic, DateTime>
|
||||
],
|
||||
defaultRenderer: new charts.BarRendererConfig<DateTime>(),
|
||||
);
|
||||
|
||||
@@ -29,20 +29,31 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
|
||||
class MealForm extends StatelessWidget {
|
||||
Meal _meal;
|
||||
late Meal _meal;
|
||||
int _planId;
|
||||
//var _mealData = {'id': null, 'planId': -1, 'time': TimeOfDay.now()};
|
||||
|
||||
final _form = GlobalKey<FormState>();
|
||||
final _timeController = TextEditingController();
|
||||
|
||||
MealForm(planId, [meal]) {
|
||||
this._planId = planId;
|
||||
this._meal = meal ?? Meal();
|
||||
|
||||
_timeController.text =
|
||||
_meal.time != null ? timeToString(_meal.time) : timeToString(TimeOfDay.now());
|
||||
MealForm(this._planId, [meal]) {
|
||||
this._meal = meal ?? Meal(plan: _planId);
|
||||
_timeController.text = timeToString(_meal.time)!;
|
||||
}
|
||||
|
||||
/*
|
||||
MealForm(int planId, [Meal? meal]) {
|
||||
_mealData['planId'] = planId;
|
||||
_timeController.text = timeToString(_mealData['time'] as TimeOfDay)!;
|
||||
|
||||
if (meal != null) {
|
||||
_mealData['id'] = meal.id;
|
||||
_mealData['time'] = meal.time;
|
||||
_timeController.text = timeToString(meal.time)!;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -52,7 +63,7 @@ class MealForm extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).time),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.time),
|
||||
controller: _timeController,
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
@@ -61,10 +72,10 @@ class MealForm extends StatelessWidget {
|
||||
// Open time picker
|
||||
var pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: _meal.time ?? TimeOfDay.now(),
|
||||
initialTime: _meal.time,
|
||||
);
|
||||
|
||||
_timeController.text = timeToString(pickedTime);
|
||||
_timeController.text = timeToString(pickedTime)!;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_meal.time = stringToTime(newValue);
|
||||
@@ -72,14 +83,12 @@ class MealForm extends StatelessWidget {
|
||||
onFieldSubmitted: (_) {},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
if (!_form.currentState.validate()) {
|
||||
if (!_form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
|
||||
_meal.plan = _planId;
|
||||
_form.currentState!.save();
|
||||
|
||||
try {
|
||||
_meal.id == null
|
||||
@@ -101,14 +110,27 @@ class MealForm extends StatelessWidget {
|
||||
}
|
||||
|
||||
class MealItemForm extends StatelessWidget {
|
||||
Meal meal;
|
||||
MealItem mealItem;
|
||||
Meal _meal;
|
||||
late MealItem _mealItem;
|
||||
|
||||
MealItemForm(meal, [mealItem]) {
|
||||
this.meal = meal;
|
||||
this.mealItem = mealItem ?? MealItem();
|
||||
//var mealItemData = {};
|
||||
|
||||
MealItemForm(this._meal, [mealItem]) {
|
||||
this._mealItem = mealItem ?? MealItem(meal: _meal.id);
|
||||
}
|
||||
|
||||
/*
|
||||
MealItemForm(this._meal, [MealItem? mealItem]) {
|
||||
//this.meal = meal;
|
||||
mealItemData['meal'] = _meal.id;
|
||||
if (mealItem != null) {
|
||||
mealItemData['ingredientId'] = mealItem.ingredientId;
|
||||
mealItemData['amount'] = mealItem.amount;
|
||||
}
|
||||
//this.mealItem = mealItem ?? MealItem();
|
||||
}
|
||||
*/
|
||||
|
||||
final _form = GlobalKey<FormState>();
|
||||
final _ingredientController = TextEditingController();
|
||||
final _amountController = TextEditingController();
|
||||
@@ -124,13 +146,13 @@ class MealItemForm extends StatelessWidget {
|
||||
TypeAheadFormField(
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: this._ingredientController,
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).ingredient),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.ingredient),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return await Provider.of<Nutrition>(context, listen: false)
|
||||
.searchIngredient(pattern);
|
||||
},
|
||||
itemBuilder: (context, suggestion) {
|
||||
itemBuilder: (context, dynamic suggestion) {
|
||||
return ListTile(
|
||||
title: Text(suggestion['value']),
|
||||
subtitle: Text(suggestion['data']['id'].toString()),
|
||||
@@ -139,49 +161,47 @@ class MealItemForm extends StatelessWidget {
|
||||
transitionBuilder: (context, suggestionsBox, controller) {
|
||||
return suggestionsBox;
|
||||
},
|
||||
onSuggestionSelected: (suggestion) {
|
||||
mealItem.ingredientId = suggestion['data']['id'];
|
||||
onSuggestionSelected: (dynamic suggestion) {
|
||||
_mealItem.ingredientId = suggestion['data']['id'];
|
||||
this._ingredientController.text = suggestion['value'];
|
||||
},
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return AppLocalizations.of(context).selectIngredient;
|
||||
if (value!.isEmpty) {
|
||||
return AppLocalizations.of(context)!.selectIngredient;
|
||||
}
|
||||
if (mealItem.ingredientId == null) {
|
||||
return AppLocalizations.of(context).selectIngredient;
|
||||
if (_mealItem.ingredientId == null) {
|
||||
return AppLocalizations.of(context)!.selectIngredient;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).amount),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.amount),
|
||||
controller: _amountController,
|
||||
keyboardType: TextInputType.number,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
mealItem.amount = double.parse(newValue);
|
||||
_mealItem.amount = double.parse(newValue!);
|
||||
},
|
||||
validator: (value) {
|
||||
try {
|
||||
double.parse(value);
|
||||
double.parse(value!);
|
||||
} catch (error) {
|
||||
return AppLocalizations.of(context).enterValidNumber;
|
||||
return AppLocalizations.of(context)!.enterValidNumber;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
if (!_form.currentState.validate()) {
|
||||
if (!_form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
try {
|
||||
mealItem.meal = meal.id;
|
||||
|
||||
Provider.of<Nutrition>(context, listen: false).addMealItem(mealItem, meal.id);
|
||||
Provider.of<Nutrition>(context, listen: false).addMealItem(_mealItem, _meal.id!);
|
||||
} on WgerHttpException catch (error) {
|
||||
showHttpExceptionErrorDialog(error, context);
|
||||
} catch (error) {
|
||||
@@ -198,45 +218,63 @@ class MealItemForm extends StatelessWidget {
|
||||
}
|
||||
|
||||
class PlanForm extends StatelessWidget {
|
||||
NutritionalPlan _plan;
|
||||
PlanForm(this._plan);
|
||||
//NutritionalPlan? _plan;
|
||||
var _planData = {
|
||||
'description': '',
|
||||
'creationDate': DateTime.now(),
|
||||
'id': null,
|
||||
};
|
||||
|
||||
final _form = GlobalKey<FormState>();
|
||||
final descriptionController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
PlanForm([NutritionalPlan? plan]) {
|
||||
if (plan != null) {
|
||||
_planData['id'] = plan.id;
|
||||
_planData['description'] = plan.description;
|
||||
_planData['creationDate'] = plan.creationDate;
|
||||
}
|
||||
|
||||
_descriptionController.text = _planData['description'] as String;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
descriptionController.text = _plan.description ?? '';
|
||||
|
||||
return Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
children: [
|
||||
// Description
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
|
||||
controller: descriptionController,
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.description),
|
||||
controller: _descriptionController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_plan.description = newValue;
|
||||
_planData['description'] = newValue!;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
// Validate and save the current values to the weightEntry
|
||||
final isValid = _form.currentState.validate();
|
||||
final isValid = _form.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
if (_plan.id != null) {
|
||||
await Provider.of<Nutrition>(context, listen: false).patchPlan(_plan);
|
||||
NutritionalPlan plan = NutritionalPlan(
|
||||
description: _planData['description'] as String,
|
||||
creationDate: _planData['creationDate'] as DateTime,
|
||||
);
|
||||
|
||||
if (_planData['id'] != null) {
|
||||
plan.id = _planData['id'] as int;
|
||||
await Provider.of<Nutrition>(context, listen: false).patchPlan(plan);
|
||||
} else {
|
||||
await Provider.of<Nutrition>(context, listen: false).postPlan(_plan);
|
||||
await Provider.of<Nutrition>(context, listen: false).postPlan(plan);
|
||||
}
|
||||
|
||||
// Saving was successful, reset the data
|
||||
|
||||
@@ -61,20 +61,20 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MutedText(AppLocalizations.of(context).energy),
|
||||
MutedText(AppLocalizations.of(context).protein),
|
||||
MutedText(AppLocalizations.of(context).carbohydrates),
|
||||
MutedText(AppLocalizations.of(context).fat),
|
||||
MutedText(AppLocalizations.of(context)!.energy),
|
||||
MutedText(AppLocalizations.of(context)!.protein),
|
||||
MutedText(AppLocalizations.of(context)!.carbohydrates),
|
||||
MutedText(AppLocalizations.of(context)!.fat),
|
||||
],
|
||||
),
|
||||
),
|
||||
...widget._meal.mealItems.map((item) => MealItemWidget(item, _expanded)).toList(),
|
||||
OutlinedButton(
|
||||
child: Text(AppLocalizations.of(context).addIngredient),
|
||||
child: Text(AppLocalizations.of(context)!.addIngredient),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).addIngredient,
|
||||
AppLocalizations.of(context)!.addIngredient,
|
||||
MealItemForm(widget._meal),
|
||||
scrollControlled: true,
|
||||
);
|
||||
@@ -96,8 +96,8 @@ class MealItemWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String unit = _item.weightUnit == null
|
||||
? AppLocalizations.of(context).g
|
||||
: _item.weightUnit.weightUnit.name;
|
||||
? AppLocalizations.of(context)!.g
|
||||
: _item.weightUnit!.weightUnit.name;
|
||||
final values = _item.nutritionalValues;
|
||||
|
||||
return Container(
|
||||
@@ -127,7 +127,7 @@ class MealItemWidget extends StatelessWidget {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
AppLocalizations.of(context)!.successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
)),
|
||||
);
|
||||
@@ -141,11 +141,11 @@ class MealItemWidget extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MutedText(
|
||||
'${values.energy.toStringAsFixed(0)} ${AppLocalizations.of(context).kcal}'),
|
||||
MutedText('${values.protein.toStringAsFixed(0)}${AppLocalizations.of(context).g}'),
|
||||
'${values.energy.toStringAsFixed(0)} ${AppLocalizations.of(context)!.kcal}'),
|
||||
MutedText('${values.protein.toStringAsFixed(0)}${AppLocalizations.of(context)!.g}'),
|
||||
MutedText(
|
||||
'${values.carbohydrates.toStringAsFixed(0)}${AppLocalizations.of(context).g}'),
|
||||
MutedText('${values.fat.toStringAsFixed(0)}${AppLocalizations.of(context).g}'),
|
||||
'${values.carbohydrates.toStringAsFixed(0)}${AppLocalizations.of(context)!.g}'),
|
||||
MutedText('${values.fat.toStringAsFixed(0)}${AppLocalizations.of(context)!.g}'),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -161,10 +161,8 @@ class DismissibleMealHeader extends StatelessWidget {
|
||||
const DismissibleMealHeader(
|
||||
this._expanded,
|
||||
this._toggle, {
|
||||
Key key,
|
||||
@required Meal meal,
|
||||
}) : _meal = meal,
|
||||
super(key: key);
|
||||
required Meal meal,
|
||||
}) : _meal = meal;
|
||||
|
||||
final Meal _meal;
|
||||
|
||||
@@ -174,7 +172,7 @@ class DismissibleMealHeader extends StatelessWidget {
|
||||
onLongPress: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
AppLocalizations.of(context)!.edit,
|
||||
MealForm(_meal.plan, _meal),
|
||||
);
|
||||
},
|
||||
@@ -243,7 +241,7 @@ class DismissibleMealHeader extends StatelessWidget {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
AppLocalizations.of(context)!.successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -255,7 +253,7 @@ class DismissibleMealHeader extends StatelessWidget {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).mealLogged,
|
||||
AppLocalizations.of(context)!.mealLogged,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -42,12 +42,12 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).addMeal),
|
||||
child: Text(AppLocalizations.of(context)!.addMeal),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).addMeal,
|
||||
MealForm(_nutritionalPlan.id),
|
||||
AppLocalizations.of(context)!.addMeal,
|
||||
MealForm(_nutritionalPlan.id!),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -67,14 +67,14 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(AppLocalizations.of(context).energy),
|
||||
Text(AppLocalizations.of(context).protein),
|
||||
Text(AppLocalizations.of(context).carbohydrates),
|
||||
Text(AppLocalizations.of(context).sugars),
|
||||
Text(AppLocalizations.of(context).fat),
|
||||
Text(AppLocalizations.of(context).saturatedFat),
|
||||
Text(AppLocalizations.of(context).fibres),
|
||||
Text(AppLocalizations.of(context).sodium),
|
||||
Text(AppLocalizations.of(context)!.energy),
|
||||
Text(AppLocalizations.of(context)!.protein),
|
||||
Text(AppLocalizations.of(context)!.carbohydrates),
|
||||
Text(AppLocalizations.of(context)!.sugars),
|
||||
Text(AppLocalizations.of(context)!.fat),
|
||||
Text(AppLocalizations.of(context)!.saturatedFat),
|
||||
Text(AppLocalizations.of(context)!.fibres),
|
||||
Text(AppLocalizations.of(context)!.sodium),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -97,14 +97,14 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(AppLocalizations.of(context).kcal),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context).g),
|
||||
Text(AppLocalizations.of(context)!.kcal),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
Text(AppLocalizations.of(context)!.g),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -130,17 +130,17 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
children: [
|
||||
Text(''),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).energy} (${AppLocalizations.of(context).kcal})'),
|
||||
'${AppLocalizations.of(context)!.energy} (${AppLocalizations.of(context)!.kcal})'),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).protein} (${AppLocalizations.of(context).g})'),
|
||||
'${AppLocalizations.of(context)!.protein} (${AppLocalizations.of(context)!.g})'),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).carbohydrates} (${AppLocalizations.of(context).g})'),
|
||||
'${AppLocalizations.of(context)!.carbohydrates} (${AppLocalizations.of(context)!.g})'),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).sugars} (${AppLocalizations.of(context).g})'),
|
||||
'${AppLocalizations.of(context)!.sugars} (${AppLocalizations.of(context)!.g})'),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).fat} (${AppLocalizations.of(context).g})'),
|
||||
'${AppLocalizations.of(context)!.fat} (${AppLocalizations.of(context)!.g})'),
|
||||
Text(
|
||||
'${AppLocalizations.of(context).saturatedFat} (${AppLocalizations.of(context).g})'),
|
||||
'${AppLocalizations.of(context)!.saturatedFat} (${AppLocalizations.of(context)!.g})'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -37,26 +37,26 @@ class NutritionalPlansList extends StatelessWidget {
|
||||
key: Key(currentPlan.id.toString()),
|
||||
confirmDismiss: (direction) async {
|
||||
// Delete workout from DB
|
||||
final bool res = await showDialog(
|
||||
final bool? res = await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).confirmDelete(currentPlan.description),
|
||||
AppLocalizations.of(context)!.confirmDelete(currentPlan.description),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).cancel),
|
||||
child: Text(AppLocalizations.of(context)!.cancel),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
AppLocalizations.of(context)!.delete,
|
||||
style: TextStyle(color: Theme.of(context).errorColor),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the workout
|
||||
_nutritrionProvider.deletePlan(currentPlan.id);
|
||||
_nutritrionProvider.deletePlan(currentPlan.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
@@ -65,7 +65,7 @@ class NutritionalPlansList extends StatelessWidget {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
AppLocalizations.of(context)!.successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -49,7 +49,7 @@ class WeightEntriesList extends StatelessWidget {
|
||||
onDismissed: (direction) {
|
||||
if (direction == DismissDirection.endToStart) {
|
||||
// Delete entry from DB
|
||||
_weightProvider.deleteEntry(currentEntry.id);
|
||||
_weightProvider.deleteEntry(currentEntry.id!);
|
||||
|
||||
// and inform the user
|
||||
Scaffold.of(context).showSnackBar(
|
||||
@@ -67,7 +67,7 @@ class WeightEntriesList extends StatelessWidget {
|
||||
if (direction == DismissDirection.startToEnd) {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).edit,
|
||||
AppLocalizations.of(context)!.edit,
|
||||
WeightForm(currentEntry),
|
||||
);
|
||||
return false;
|
||||
|
||||
@@ -13,11 +13,11 @@ class WeightForm extends StatelessWidget {
|
||||
final dateController = TextEditingController(text: toDate(DateTime.now()).toString());
|
||||
final weightController = TextEditingController();
|
||||
|
||||
WeightEntry _weightEntry;
|
||||
late WeightEntry _weightEntry;
|
||||
|
||||
WeightForm([weightEntry]) {
|
||||
WeightForm([WeightEntry? weightEntry]) {
|
||||
this._weightEntry = weightEntry ?? WeightEntry();
|
||||
weightController.text = _weightEntry.weight == null ? '' : _weightEntry.weight.toString();
|
||||
weightController.text = _weightEntry.id == null ? '' : _weightEntry.weight.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -28,7 +28,7 @@ class WeightForm extends StatelessWidget {
|
||||
children: [
|
||||
// Weight date
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).date),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.date),
|
||||
controller: dateController,
|
||||
onTap: () async {
|
||||
// Stop keyboard from appearing
|
||||
@@ -42,44 +42,44 @@ class WeightForm extends StatelessWidget {
|
||||
lastDate: DateTime.now(),
|
||||
);
|
||||
|
||||
dateController.text = toDate(pickedDate);
|
||||
dateController.text = toDate(pickedDate)!;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_weightEntry.date = DateTime.parse(newValue);
|
||||
_weightEntry.date = DateTime.parse(newValue!);
|
||||
},
|
||||
onFieldSubmitted: (_) {},
|
||||
),
|
||||
|
||||
// Weight
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.weight),
|
||||
controller: weightController,
|
||||
keyboardType: TextInputType.number,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_weightEntry.weight = double.parse(newValue);
|
||||
_weightEntry.weight = double.parse(newValue!);
|
||||
},
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return AppLocalizations.of(context).enterValue;
|
||||
if (value!.isEmpty) {
|
||||
return AppLocalizations.of(context)!.enterValue;
|
||||
}
|
||||
try {
|
||||
double.parse(value);
|
||||
} catch (error) {
|
||||
return AppLocalizations.of(context).enterValidNumber;
|
||||
return AppLocalizations.of(context)!.enterValidNumber;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
// Validate and save the current values to the weightEntry
|
||||
final isValid = _form.currentState.validate();
|
||||
final isValid = _form.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
|
||||
@@ -34,7 +34,7 @@ class SettingWidget extends StatelessWidget {
|
||||
final bool expanded;
|
||||
final toggle;
|
||||
|
||||
SettingWidget({this.setting, this.expanded, this.toggle});
|
||||
SettingWidget({required this.setting, required this.expanded, required this.toggle});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -134,7 +134,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).gymMode,
|
||||
AppLocalizations.of(context)!.gymMode,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
Icon(
|
||||
@@ -151,11 +151,11 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
)
|
||||
.toList(),
|
||||
OutlinedButton(
|
||||
child: Text(AppLocalizations.of(context).addExercise),
|
||||
child: Text(AppLocalizations.of(context)!.addExercise),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newSet,
|
||||
AppLocalizations.of(context)!.newSet,
|
||||
SetFormWidget(widget._day),
|
||||
scrollControlled: true,
|
||||
);
|
||||
@@ -174,14 +174,12 @@ class DayHeaderDismissible extends StatelessWidget {
|
||||
final _toggle;
|
||||
|
||||
const DayHeaderDismissible({
|
||||
Key key,
|
||||
@required Day day,
|
||||
@required bool expanded,
|
||||
@required Function toggle,
|
||||
}) : _day = day,
|
||||
required Day day,
|
||||
required bool expanded,
|
||||
required Function toggle,
|
||||
}) : _day = day,
|
||||
_expanded = expanded,
|
||||
_toggle = toggle,
|
||||
super(key: key);
|
||||
_toggle = toggle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -254,7 +252,7 @@ class DayHeaderDismissible extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).gymMode,
|
||||
AppLocalizations.of(context)!.gymMode,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
Icon(
|
||||
@@ -273,7 +271,7 @@ class DayHeaderDismissible extends StatelessWidget {
|
||||
content: Text('Would open weight log form for this day'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).dismiss),
|
||||
child: Text(AppLocalizations.of(context)!.dismiss),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -20,10 +20,9 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class ExerciseImage extends StatelessWidget {
|
||||
const ExerciseImage({
|
||||
Key key,
|
||||
@required this.imageUrl,
|
||||
@required this.serverUrl,
|
||||
}) : super(key: key);
|
||||
required this.imageUrl,
|
||||
required this.serverUrl,
|
||||
});
|
||||
|
||||
final String imageUrl;
|
||||
final String serverUrl;
|
||||
|
||||
@@ -37,46 +37,43 @@ class WorkoutForm extends StatelessWidget {
|
||||
WorkoutPlan _plan;
|
||||
final _form = GlobalKey<FormState>();
|
||||
|
||||
WorkoutForm(
|
||||
this._plan, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
WorkoutForm(this._plan);
|
||||
|
||||
final TextEditingController workoutController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
workoutController.text = _plan.description ?? '';
|
||||
workoutController.text = _plan.description;
|
||||
|
||||
return Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.description),
|
||||
controller: workoutController,
|
||||
validator: (value) {
|
||||
const minLength = 5;
|
||||
const maxLength = 100;
|
||||
if (value.isEmpty || value.length < minLength || value.length > maxLength) {
|
||||
if (value!.isEmpty || value.length < minLength || value.length > maxLength) {
|
||||
return 'Please enter between $minLength and $maxLength characters.';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_plan.description = newValue;
|
||||
_plan.description = newValue!;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
// Validate and save
|
||||
final isValid = _form.currentState.validate();
|
||||
final isValid = _form.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
// Save to DB
|
||||
final workout = _plan.id != null
|
||||
@@ -112,9 +109,9 @@ class _DayCheckboxState extends State<DayCheckbox> {
|
||||
return CheckboxListTile(
|
||||
title: Text(widget._day.getDayName(widget._dayNr)),
|
||||
value: _isSelected,
|
||||
onChanged: (bool newValue) {
|
||||
onChanged: (bool? newValue) {
|
||||
setState(() {
|
||||
_isSelected = newValue;
|
||||
_isSelected = newValue!;
|
||||
if (!newValue) {
|
||||
widget._day.daysOfWeek.remove(widget._dayNr);
|
||||
} else {
|
||||
@@ -129,15 +126,11 @@ class _DayCheckboxState extends State<DayCheckbox> {
|
||||
class DayFormWidget extends StatefulWidget {
|
||||
final WorkoutPlan workout;
|
||||
final dayController = TextEditingController();
|
||||
Day _day;
|
||||
Day _day = Day();
|
||||
|
||||
DayFormWidget({
|
||||
@required this.workout,
|
||||
day,
|
||||
}) {
|
||||
DayFormWidget(this.workout, [Day? day]) {
|
||||
this._day = day ?? Day();
|
||||
_day.workout = this.workout;
|
||||
_day.workoutId = this.workout.id;
|
||||
_day.workoutId = this.workout.id!;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -156,15 +149,15 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.description),
|
||||
controller: widget.dayController,
|
||||
onSaved: (value) {
|
||||
widget._day.description = value;
|
||||
widget._day.description = value!;
|
||||
},
|
||||
validator: (value) {
|
||||
const minLength = 5;
|
||||
const maxLength = 100;
|
||||
if (value.isEmpty || value.length < minLength || value.length > maxLength) {
|
||||
if (value!.isEmpty || value.length < minLength || value.length > maxLength) {
|
||||
return 'Please enter between $minLength and $maxLength characters.';
|
||||
}
|
||||
return null;
|
||||
@@ -174,12 +167,12 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
Text('Week days'),
|
||||
...Day.weekdays.keys.map((dayNr) => DayCheckbox(dayNr, widget._day)).toList(),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
if (!_form.currentState.validate()) {
|
||||
if (!_form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
try {
|
||||
Provider.of<WorkoutPlans>(context, listen: false).addDay(
|
||||
@@ -217,11 +210,11 @@ class _DayFormWidgetState extends State<DayFormWidget> {
|
||||
|
||||
class SetFormWidget extends StatefulWidget {
|
||||
Day _day;
|
||||
Set _set;
|
||||
Set _set = Set();
|
||||
|
||||
SetFormWidget(Day day, [Set set]) {
|
||||
this._day = day;
|
||||
this._set = set ?? Set(day: day.id, sets: 4);
|
||||
SetFormWidget(Day this._day, [Set? set]) {
|
||||
//this._day = day;
|
||||
this._set = set ?? Set.withData(day: _day.id, sets: 4);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -261,7 +254,7 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
textFieldConfiguration: TextFieldConfiguration(
|
||||
controller: this._exercisesController,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).exercise,
|
||||
labelText: AppLocalizations.of(context)!.exercise,
|
||||
helperMaxLines: 3,
|
||||
helperText: 'You can search for more than one exercise, they will be grouped '
|
||||
'together for a superset.'),
|
||||
@@ -270,35 +263,36 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
return await Provider.of<Exercises>(context, listen: false).searchExercise(pattern);
|
||||
},
|
||||
itemBuilder: (context, suggestion) {
|
||||
// TODO: this won't work if the server uses e.g. AWS to serve
|
||||
// the static files
|
||||
String serverUrl = Provider.of<Auth>(context, listen: false).serverUrl;
|
||||
final exercise = Provider.of<Exercises>(context, listen: false)
|
||||
.findById(suggestion['data']['id']);
|
||||
final result = suggestion! as Map;
|
||||
|
||||
String serverUrl = Provider.of<Auth>(context, listen: false).serverUrl!;
|
||||
final exercise =
|
||||
Provider.of<Exercises>(context, listen: false).findById(result['data']['id']);
|
||||
return ListTile(
|
||||
leading: Container(
|
||||
width: 45,
|
||||
child: suggestion['data']['image'] != null
|
||||
child: result['data']['image'] != null
|
||||
? ExerciseImage(
|
||||
imageUrl: suggestion['data']['image'],
|
||||
imageUrl: result['data']['image'],
|
||||
serverUrl: serverUrl,
|
||||
)
|
||||
: Container(),
|
||||
),
|
||||
title: Text(exercise.name),
|
||||
subtitle: Text(exercise.category.name),
|
||||
subtitle: Text(exercise.categoryObj.name),
|
||||
);
|
||||
},
|
||||
transitionBuilder: (context, suggestionsBox, controller) {
|
||||
return suggestionsBox;
|
||||
},
|
||||
onSuggestionSelected: (suggestion) {
|
||||
final exercise = Provider.of<Exercises>(context, listen: false)
|
||||
.findById(suggestion['data']['id']);
|
||||
final result = suggestion! as Map;
|
||||
final exercise =
|
||||
Provider.of<Exercises>(context, listen: false).findById(result['data']['id']);
|
||||
addExercise(exercise);
|
||||
},
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
if (value!.isEmpty) {
|
||||
return 'Please select an exercise';
|
||||
}
|
||||
return null;
|
||||
@@ -320,7 +314,9 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
widget._set.settings = [];
|
||||
for (var exercise in widget._set.exercisesObj) {
|
||||
for (int loop = 0; loop < widget._set.sets; loop++) {
|
||||
widget._set.settings.add(Setting(exerciseObj: exercise));
|
||||
Setting setting = Setting();
|
||||
setting.exerciseObj = exercise;
|
||||
widget._set.settings.add(setting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,13 +356,13 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
final isValid = _formKey.currentState.validate();
|
||||
final isValid = _formKey.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_formKey.currentState.save();
|
||||
_formKey.currentState!.save();
|
||||
|
||||
final workoutProvider = Provider.of<WorkoutPlans>(context, listen: false);
|
||||
|
||||
@@ -379,11 +375,12 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
|
||||
// Save remaining settings
|
||||
for (var setting in widget._set.settings) {
|
||||
setting.setId = setDb.id;
|
||||
setting.setId = setDb.id!;
|
||||
|
||||
setting.weightUnit = setting.weightUnit ?? workoutProvider.defaultWeightUnit.id;
|
||||
setting.repetitionUnit =
|
||||
setting.repetitionUnit ?? workoutProvider.defaultRepetitionUnit.id;
|
||||
setting.weightUnitId = workoutProvider.defaultWeightUnit.id;
|
||||
//setting.weightUnitId ?? workoutProvider.defaultWeightUnit.id;
|
||||
setting.repetitionUnitId = workoutProvider.defaultRepetitionUnit.id;
|
||||
//setting.repetitionUnitId ?? workoutProvider.defaultRepetitionUnit.id;
|
||||
setting.comment = '';
|
||||
setting.repsText = 'temp text';
|
||||
|
||||
@@ -406,18 +403,19 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
|
||||
class ExerciseSetting extends StatelessWidget {
|
||||
Exercise _exercise;
|
||||
int _numberOfSets;
|
||||
int _numberOfSets = 4;
|
||||
bool _detailed;
|
||||
Function removeExercise;
|
||||
List<Setting> _settings = [];
|
||||
|
||||
ExerciseSetting(Exercise exercise, List<Setting> settings, bool expanded, double sliderValue,
|
||||
removeExercise) {
|
||||
this._exercise = exercise;
|
||||
this._settings = settings;
|
||||
this._detailed = expanded;
|
||||
ExerciseSetting(
|
||||
this._exercise,
|
||||
this._settings,
|
||||
this._detailed,
|
||||
double sliderValue,
|
||||
this.removeExercise,
|
||||
) {
|
||||
this._numberOfSets = sliderValue.round();
|
||||
this.removeExercise = removeExercise;
|
||||
}
|
||||
|
||||
Widget getRow() {
|
||||
@@ -478,9 +476,7 @@ class RepsInputWidget extends StatelessWidget {
|
||||
final _repsController = TextEditingController();
|
||||
Setting _setting;
|
||||
|
||||
RepsInputWidget(Setting setting) {
|
||||
this._setting = setting;
|
||||
}
|
||||
RepsInputWidget(this._setting);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -503,9 +499,7 @@ class WeightInputWidget extends StatelessWidget {
|
||||
final _weightController = TextEditingController();
|
||||
Setting _setting;
|
||||
|
||||
WeightInputWidget(Setting setting) {
|
||||
this._setting = setting;
|
||||
}
|
||||
WeightInputWidget(this._setting);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -525,7 +519,7 @@ class WeightInputWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
class RiRInputWidget extends StatefulWidget {
|
||||
RiRInputWidget({Key key}) : super(key: key);
|
||||
RiRInputWidget();
|
||||
|
||||
@override
|
||||
_RiRInputWidgetState createState() => _RiRInputWidgetState();
|
||||
@@ -542,9 +536,9 @@ class _RiRInputWidgetState extends State<RiRInputWidget> {
|
||||
height: 0,
|
||||
//color: Colors.deepPurpleAccent,
|
||||
),
|
||||
onChanged: (String newValue) {
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
dropdownValue = newValue;
|
||||
dropdownValue = newValue!;
|
||||
});
|
||||
},
|
||||
items: <String>['1', '1.5', '2', '2.5', '3', '3.5']
|
||||
@@ -559,14 +553,14 @@ class _RiRInputWidgetState extends State<RiRInputWidget> {
|
||||
}
|
||||
|
||||
class WeightUnitInputWidget extends StatefulWidget {
|
||||
WeightUnitInputWidget({Key key}) : super(key: key);
|
||||
WeightUnitInputWidget({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_WeightUnitInputWidgetState createState() => _WeightUnitInputWidgetState();
|
||||
}
|
||||
|
||||
class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
WeightUnit dropdownValue;
|
||||
late WeightUnit dropdownValue;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -576,9 +570,9 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
height: 0,
|
||||
// color: Colors.deepPurpleAccent,
|
||||
),
|
||||
onChanged: (WeightUnit newValue) {
|
||||
onChanged: (WeightUnit? newValue) {
|
||||
setState(() {
|
||||
dropdownValue = newValue;
|
||||
dropdownValue = newValue!;
|
||||
});
|
||||
},
|
||||
items: Provider.of<WorkoutPlans>(context, listen: false)
|
||||
@@ -597,14 +591,14 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
}
|
||||
|
||||
class RepetitionUnitInputWidget extends StatefulWidget {
|
||||
RepetitionUnitInputWidget({Key key}) : super(key: key);
|
||||
RepetitionUnitInputWidget();
|
||||
|
||||
@override
|
||||
_RepetitionUnitInputWidgetState createState() => _RepetitionUnitInputWidgetState();
|
||||
}
|
||||
|
||||
class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
|
||||
RepetitionUnit dropdownValue;
|
||||
late RepetitionUnit dropdownValue;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -614,9 +608,9 @@ class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
|
||||
height: 0,
|
||||
// color: Colors.deepPurpleAccent,
|
||||
),
|
||||
onChanged: (RepetitionUnit newValue) {
|
||||
onChanged: (RepetitionUnit? newValue) {
|
||||
setState(() {
|
||||
dropdownValue = newValue;
|
||||
dropdownValue = newValue!;
|
||||
});
|
||||
},
|
||||
items: Provider.of<WorkoutPlans>(context, listen: false)
|
||||
|
||||
@@ -104,7 +104,7 @@ class StartPage extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).todaysWorkout,
|
||||
AppLocalizations.of(context)!.todaysWorkout,
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
),
|
||||
@@ -165,7 +165,7 @@ class LogPage extends StatelessWidget {
|
||||
|
||||
_log.date = DateTime.now();
|
||||
_log.exercise = _exercise.id;
|
||||
_log.workoutPlan = _workoutPlan.id;
|
||||
_log.workoutPlan = _workoutPlan.id!;
|
||||
_log.repetitionUnit = 1;
|
||||
_log.weightUnit = 1;
|
||||
}
|
||||
@@ -191,33 +191,33 @@ class LogPage extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).repetitions),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.repetitions),
|
||||
controller: _repsController,
|
||||
keyboardType: TextInputType.number,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_log.reps = int.parse(newValue);
|
||||
_log.reps = int.parse(newValue!);
|
||||
},
|
||||
validator: (value) {
|
||||
try {
|
||||
double.parse(value);
|
||||
double.parse(value!);
|
||||
} catch (error) {
|
||||
return AppLocalizations.of(context).enterValidNumber;
|
||||
return AppLocalizations.of(context)!.enterValidNumber;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.weight),
|
||||
controller: _weightController,
|
||||
keyboardType: TextInputType.number,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_log.weight = double.parse(newValue);
|
||||
_log.weight = double.parse(newValue!);
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).rir),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.rir),
|
||||
controller: _rirController,
|
||||
keyboardType: TextInputType.number,
|
||||
onFieldSubmitted: (_) {},
|
||||
@@ -225,7 +225,7 @@ class LogPage extends StatelessWidget {
|
||||
),
|
||||
/*
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).comment),
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.comment),
|
||||
controller: _commentController,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: 3,
|
||||
@@ -237,14 +237,14 @@ class LogPage extends StatelessWidget {
|
||||
|
||||
*/
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
// Validate and save the current values to the weightEntry
|
||||
final isValid = _form.currentState.validate();
|
||||
final isValid = _form.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
@@ -345,15 +345,15 @@ class _SessionPageState extends State<SessionPage> {
|
||||
builder: (FormFieldState<int> state) {
|
||||
return InputDecorator(
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).impression,
|
||||
labelText: AppLocalizations.of(context)!.impression,
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<int>(
|
||||
value: impressionValue,
|
||||
isDense: true,
|
||||
onChanged: (int newValue) {
|
||||
onChanged: (int? newValue) {
|
||||
setState(() {
|
||||
impressionValue = newValue;
|
||||
impressionValue = newValue!;
|
||||
state.didChange(newValue);
|
||||
});
|
||||
},
|
||||
@@ -361,7 +361,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
return DropdownMenuItem<int>(
|
||||
value: key,
|
||||
child: Text(
|
||||
ImpressionMap[key],
|
||||
ImpressionMap[key]!,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
@@ -372,14 +372,14 @@ class _SessionPageState extends State<SessionPage> {
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).notes,
|
||||
labelText: AppLocalizations.of(context)!.notes,
|
||||
),
|
||||
maxLines: 3,
|
||||
controller: notesController,
|
||||
keyboardType: TextInputType.multiline,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {
|
||||
_session.notes = newValue;
|
||||
_session.notes = newValue!;
|
||||
},
|
||||
),
|
||||
Row(
|
||||
@@ -387,7 +387,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
Flexible(
|
||||
child: TextFormField(
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).timeStart),
|
||||
InputDecoration(labelText: AppLocalizations.of(context)!.timeStart),
|
||||
controller: timeStartController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
@@ -396,7 +396,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
Flexible(
|
||||
child: TextFormField(
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).timeEnd),
|
||||
InputDecoration(labelText: AppLocalizations.of(context)!.timeEnd),
|
||||
controller: timeEndController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
@@ -405,21 +405,20 @@ class _SessionPageState extends State<SessionPage> {
|
||||
],
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
child: Text(AppLocalizations.of(context)!.save),
|
||||
onPressed: () async {
|
||||
// Validate and save the current values to the weightEntry
|
||||
final isValid = _form.currentState.validate();
|
||||
final isValid = _form.currentState!.validate();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
_form.currentState.save();
|
||||
_form.currentState!.save();
|
||||
_session.date = DateTime.now();
|
||||
_session.workoutId = widget._workoutPlan.id;
|
||||
_session.workoutId = widget._workoutPlan.id!;
|
||||
_session.impression = impressionValue;
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
print(_session.toJson());
|
||||
await Provider.of<WorkoutPlans>(context, listen: false).addSession(_session);
|
||||
Navigator.of(context).pop();
|
||||
} on WgerHttpException catch (error) {
|
||||
@@ -456,7 +455,7 @@ class TimerWidget extends StatefulWidget {
|
||||
class _TimerWidgetState extends State<TimerWidget> {
|
||||
// See https://stackoverflow.com/questions/54610121/flutter-countdown-timer
|
||||
|
||||
Timer _timer;
|
||||
Timer? _timer;
|
||||
int _seconds = 1;
|
||||
final _maxSeconds = 600;
|
||||
DateTime today = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||
|
||||
@@ -36,8 +36,8 @@ class ExerciseLog extends StatelessWidget {
|
||||
final _workoutPlansData = Provider.of<WorkoutPlans>(context, listen: false);
|
||||
final _workout = _workoutPlansData.currentPlan;
|
||||
|
||||
Future<dynamic> _getChartEntries(BuildContext context) async {
|
||||
return await _workoutPlansData.fetchLogData(_workout, _exercise);
|
||||
Future<Map<String, dynamic>> _getChartEntries(BuildContext context) async {
|
||||
return await _workoutPlansData.fetchLogData(_workout!, _exercise);
|
||||
}
|
||||
|
||||
return Column(
|
||||
@@ -48,54 +48,55 @@ class ExerciseLog extends StatelessWidget {
|
||||
),
|
||||
FutureBuilder(
|
||||
future: _getChartEntries(context),
|
||||
builder: (context, snapshot) => snapshot.connectionState == ConnectionState.waiting
|
||||
? Container(
|
||||
height: 120,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
Container(
|
||||
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) =>
|
||||
snapshot.connectionState == ConnectionState.waiting
|
||||
? Container(
|
||||
height: 120,
|
||||
child: LogChartWidget(snapshot.data),
|
||||
),
|
||||
const Padding(padding: EdgeInsets.symmetric(vertical: 5)),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
...snapshot.data['logs'].entries.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${DateFormat.yMd().format(DateTime.parse(e.key))}',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 120,
|
||||
child: LogChartWidget(snapshot.data),
|
||||
),
|
||||
const Padding(padding: EdgeInsets.symmetric(vertical: 5)),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
...snapshot.data!['logs']!.entries.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${DateFormat.yMd().format(DateTime.parse(e.key))}',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
...e.value.map((i) {
|
||||
return Text("${i['weight']} - ${i['reps']}");
|
||||
})
|
||||
],
|
||||
),
|
||||
...e.value.map((i) {
|
||||
return Text("${i['weight']} - ${i['reps']}");
|
||||
})
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Text(AppLocalizations.of(context).amount),
|
||||
Text(AppLocalizations.of(context).unit),
|
||||
Text(AppLocalizations.of(context).weight),
|
||||
Text(AppLocalizations.of(context).unit),
|
||||
Text(AppLocalizations.of(context).rir),
|
||||
Text(AppLocalizations.of(context)!.amount),
|
||||
Text(AppLocalizations.of(context)!.unit),
|
||||
Text(AppLocalizations.of(context)!.weight),
|
||||
Text(AppLocalizations.of(context)!.unit),
|
||||
Text(AppLocalizations.of(context)!.rir),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -61,14 +61,14 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).logHelpEntries,
|
||||
AppLocalizations.of(context)!.logHelpEntries,
|
||||
textAlign: TextAlign.justify,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).logHelpEntriesUnits,
|
||||
AppLocalizations.of(context)!.logHelpEntriesUnits,
|
||||
textAlign: TextAlign.justify,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -57,12 +57,12 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
|
||||
Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).add),
|
||||
child: Text(AppLocalizations.of(context)!.add),
|
||||
onPressed: () {
|
||||
showFormBottomSheet(
|
||||
context,
|
||||
AppLocalizations.of(context).newDay,
|
||||
DayFormWidget(workout: widget._workoutPlan),
|
||||
AppLocalizations.of(context)!.newDay,
|
||||
DayFormWidget(widget._workoutPlan),
|
||||
scrollControlled: true,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -44,22 +44,22 @@ class WorkoutPlansList extends StatelessWidget {
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).confirmDelete(currentWorkout.description),
|
||||
AppLocalizations.of(context)!.confirmDelete(currentWorkout.description),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).cancel),
|
||||
child: Text(AppLocalizations.of(context)!.cancel),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
AppLocalizations.of(context)!.delete,
|
||||
style: TextStyle(color: Theme.of(context).errorColor),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the workout
|
||||
Provider.of<WorkoutPlans>(context, listen: false)
|
||||
.deleteWorkout(currentWorkout.id);
|
||||
.deleteWorkout(currentWorkout.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
@@ -68,7 +68,7 @@ class WorkoutPlansList extends StatelessWidget {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
AppLocalizations.of(context)!.successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -97,9 +97,9 @@ class WorkoutPlansList extends StatelessWidget {
|
||||
child: Card(
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
_workoutProvider.setCurrentPlan(currentWorkout.id);
|
||||
_workoutProvider.setCurrentPlan(currentWorkout.id!);
|
||||
|
||||
return Navigator.of(context)
|
||||
Navigator.of(context)
|
||||
.pushNamed(WorkoutPlanScreen.routeName, arguments: currentWorkout);
|
||||
},
|
||||
title: Text(currentWorkout.description),
|
||||
|
||||
34
pubspec.lock
34
pubspec.lock
@@ -7,14 +7,14 @@ packages:
|
||||
name: _fe_analyzer_shared
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "18.0.0"
|
||||
version: "19.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "1.3.0"
|
||||
android_metadata:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -105,7 +105,7 @@ packages:
|
||||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.0.3"
|
||||
version: "8.0.4"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -163,7 +163,7 @@ packages:
|
||||
source: hosted
|
||||
version: "3.7.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
@@ -236,28 +236,28 @@ packages:
|
||||
name: flutter_calendar_carousel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.3"
|
||||
version: "2.0.0"
|
||||
flutter_keyboard_visibility:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_keyboard_visibility
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.6"
|
||||
version: "5.0.0"
|
||||
flutter_keyboard_visibility_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_keyboard_visibility_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "2.0.0"
|
||||
flutter_keyboard_visibility_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_keyboard_visibility_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "2.0.0"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -281,7 +281,7 @@ packages:
|
||||
name: flutter_typeahead
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "3.1.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -293,7 +293,7 @@ packages:
|
||||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.0.1"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -307,7 +307,7 @@ packages:
|
||||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.0"
|
||||
version: "0.13.1"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -328,7 +328,7 @@ packages:
|
||||
name: image
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
version: "3.0.2"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -356,7 +356,7 @@ packages:
|
||||
name: json_annotation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
version: "4.0.1"
|
||||
json_serializable:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -440,7 +440,7 @@ packages:
|
||||
name: path_provider_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.0.1"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -475,7 +475,7 @@ packages:
|
||||
name: plugin_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
version: "2.0.0"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -489,7 +489,7 @@ packages:
|
||||
name: process
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
version: "4.2.1"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -683,7 +683,7 @@ packages:
|
||||
name: url_launcher_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.0.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
version: 0.1.0+7
|
||||
|
||||
environment:
|
||||
sdk: ">=2.10.0 <3.0.0"
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
@@ -30,15 +30,16 @@ dependencies:
|
||||
intl: ^0.17.0
|
||||
http: ^0.13.0
|
||||
shared_preferences: ^2.0.5
|
||||
flutter_calendar_carousel: ^1.5.3
|
||||
flutter_calendar_carousel: ^2.0.0
|
||||
cupertino_icons: ^1.0.0
|
||||
json_annotation: ^4.0.0
|
||||
url_launcher: ^6.0.2
|
||||
charts_flutter: ^0.10.0
|
||||
flutter_typeahead: ^2.0.0
|
||||
flutter_typeahead: ^3.1.0
|
||||
table_calendar: ^2.3.3
|
||||
package_info: ^2.0.0
|
||||
android_metadata: ^0.1.3
|
||||
collection: ^1.15.0-nullsafety.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@@ -45,7 +45,7 @@ void main() {
|
||||
group('model', () {
|
||||
test('Test the individual values from the model', () {
|
||||
WeightEntry _weightModel;
|
||||
_weightModel = WeightEntry();
|
||||
//_weightModel = WeightEntry();
|
||||
_weightModel = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 10, 01));
|
||||
|
||||
expect(_weightModel.id, 1);
|
||||
|
||||
@@ -34,11 +34,11 @@ void main() {
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
final client = MockClient();
|
||||
when(client.delete(
|
||||
any,
|
||||
any!,
|
||||
headers: anyNamed('headers'),
|
||||
)).thenAnswer((_) async => http.Response('', 200));
|
||||
when(client.post(
|
||||
any,
|
||||
any!,
|
||||
headers: anyNamed('headers'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer(
|
||||
|
||||
Reference in New Issue
Block a user