WT1.1.11 Null-Safe migration
This commit is contained in:
@@ -5,38 +5,36 @@ import 'package:aitrainer_app/model/model_change.dart';
|
||||
import 'package:aitrainer_app/service/customer_exercise_device_service.dart';
|
||||
|
||||
class CustomerExerciseDeviceRepository {
|
||||
List<CustomerExerciseDevice> _devices = List();
|
||||
List<CustomerExerciseDevice> _devices = [];
|
||||
|
||||
List<CustomerExerciseDevice> getDevices() => this._devices;
|
||||
|
||||
void setDevices(List<CustomerExerciseDevice> devices) => this._devices = devices;
|
||||
|
||||
Future<List<CustomerExerciseDevice>> getDBDevices() async {
|
||||
Future<List<CustomerExerciseDevice>?> getDBDevices() async {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
final int customerId = Cache().userLoggedIn.customerId;
|
||||
final int customerId = Cache().userLoggedIn!.customerId!;
|
||||
this._devices = await CustomerExerciseDeviceApi().getDevices(customerId);
|
||||
}
|
||||
return this._devices;
|
||||
}
|
||||
|
||||
Future<void> addDevice(ExerciseDevice device) async {
|
||||
CustomerExerciseDevice found;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
_devices = List();
|
||||
}
|
||||
CustomerExerciseDevice? found;
|
||||
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
|
||||
if (found == null) {
|
||||
int customerId;
|
||||
int? customerId;
|
||||
if (Cache().userLoggedIn != null) {
|
||||
customerId = Cache().userLoggedIn.customerId;
|
||||
customerId = Cache().userLoggedIn!.customerId!;
|
||||
}
|
||||
CustomerExerciseDevice newDevice =
|
||||
CustomerExerciseDevice(customerId: customerId, exerciseDeviceId: device.exerciseDeviceId, favourite: false);
|
||||
CustomerExerciseDevice(customerId: customerId!, exerciseDeviceId: device.exerciseDeviceId, favourite: false);
|
||||
newDevice.change = ModelChange.add;
|
||||
CustomerExerciseDevice saved = await CustomerExerciseDeviceApi().addDevice(newDevice);
|
||||
this._devices.add(saved);
|
||||
@@ -45,18 +43,18 @@ class CustomerExerciseDeviceRepository {
|
||||
}
|
||||
|
||||
Future<void> removeDevice(ExerciseDevice device) async {
|
||||
CustomerExerciseDevice found;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
}
|
||||
CustomerExerciseDevice? found;
|
||||
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == device.exerciseDeviceId) {
|
||||
found = element;
|
||||
}
|
||||
});
|
||||
|
||||
if (found != null) {
|
||||
this._devices.remove(found);
|
||||
//if (found.change != ModelChange.add) {
|
||||
await CustomerExerciseDeviceApi().removeDevice(found.customerExerciseDeviceId);
|
||||
await CustomerExerciseDeviceApi().removeDevice(found!.customerExerciseDeviceId!);
|
||||
//}
|
||||
Cache().setCustomerDevices(_devices);
|
||||
}
|
||||
@@ -64,13 +62,13 @@ class CustomerExerciseDeviceRepository {
|
||||
|
||||
bool hasDevice(int exerciseDeviceId) {
|
||||
bool found = false;
|
||||
if (_devices != null) {
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == exerciseDeviceId) {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._devices.forEach((element) {
|
||||
if (element.exerciseDeviceId == exerciseDeviceId) {
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ class GenderItem {
|
||||
}
|
||||
|
||||
class CustomerRepository with Logging {
|
||||
Customer customer;
|
||||
Customer _trainee;
|
||||
List<Customer> _trainees;
|
||||
List<CustomerProperty> _allProperties;
|
||||
late Customer customer;
|
||||
late Customer? _trainee;
|
||||
List<Customer>? _trainees;
|
||||
List<CustomerProperty>? _allProperties;
|
||||
final PropertyRepository propertyRepository = PropertyRepository();
|
||||
final List<Property> womanSizes = List();
|
||||
final List<Property> manSizes = List();
|
||||
final List<Property> womanSizes = [];
|
||||
final List<Property> manSizes = [];
|
||||
|
||||
final double baseWidth = 312;
|
||||
final double baseHeight = 675.2;
|
||||
@@ -37,18 +37,18 @@ class CustomerRepository with Logging {
|
||||
|
||||
//List<CustomerRepository> customerList = List<CustomerRepository>();
|
||||
bool visibleDetails = false;
|
||||
List<GenderItem> genders;
|
||||
late List<GenderItem> genders;
|
||||
|
||||
CustomerRepository({this.customer}) {
|
||||
CustomerRepository() {
|
||||
customer = Customer();
|
||||
|
||||
if (Cache().userLoggedIn != null) {
|
||||
isMan = (Cache().userLoggedIn.sex == "m");
|
||||
isMan = (Cache().userLoggedIn!.sex == "m");
|
||||
}
|
||||
}
|
||||
|
||||
String getGenderByName(String name) {
|
||||
String dbValue;
|
||||
String? getGenderByName(String name) {
|
||||
String? dbValue;
|
||||
genders.forEach((element) {
|
||||
if (element.name == name) {
|
||||
dbValue = element.dbValue;
|
||||
@@ -57,8 +57,8 @@ class CustomerRepository with Logging {
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
String getGenderByDBValue(String dbValue) {
|
||||
String name;
|
||||
String? getGenderByDBValue(String dbValue) {
|
||||
String? name;
|
||||
genders.forEach((element) {
|
||||
if (element.dbValue == dbValue) {
|
||||
name = element.name;
|
||||
@@ -67,11 +67,11 @@ class CustomerRepository with Logging {
|
||||
return name;
|
||||
}
|
||||
|
||||
String get name {
|
||||
String? get name {
|
||||
return this.customer.name != null ? this.customer.name : "";
|
||||
}
|
||||
|
||||
String get firstName {
|
||||
String? get firstName {
|
||||
return this.customer.firstname != null ? this.customer.firstname : "";
|
||||
}
|
||||
|
||||
@@ -79,19 +79,19 @@ class CustomerRepository with Logging {
|
||||
return this.customer.sex == "m" ? "Man" : "Woman";
|
||||
}
|
||||
|
||||
int get birthYear {
|
||||
int? get birthYear {
|
||||
return this.customer.birthYear;
|
||||
}
|
||||
|
||||
String get goal {
|
||||
String? get goal {
|
||||
return this.customer.goal;
|
||||
}
|
||||
|
||||
String get fitnessLevel {
|
||||
String? get fitnessLevel {
|
||||
return this.customer.fitnessLevel;
|
||||
}
|
||||
|
||||
String get bodyType {
|
||||
String? get bodyType {
|
||||
return this.customer.bodyType;
|
||||
}
|
||||
|
||||
@@ -128,16 +128,17 @@ class CustomerRepository with Logging {
|
||||
setCustomerProperty(String propertyName, double value, {id = 0}) {
|
||||
if (this.customer.properties[propertyName] == null) {
|
||||
this.customer.properties[propertyName] = CustomerProperty(
|
||||
propertyId: propertyRepository.getPropertyByName("Height").propertyId,
|
||||
customerId: this.customer.customerId,
|
||||
propertyValue: value);
|
||||
propertyId: propertyRepository.getPropertyByName("Height")!.propertyId,
|
||||
customerId: this.customer.customerId!,
|
||||
propertyValue: value,
|
||||
dateAdd: DateTime.now());
|
||||
} else {
|
||||
this.customer.properties[propertyName].propertyValue = value;
|
||||
this.customer.properties[propertyName]!.propertyValue = value;
|
||||
}
|
||||
this.customer.properties[propertyName].dateAdd = DateTime.now();
|
||||
this.customer.properties[propertyName].newData = true;
|
||||
this.customer.properties[propertyName]!.dateAdd = DateTime.now();
|
||||
this.customer.properties[propertyName]!.newData = true;
|
||||
if (id > 0) {
|
||||
this.customer.properties[propertyName].customerPropertyId = id;
|
||||
this.customer.properties[propertyName]!.customerPropertyId = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,14 +151,14 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
double getCustomerPropertyValue(String propertyName) {
|
||||
if (this.customer == null || this.customer.properties == null || this.customer.properties[propertyName] == null) {
|
||||
if (this.customer.properties[propertyName] == null) {
|
||||
return 0.0;
|
||||
} else {
|
||||
return this.customer.properties[propertyName].propertyValue;
|
||||
return this.customer.properties[propertyName]!.propertyValue;
|
||||
}
|
||||
}
|
||||
|
||||
CustomerProperty getCustomerProperty(String propertyName) {
|
||||
CustomerProperty? getCustomerProperty(String propertyName) {
|
||||
return this.customer.properties[propertyName];
|
||||
}
|
||||
|
||||
@@ -210,39 +211,41 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
Future<void> savePropertyByName(String name) async {
|
||||
await Future.forEach(this._allProperties, (element) async {
|
||||
final CustomerProperty customerProperty = element;
|
||||
final Property property = propertyRepository.getPropertyByName(name);
|
||||
if (property.propertyId == customerProperty.propertyId) {
|
||||
await CustomerApi().updateProperty(customerProperty);
|
||||
await Future.forEach(this._allProperties!, (element) async {
|
||||
final CustomerProperty customerProperty = element as CustomerProperty;
|
||||
final Property? property = propertyRepository.getPropertyByName(name);
|
||||
if (property != null) {
|
||||
if (property.propertyId == customerProperty.propertyId) {
|
||||
await CustomerApi().updateProperty(customerProperty);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<Customer> getTraineeAsCustomer() async {
|
||||
this._trainee = await CustomerApi().getTrainee(Cache().userLoggedIn.customerId);
|
||||
Future<Customer?> getTraineeAsCustomer() async {
|
||||
this._trainee = await CustomerApi().getTrainee(Cache().userLoggedIn!.customerId!);
|
||||
return _trainee;
|
||||
}
|
||||
|
||||
Future<List<Customer>> getTrainees() async {
|
||||
int trainerId = Cache().userLoggedIn.customerId;
|
||||
Future<List<Customer?>?> getTrainees() async {
|
||||
int trainerId = Cache().userLoggedIn!.customerId!;
|
||||
final results = await CustomerApi().getTrainees(trainerId);
|
||||
this._trainees = results;
|
||||
return results;
|
||||
}
|
||||
|
||||
Future<List<CustomerProperty>> getAllCustomerProperties() async {
|
||||
int customerId = Cache().userLoggedIn.customerId;
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
final results = await CustomerApi().getAllProperties(customerId);
|
||||
this._allProperties = results;
|
||||
return results;
|
||||
}
|
||||
|
||||
List<CustomerProperty> getAllProperties() {
|
||||
List<CustomerProperty>? getAllProperties() {
|
||||
return this._allProperties;
|
||||
}
|
||||
|
||||
List<Customer> getTraineesList() {
|
||||
List<Customer>? getTraineesList() {
|
||||
return _trainees;
|
||||
}
|
||||
|
||||
@@ -250,7 +253,7 @@ class CustomerRepository with Logging {
|
||||
if (_trainees == null) {
|
||||
return;
|
||||
}
|
||||
_trainees.forEach((element) {
|
||||
_trainees!.forEach((element) {
|
||||
if (traineeId == element.customerId) {
|
||||
this._trainee = element;
|
||||
}
|
||||
@@ -262,15 +265,15 @@ class CustomerRepository with Logging {
|
||||
_trainee = null;
|
||||
}
|
||||
|
||||
Customer getTrainee() {
|
||||
Customer? getTrainee() {
|
||||
return this._trainee;
|
||||
}
|
||||
|
||||
Customer getTraineeById(int customerId) {
|
||||
Customer? getTraineeById(int customerId) {
|
||||
if (_trainees == null) {
|
||||
return null;
|
||||
}
|
||||
_trainees.forEach((element) {
|
||||
_trainees!.forEach((element) {
|
||||
if (customerId == element.customerId) {
|
||||
this._trainee = element;
|
||||
}
|
||||
@@ -279,7 +282,7 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
Future<List<Purchase>> getPurchase() async {
|
||||
int customerId = Cache().userLoggedIn.customerId;
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
List<Purchase> purchases = await PurchaseApi().getPurchasesByCustomer(customerId);
|
||||
return purchases;
|
||||
}
|
||||
@@ -289,9 +292,9 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
Future<List<ProductTest>> getProductTests() async {
|
||||
List<ProductTest> tests = List();
|
||||
List<ProductTest> tests = [];
|
||||
try {
|
||||
int customerId = Cache().userLoggedIn.customerId;
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
tests = await ProductTestApi().getProductTestByCustomer(customerId);
|
||||
} on NotFoundException catch (_) {
|
||||
log("Product Tests not found");
|
||||
@@ -314,7 +317,7 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
void addSizes(String sex) {
|
||||
List<Property> properties = Cache().getProperties();
|
||||
List<Property>? properties = Cache().getProperties();
|
||||
if (properties == null) {
|
||||
return;
|
||||
}
|
||||
@@ -451,8 +454,8 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
}
|
||||
|
||||
int getWeightCoordinate(isMan, {isTop = false, isLeft = false}) {
|
||||
int value = 0;
|
||||
int? getWeightCoordinate(isMan, {isTop = false, isLeft = false}) {
|
||||
int? value = 0;
|
||||
this.manSizes.forEach((element) {
|
||||
if (element.propertyName == SizesEnum.Weight.toStr()) {
|
||||
if (isTop == true) {
|
||||
@@ -465,8 +468,8 @@ class CustomerRepository with Logging {
|
||||
return value;
|
||||
}
|
||||
|
||||
Property getPropertyByName(String propertyName) {
|
||||
Property property;
|
||||
Property? getPropertyByName(String propertyName) {
|
||||
Property? property;
|
||||
List<Property> sizes;
|
||||
if (this.sex == "m") {
|
||||
sizes = this.manSizes;
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/service/exercise_device_service.dart';
|
||||
|
||||
class ExerciseDeviceRepository {
|
||||
List<ExerciseDevice> _devices = List();
|
||||
List<ExerciseDevice> _devices = [];
|
||||
|
||||
List<ExerciseDevice> getDevices() {
|
||||
return this._devices;
|
||||
@@ -37,9 +37,9 @@ class ExerciseDeviceRepository {
|
||||
}
|
||||
|
||||
List<ExerciseDevice> getGymDevices() {
|
||||
final List<ExerciseDevice> gymDevices = List();
|
||||
if (_devices == null || _devices.isEmpty) {
|
||||
_devices = Cache().getDevices();
|
||||
final List<ExerciseDevice> gymDevices = [];
|
||||
if (_devices.isEmpty) {
|
||||
_devices = Cache().getDevices()!;
|
||||
}
|
||||
_devices.forEach((element) {
|
||||
if (isGymElement(element.name)) {
|
||||
|
||||
@@ -9,10 +9,10 @@ import 'package:aitrainer_app/service/exercise_plan_service.dart';
|
||||
|
||||
class ExercisePlanRepository {
|
||||
bool newPlan = true;
|
||||
ExercisePlan exercisePlan;
|
||||
ExercisePlan? exercisePlan;
|
||||
LinkedHashMap<int, ExercisePlanDetail> exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
int customerId = 0;
|
||||
ExercisePlanDetail actualPlanDetail;
|
||||
ExercisePlanDetail? actualPlanDetail;
|
||||
|
||||
void setCustomerId(int customerId) {
|
||||
this.customerId = customerId;
|
||||
@@ -24,41 +24,41 @@ class ExercisePlanRepository {
|
||||
this.exercisePlan = plan;
|
||||
}
|
||||
|
||||
ExercisePlan getExercisePlan() => exercisePlan;
|
||||
ExercisePlan? getExercisePlan() => exercisePlan;
|
||||
|
||||
void addDetailToPlan() {
|
||||
if (exercisePlan != null) {
|
||||
actualPlanDetail.exercisePlanId = exercisePlan.exercisePlanId;
|
||||
if (exercisePlan != null && actualPlanDetail != null) {
|
||||
actualPlanDetail!.exercisePlanId = exercisePlan!.exercisePlanId!;
|
||||
exercisePlanDetails[actualPlanDetail!.exerciseTypeId] = actualPlanDetail!;
|
||||
Cache().addToMyExercisePlanDetails(actualPlanDetail!);
|
||||
}
|
||||
exercisePlanDetails[actualPlanDetail.exerciseTypeId] = actualPlanDetail;
|
||||
Cache().addToMyExercisePlanDetails(actualPlanDetail);
|
||||
}
|
||||
|
||||
ExercisePlanDetail getExercisePlanDetailByExerciseId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId];
|
||||
ExercisePlanDetail? getExercisePlanDetailByExerciseId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId];
|
||||
|
||||
void setActualPlanDetailByExerciseType(ExerciseType exerciseType) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
ExercisePlanDetail? detail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
if (detail != null) {
|
||||
actualPlanDetail = detail;
|
||||
} else {
|
||||
actualPlanDetail = ExercisePlanDetail(exerciseType.exerciseTypeId);
|
||||
}
|
||||
actualPlanDetail.exerciseType = exerciseType;
|
||||
actualPlanDetail!.exerciseType = exerciseType;
|
||||
}
|
||||
|
||||
ExercisePlanDetail getActualPlanDetail() => actualPlanDetail;
|
||||
ExercisePlanDetail? getActualPlanDetail() => actualPlanDetail;
|
||||
|
||||
void setActualPlanDetail(ExercisePlanDetail detail) {
|
||||
this.actualPlanDetail = detail;
|
||||
}
|
||||
|
||||
int getPlanDetailId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId].exercisePlanDetailId;
|
||||
int getPlanDetailId(int exerciseTypeId) => exercisePlanDetails[exerciseTypeId]!.exercisePlanDetailId!;
|
||||
|
||||
String getPlanDetail(int exerciseTypeId) {
|
||||
ExercisePlanDetail detail = exercisePlanDetails[exerciseTypeId];
|
||||
ExercisePlanDetail? detail = exercisePlanDetails[exerciseTypeId];
|
||||
String detailString = "";
|
||||
if (detail != null) {
|
||||
detailString = detail.serie.toString() + "x" + detail.repeats.toString() + " " + detail.weightEquation + "kg";
|
||||
detailString = detail.serie.toString() + "x" + detail.repeats.toString() + " " + detail.weightEquation! + "kg";
|
||||
}
|
||||
return detailString;
|
||||
}
|
||||
@@ -71,8 +71,8 @@ class ExercisePlanRepository {
|
||||
if (exercisePlanDetails[exerciseType.exerciseTypeId] == null) {
|
||||
return;
|
||||
}
|
||||
ExercisePlanDetail exercisePlanDetail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
exercisePlanDetail.serie = serie;
|
||||
ExercisePlanDetail? exercisePlanDetail = exercisePlanDetails[exerciseType.exerciseTypeId];
|
||||
exercisePlanDetail!.serie = serie;
|
||||
exercisePlanDetail.repeats = repeat;
|
||||
exercisePlanDetail.weightEquation = weight;
|
||||
exercisePlanDetail.change = ModelChange.update;
|
||||
@@ -85,7 +85,7 @@ class ExercisePlanRepository {
|
||||
}
|
||||
|
||||
void removeExerciseTypeFromPlanByExerciseTypeId(int exerciseTypeId) {
|
||||
exercisePlanDetails[exerciseTypeId].change = ModelChange.delete;
|
||||
exercisePlanDetails[exerciseTypeId]!.change = ModelChange.delete;
|
||||
Cache().deleteMyExercisePlanDetailByExerciseTypeId(exerciseTypeId);
|
||||
}
|
||||
|
||||
@@ -96,22 +96,22 @@ class ExercisePlanRepository {
|
||||
}
|
||||
|
||||
String exercisePlanName;
|
||||
if (this.customerId == Cache().userLoggedIn.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn.name + " private";
|
||||
if (this.customerId == Cache().userLoggedIn!.customerId) {
|
||||
exercisePlanName = Cache().userLoggedIn!.name! + " private";
|
||||
} else {
|
||||
exercisePlanName = Cache().getTrainee().name + " " + Cache().getTrainee().firstname + " private";
|
||||
exercisePlanName = Cache().getTrainee()!.name! + " " + Cache().getTrainee()!.firstname! + " private";
|
||||
}
|
||||
|
||||
exercisePlan = ExercisePlan(exercisePlanName, this.customerId);
|
||||
}
|
||||
if (newPlan) {
|
||||
exercisePlan.dateAdd = DateTime.now();
|
||||
exercisePlan.private = true;
|
||||
ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan);
|
||||
exercisePlan!.dateAdd = DateTime.now();
|
||||
exercisePlan!.private = true;
|
||||
ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan!);
|
||||
|
||||
LinkedHashMap<int, ExercisePlanDetail> savedExercisePlanDetails = LinkedHashMap();
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId!;
|
||||
ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail);
|
||||
savedExercisePlanDetails[savedDetail.exerciseTypeId] = savedDetail;
|
||||
});
|
||||
@@ -123,11 +123,11 @@ class ExercisePlanRepository {
|
||||
|
||||
exercisePlanDetails.forEach((exerciseTypeId, exercisePlanDetail) async {
|
||||
if (exercisePlanDetail.change == ModelChange.delete) {
|
||||
await ExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId);
|
||||
await ExercisePlanApi().deleteExercisePlanDetail(exercisePlanDetail.exercisePlanDetailId!);
|
||||
exercisePlanDetail.change = ModelChange.deleted;
|
||||
Cache().deletedMyExercisePlanDetail(exercisePlanDetail);
|
||||
} else if (exercisePlanDetail.change == ModelChange.update) {
|
||||
await ExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId);
|
||||
await ExercisePlanApi().updateExercisePlanDetail(exercisePlanDetail, exercisePlanDetail.exercisePlanDetailId!);
|
||||
Cache().updateMyExercisePlanDetail(exercisePlanDetail);
|
||||
exercisePlanDetail.change = ModelChange.saved;
|
||||
} else if (exercisePlanDetail.change == ModelChange.add) {
|
||||
@@ -139,11 +139,11 @@ class ExercisePlanRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ExercisePlan> getLastExercisePlan() async {
|
||||
Future<ExercisePlan?> getLastExercisePlan() async {
|
||||
if (customerId == 0) {
|
||||
return null;
|
||||
}
|
||||
ExercisePlan myExercisePlan = Cache().getMyExercisePlan();
|
||||
ExercisePlan? myExercisePlan = Cache().getMyExercisePlan();
|
||||
if (myExercisePlan != null) {
|
||||
exercisePlan = myExercisePlan;
|
||||
return myExercisePlan;
|
||||
@@ -151,26 +151,26 @@ class ExercisePlanRepository {
|
||||
|
||||
exercisePlan = await ExercisePlanApi().getLastExercisePlan(customerId);
|
||||
newPlan = (exercisePlan == null);
|
||||
Cache().setMyExercisePlan(exercisePlan);
|
||||
Cache().setMyExercisePlan(exercisePlan!);
|
||||
return exercisePlan;
|
||||
}
|
||||
|
||||
Future<void> getExercisePlanDetails() async {
|
||||
if (exercisePlan == null) {
|
||||
ExercisePlan exercisePlan = await this.getLastExercisePlan();
|
||||
ExercisePlan? exercisePlan = await this.getLastExercisePlan();
|
||||
if (exercisePlan == null) {
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<ExercisePlanDetail> list = List();
|
||||
List<ExercisePlanDetail> list = [];
|
||||
LinkedHashMap<int, ExercisePlanDetail> listCache = Cache().getMyExercisePlanDetails();
|
||||
if (listCache.length > 0) {
|
||||
exercisePlanDetails = listCache;
|
||||
return;
|
||||
} else {
|
||||
list = await ExercisePlanApi().getExercisePlanDetail(exercisePlan.exercisePlanId);
|
||||
list = await ExercisePlanApi().getExercisePlanDetail(exercisePlan!.exercisePlanId!);
|
||||
}
|
||||
|
||||
exercisePlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||
|
||||
@@ -7,15 +7,15 @@ import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class ExerciseRepository {
|
||||
Exercise exercise;
|
||||
Customer customer;
|
||||
ExerciseType exerciseType;
|
||||
List<Exercise> exerciseList;
|
||||
List<Exercise> exerciseLogList = List();
|
||||
List<Exercise> actualExerciseList = List();
|
||||
Exercise? exercise;
|
||||
Customer? customer;
|
||||
ExerciseType? exerciseType;
|
||||
List<Exercise>? exerciseList;
|
||||
List<Exercise>? exerciseLogList = [];
|
||||
List<Exercise>? actualExerciseList = [];
|
||||
|
||||
double rmWendler = 0;
|
||||
double rmMcglothlin = 0;
|
||||
@@ -24,8 +24,8 @@ class ExerciseRepository {
|
||||
double rmOconner = 0;
|
||||
double rmWathen = 0;
|
||||
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
DateTime? start;
|
||||
DateTime? end;
|
||||
|
||||
ExerciseRepository() {
|
||||
this.createNew();
|
||||
@@ -33,14 +33,14 @@ class ExerciseRepository {
|
||||
|
||||
createNew() {
|
||||
this.exercise = Exercise();
|
||||
exercise.dateAdd = DateTime.now();
|
||||
exercise!.dateAdd = DateTime.now();
|
||||
}
|
||||
|
||||
setQuantity(double quantity) {
|
||||
if (this.exercise == null) {
|
||||
this.createNew();
|
||||
}
|
||||
this.exercise.quantity = quantity;
|
||||
this.exercise!.quantity = quantity;
|
||||
}
|
||||
|
||||
setUnitQuantity(double unitQuantity) {
|
||||
@@ -48,7 +48,7 @@ class ExerciseRepository {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.unitQuantity = unitQuantity;
|
||||
this.exercise!.unitQuantity = unitQuantity;
|
||||
}
|
||||
|
||||
setUnit(String unit) {
|
||||
@@ -56,7 +56,7 @@ class ExerciseRepository {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.unit = unit;
|
||||
this.exercise!.unit = unit;
|
||||
}
|
||||
|
||||
setDatetimeExercise(DateTime datetimeExercise) {
|
||||
@@ -64,33 +64,33 @@ class ExerciseRepository {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.dateAdd = datetimeExercise;
|
||||
this.exercise!.dateAdd = datetimeExercise;
|
||||
}
|
||||
|
||||
double get unitQuantity => this.exercise.unitQuantity;
|
||||
double? get unitQuantity => this.exercise!.unitQuantity;
|
||||
|
||||
double get quantity => this.exercise.quantity;
|
||||
double? get quantity => this.exercise!.quantity;
|
||||
|
||||
Exercise getExercise() => this.exercise;
|
||||
Exercise? getExercise() => this.exercise;
|
||||
|
||||
Future<Exercise> addExercise() async {
|
||||
final Exercise modelExercise = this.exercise;
|
||||
modelExercise.customerId = this.customer.customerId;
|
||||
modelExercise.exerciseTypeId = this.exerciseType.exerciseTypeId;
|
||||
if (exerciseType.unitQuantity != "1") {
|
||||
final Exercise modelExercise = this.exercise!;
|
||||
modelExercise.customerId = this.customer!.customerId;
|
||||
modelExercise.exerciseTypeId = this.exerciseType!.exerciseTypeId;
|
||||
if (exerciseType!.unitQuantity != "1") {
|
||||
modelExercise.unitQuantity = null;
|
||||
}
|
||||
|
||||
Exercise copy = modelExercise.copy();
|
||||
this.actualExerciseList.add(copy);
|
||||
this.actualExerciseList!.add(copy);
|
||||
//final int index = this.actualExerciseList.length - 1;
|
||||
//print("$index. actual exercise " + this.actualExerciseList[index].toJson().toString());
|
||||
Exercise savedExercise = await ExerciseApi().addExercise(modelExercise);
|
||||
|
||||
//this.actualExerciseList[index].exerciseId = savedExercise.exerciseId;
|
||||
if (customer.customerId == Cache().userLoggedIn.customerId) {
|
||||
if (customer!.customerId == Cache().userLoggedIn!.customerId) {
|
||||
Cache().addExercise(savedExercise);
|
||||
} else if (Cache().getTrainee() != null && customer.customerId == Cache().getTrainee().customerId) {
|
||||
} else if (Cache().getTrainee() != null && customer!.customerId == Cache().getTrainee()!.customerId) {
|
||||
Cache().addExerciseTrainee(savedExercise);
|
||||
}
|
||||
|
||||
@@ -100,12 +100,12 @@ class ExerciseRepository {
|
||||
void initExercise() {
|
||||
this.createNew();
|
||||
this.exerciseType = exerciseType;
|
||||
this.setUnit(exerciseType.unit);
|
||||
exercise.exerciseTypeId = this.exerciseType.exerciseTypeId;
|
||||
this.setUnit(exerciseType!.unit);
|
||||
exercise!.exerciseTypeId = this.exerciseType!.exerciseTypeId;
|
||||
this.setQuantity(12);
|
||||
this.setUnitQuantity(30);
|
||||
this.exercise.exercisePlanDetailId = 0;
|
||||
exercise.exerciseId = 0;
|
||||
this.exercise!.exercisePlanDetailId = 0;
|
||||
exercise!.exerciseId = 0;
|
||||
this.start = DateTime.now();
|
||||
}
|
||||
|
||||
@@ -121,35 +121,35 @@ class ExerciseRepository {
|
||||
final results = await ExerciseApi().getExercisesByCustomer(customerId);
|
||||
this.exerciseList = results;
|
||||
if (Cache().userLoggedIn != null) {
|
||||
if (customerId == Cache().userLoggedIn.customerId) {
|
||||
Cache().setExercises(exerciseList);
|
||||
} else if (Cache().getTrainee() != null && customerId == Cache().getTrainee().customerId) {
|
||||
Cache().setExercisesTrainee(exerciseList);
|
||||
if (customerId == Cache().userLoggedIn!.customerId) {
|
||||
Cache().setExercises(exerciseList!);
|
||||
} else if (Cache().getTrainee() != null && customerId == Cache().getTrainee()!.customerId) {
|
||||
Cache().setExercisesTrainee(exerciseList!);
|
||||
}
|
||||
}
|
||||
return this.exerciseList;
|
||||
return this.exerciseList!;
|
||||
}
|
||||
|
||||
List<Exercise> getExerciseList() {
|
||||
List<Exercise>? getExerciseList() {
|
||||
this.exerciseList = Cache().getExercises();
|
||||
return this.exerciseList;
|
||||
}
|
||||
|
||||
List<Exercise> getExerciseListTrainee() {
|
||||
List<Exercise>? getExerciseListTrainee() {
|
||||
this.exerciseList = Cache().getExercisesTrainee();
|
||||
return this.exerciseList;
|
||||
}
|
||||
|
||||
String nextMissingBaseExercise(SplayTreeMap sortedTree) {
|
||||
String? nextMissingBaseExercise(SplayTreeMap sortedTree) {
|
||||
if (exerciseList == null) {
|
||||
exerciseList = Cache().getExercises();
|
||||
}
|
||||
|
||||
if (exerciseList == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
String missingTreeName;
|
||||
String foundTreeName;
|
||||
String? missingTreeName;
|
||||
String? foundTreeName;
|
||||
bool isBreak = false;
|
||||
|
||||
sortedTree.forEach((key, list) {
|
||||
@@ -162,13 +162,15 @@ class ExerciseRepository {
|
||||
missingTreeName = treeName;
|
||||
}
|
||||
if (exercise.base) {
|
||||
exerciseList.forEach((element) {
|
||||
if (element.exerciseTypeId == exercise.exerciseTypeId) {
|
||||
foundTreeName = treeName;
|
||||
//print("Found " + foundTreeName + " Missing actual: " + missingTreeName);
|
||||
isBreak = true;
|
||||
}
|
||||
});
|
||||
if (exerciseList != null) {
|
||||
exerciseList!.forEach((element) {
|
||||
if (element.exerciseTypeId == exercise.exerciseTypeId) {
|
||||
foundTreeName = treeName;
|
||||
//print("Found " + foundTreeName + " Missing actual: " + missingTreeName);
|
||||
isBreak = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (foundTreeName == null && !isBreak) {
|
||||
@@ -181,19 +183,19 @@ class ExerciseRepository {
|
||||
}
|
||||
|
||||
void getBaseExerciseFinishedPercent() {
|
||||
List<int> checkedExerciseTypeId = List();
|
||||
List<int> baseTreeItem = List();
|
||||
List<int> checkedBaseTreeItem = List();
|
||||
List<int> checkedExerciseTypeId = [];
|
||||
List<int> baseTreeItem = [];
|
||||
List<int> checkedBaseTreeItem = [];
|
||||
int count1RMExercises = 0;
|
||||
LinkedHashMap<String, WorkoutMenuTree> tree = Cache().getWorkoutMenuTree();
|
||||
|
||||
if (tree == null) {
|
||||
if (tree.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null && treeItem.exerciseType.base == true && !baseTreeItem.contains(treeItem.parent)) {
|
||||
if (treeItem.exerciseType != null && treeItem.exerciseType!.base == true && !baseTreeItem.contains(treeItem.parent)) {
|
||||
baseTreeItem.add(treeItem.parent);
|
||||
}
|
||||
});
|
||||
@@ -206,15 +208,15 @@ class ExerciseRepository {
|
||||
return;
|
||||
}
|
||||
|
||||
exerciseList.forEach((element) {
|
||||
exerciseList!.forEach((element) {
|
||||
Exercise exercise = element;
|
||||
if (!checkedExerciseTypeId.contains(exercise.exerciseTypeId)) {
|
||||
checkedExerciseTypeId.add(exercise.exerciseTypeId);
|
||||
checkedExerciseTypeId.add(exercise.exerciseTypeId!);
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null &&
|
||||
treeItem.exerciseType.base == true &&
|
||||
exercise.exerciseTypeId == treeItem.exerciseType.exerciseTypeId &&
|
||||
treeItem.exerciseType!.base == true &&
|
||||
exercise.exerciseTypeId == treeItem.exerciseType!.exerciseTypeId &&
|
||||
!checkedBaseTreeItem.contains(treeItem.parent)) {
|
||||
//print ("id: " + exercise.exerciseTypeId.toString());
|
||||
checkedBaseTreeItem.add(treeItem.parent);
|
||||
@@ -232,28 +234,33 @@ class ExerciseRepository {
|
||||
}
|
||||
|
||||
void getLastExercise() {
|
||||
List<Exercise> exercises = this.getExerciseList();
|
||||
Exercise lastExercise = exercises[0];
|
||||
exercises.forEach((element) {
|
||||
Exercise actualExercise = element;
|
||||
if (actualExercise.dateAdd.compareTo(lastExercise.dateAdd) > 0) {
|
||||
lastExercise = actualExercise;
|
||||
}
|
||||
});
|
||||
List<Exercise>? exercises = this.getExerciseList();
|
||||
Exercise? lastExercise = exercises == null ? null : exercises[0];
|
||||
if (exercises != null) {
|
||||
exercises.forEach((element) {
|
||||
Exercise actualExercise = element;
|
||||
if (actualExercise.dateAdd!.compareTo(lastExercise!.dateAdd!) > 0) {
|
||||
lastExercise = actualExercise;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.exercise = lastExercise;
|
||||
this.customer = Cache().userLoggedIn;
|
||||
this.exerciseType = getExerciseTypeById(exercise.exerciseTypeId);
|
||||
this.customer = Cache().userLoggedIn!;
|
||||
this.exerciseType = getExerciseTypeById(exercise!.exerciseTypeId!);
|
||||
return;
|
||||
}
|
||||
|
||||
ExerciseType getExerciseTypeById(int exerciseTypeId) {
|
||||
ExerciseType actualExerciseType;
|
||||
Cache().getExerciseTypes().forEach((element) {
|
||||
ExerciseType exerciseType = element;
|
||||
if (exerciseType.exerciseTypeId == exerciseTypeId) {
|
||||
actualExerciseType = exerciseType;
|
||||
}
|
||||
});
|
||||
ExerciseType? getExerciseTypeById(int exerciseTypeId) {
|
||||
ExerciseType? actualExerciseType;
|
||||
List<ExerciseType>? exercises = Cache().getExerciseTypes();
|
||||
if (exercises != null) {
|
||||
exercises.forEach((element) {
|
||||
ExerciseType exerciseType = element;
|
||||
if (exerciseType.exerciseTypeId == exerciseTypeId) {
|
||||
actualExerciseType = exerciseType;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (actualExerciseType == null) {
|
||||
throw Exception("Data error, no ExerciseType for exerciseTypeId $exerciseTypeId");
|
||||
}
|
||||
@@ -261,60 +268,64 @@ class ExerciseRepository {
|
||||
}
|
||||
|
||||
void getSameExercise(int exerciseTypeId, String day) {
|
||||
this.actualExerciseList = List();
|
||||
for (int i = 0; i < this.exerciseList.length; i++) {
|
||||
Exercise exercise = exerciseList[i];
|
||||
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd);
|
||||
if (exerciseTypeId == exercise.exerciseTypeId && exerciseDate == day) {
|
||||
this.actualExerciseList.add(exercise);
|
||||
this.actualExerciseList = [];
|
||||
if (exerciseList != null) {
|
||||
for (int i = 0; i < this.exerciseList!.length; i++) {
|
||||
Exercise exercise = exerciseList![i];
|
||||
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
|
||||
if (exerciseTypeId == exercise.exerciseTypeId && exerciseDate == day) {
|
||||
this.actualExerciseList!.add(exercise);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sortByDate() {
|
||||
if (exerciseList.isEmpty) {
|
||||
if (exerciseList == null || exerciseList!.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
exerciseList.sort((a, b) {
|
||||
final String datePartA = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(a.dateAdd);
|
||||
String aId = a.exerciseTypeId.toString() + "_" + datePartA;
|
||||
final String datePartB = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(b.dateAdd);
|
||||
String bId = b.exerciseTypeId.toString() + "_" + datePartB;
|
||||
return aId.compareTo(bId);
|
||||
exerciseList!.sort((a, b) {
|
||||
final String datePartA = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(a.dateAdd!);
|
||||
String aId = datePartA + "_" + a.exerciseTypeId.toString();
|
||||
final String datePartB = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(b.dateAdd!);
|
||||
String bId = datePartB + "_" + b.exerciseTypeId.toString();
|
||||
return bId.compareTo(aId);
|
||||
});
|
||||
|
||||
this.exerciseLogList = List();
|
||||
this.exerciseLogList = [];
|
||||
String summary = "";
|
||||
|
||||
String prevDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exerciseList[0].dateAdd);
|
||||
int prevExerciseTypeId = exerciseList[0].exerciseTypeId;
|
||||
Exercise prevExercise = exerciseList[0];
|
||||
String prevDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exerciseList![0].dateAdd!);
|
||||
int prevExerciseTypeId = exerciseList![0].exerciseTypeId!;
|
||||
Exercise prevExercise = exerciseList![0];
|
||||
int prevCount = 0;
|
||||
for (int i = 0; i < this.exerciseList.length; i++) {
|
||||
Exercise exercise = exerciseList[i];
|
||||
int exerciseTypeId = exercise.exerciseTypeId;
|
||||
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd);
|
||||
print(" -- $prevExerciseTypeId - '$prevDate' against $exerciseTypeId - '$exerciseDate'");
|
||||
for (int i = 0; i < this.exerciseList!.length; i++) {
|
||||
Exercise exercise = exerciseList![i];
|
||||
int exerciseTypeId = exercise.exerciseTypeId!;
|
||||
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
|
||||
//print(" -- $prevExerciseTypeId - '$prevDate' against $exerciseTypeId - '$exerciseDate'");
|
||||
if (exerciseTypeId != prevExerciseTypeId || prevDate != exerciseDate) {
|
||||
ExerciseType exerciseType = Cache().getExerciseTypeById(prevExercise.exerciseTypeId);
|
||||
String unit = exerciseType.unitQuantityUnit != null ? exerciseType.unitQuantityUnit : prevExercise.unit;
|
||||
ExerciseType? exerciseType = Cache().getExerciseTypeById(prevExercise.exerciseTypeId!);
|
||||
String unit = exerciseType != null && exerciseType.unitQuantityUnit != null ? exerciseType.unitQuantityUnit! : prevExercise.unit!;
|
||||
prevExercise.summary = summary + " " + unit;
|
||||
exerciseLogList.add(prevExercise);
|
||||
exerciseLogList!.add(prevExercise);
|
||||
//print("Log add " + exercise.toJson().toString());
|
||||
summary = "";
|
||||
prevCount = 0;
|
||||
}
|
||||
String delimiter = "";
|
||||
if (prevCount > 0) delimiter = ", ";
|
||||
double quantity = exercise.quantity == null ? 0 : exercise.quantity;
|
||||
double quantity = exercise.quantity == null ? 0 : exercise.quantity!;
|
||||
summary += delimiter + quantity.toStringAsFixed(0);
|
||||
ExerciseType exerciseType = Cache().getExerciseTypeById(exercise.exerciseTypeId);
|
||||
print("exerciseType " + (exerciseType == null ? "NULL" : exerciseType.name) + " ID " + exercise.exerciseTypeId.toString());
|
||||
if (exerciseType.unitQuantity == "1") {
|
||||
summary += "x" + exercise.unitQuantity.toStringAsFixed(0);
|
||||
ExerciseType? exerciseType = Cache().getExerciseTypeById(exercise.exerciseTypeId!);
|
||||
//print("exerciseType " + (exerciseType == null ? "NULL" : exerciseType.name) + " ID " + exercise.exerciseTypeId.toString());
|
||||
if (exerciseType != null) {
|
||||
if (exerciseType.unitQuantity == "1") {
|
||||
summary += "x" + exercise.unitQuantity!.toStringAsFixed(0);
|
||||
}
|
||||
//print(" --- sum " + exerciseType.name + " $summary");
|
||||
}
|
||||
print(" --- sum " + exerciseType.name + " $summary");
|
||||
|
||||
prevExerciseTypeId = exerciseTypeId;
|
||||
prevDate = exerciseDate;
|
||||
@@ -322,6 +333,6 @@ class ExerciseRepository {
|
||||
prevCount++;
|
||||
}
|
||||
prevExercise.summary = summary;
|
||||
exerciseLogList.add(prevExercise);
|
||||
exerciseLogList!.add(prevExercise);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,49 +9,44 @@ extension ResultTypeExt on ResultType {
|
||||
}
|
||||
|
||||
class ExerciseResultRepository {
|
||||
final List<ResultExt> _results = List();
|
||||
final List<ResultExt> _results = [];
|
||||
ResultType resultType;
|
||||
|
||||
ExerciseResultRepository({this.resultType}) {
|
||||
if (resultType == null) {
|
||||
resultType = ResultType.man;
|
||||
}
|
||||
ExerciseResultRepository({required this.resultType}) {
|
||||
if (resultType.equals(ResultType.man) || resultType.equals(ResultType.woman)) {
|
||||
//_results.add(ResultExt(itemString: ResultItem.time.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.reps_volume.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.weight_volume.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.reps_volume.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.weight_volume.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description.toString()));
|
||||
} else {
|
||||
//_results.add(ResultExt(itemString: ResultItem.time.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.distance.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.steps.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.speed_max.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.distance.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.steps.description.toString()));
|
||||
_results.add(ResultExt(itemString: ResultItem.speed_max.description.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
List<ResultExt> getResults() => this._results;
|
||||
|
||||
Future<void> saveExerciseResults() async {
|
||||
if (this._results != null) {
|
||||
this._results.forEach((result) async {
|
||||
ExerciseResult exerciseResult = ExerciseResult();
|
||||
exerciseResult.customerId = Cache().userLoggedIn.customerId;
|
||||
exerciseResult.exerciseId = result.exerciseId;
|
||||
exerciseResult.dateFrom = result.dateFrom;
|
||||
exerciseResult.dateTo = result.dateTo;
|
||||
exerciseResult.resultType = result.itemString;
|
||||
exerciseResult.value = result.data;
|
||||
//await ExerciseResultApi().saveExerciseResult(exerciseResult);
|
||||
});
|
||||
}
|
||||
this._results.forEach((result) async {
|
||||
ExerciseResult exerciseResult = ExerciseResult();
|
||||
exerciseResult.customerId = Cache().userLoggedIn!.customerId!;
|
||||
exerciseResult.exerciseId = result.exerciseId!;
|
||||
exerciseResult.dateFrom = result.dateFrom!;
|
||||
exerciseResult.dateTo = result.dateTo;
|
||||
exerciseResult.resultType = result.itemString;
|
||||
exerciseResult.value = result.data;
|
||||
//await ExerciseResultApi().saveExerciseResult(exerciseResult);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,29 @@ import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/service/property_service.dart';
|
||||
|
||||
class PropertyRepository {
|
||||
List<Property> _properties;
|
||||
late List<Property>? _properties;
|
||||
|
||||
Future<List<Property>> getDBProperties() async {
|
||||
Future<List<Property>?> getDBProperties() async {
|
||||
this._properties = await PropertyApi().getProperties();
|
||||
return this._properties;
|
||||
}
|
||||
|
||||
List<Property> getProperties() {
|
||||
List<Property>? getProperties() {
|
||||
return this._properties;
|
||||
}
|
||||
|
||||
Property getPropertyByName(String name) {
|
||||
Property property;
|
||||
Property? getPropertyByName(String name) {
|
||||
Property? property;
|
||||
if (_properties == null) {
|
||||
_properties = Cache().getProperties();
|
||||
}
|
||||
this._properties.forEach((element) {
|
||||
if (name == element.propertyName) {
|
||||
property = element;
|
||||
}
|
||||
});
|
||||
if (_properties != null) {
|
||||
this._properties!.forEach((element) {
|
||||
if (name == element.propertyName) {
|
||||
property = element;
|
||||
}
|
||||
});
|
||||
}
|
||||
return property;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ import 'package:aitrainer_app/service/firebase_api.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart' as auth;
|
||||
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||
|
||||
class UserRepository with Logging {
|
||||
User user;
|
||||
late User user;
|
||||
|
||||
UserRepository() {
|
||||
this.createNewUser();
|
||||
@@ -29,7 +28,7 @@ class UserRepository with Logging {
|
||||
Future<void> addUser() async {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
String rc = await FirebaseApi().registerEmail(modelUser.email, modelUser.password);
|
||||
String rc = await FirebaseApi().registerEmail(modelUser.email!, modelUser.password!);
|
||||
if (rc == FirebaseApi.SIGN_IN_OK) {
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
@@ -44,17 +43,14 @@ class UserRepository with Logging {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
Map<String, dynamic> userData = await FirebaseApi().registerWithFacebook();
|
||||
if (userData != null) {
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Facebook signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} else {
|
||||
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Facebook signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} on auth.FirebaseAuthException catch (e) {
|
||||
if (e.code == 'email-already-in-use') {
|
||||
log('The account already exists for that email.');
|
||||
@@ -84,17 +80,14 @@ class UserRepository with Logging {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
Map<String, dynamic> userData = await FirebaseApi().registerWithGoogle();
|
||||
if (userData != null) {
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Google signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} else {
|
||||
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Google signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} on auth.FirebaseAuthException catch (e) {
|
||||
if (e.code == 'email-already-in-use') {
|
||||
log('The account already exists for that email.');
|
||||
@@ -117,17 +110,14 @@ class UserRepository with Logging {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
Map<String, dynamic> userData = await FirebaseApi().registerWithApple();
|
||||
if (userData != null) {
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Apple signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} else {
|
||||
|
||||
modelUser.email = userData['email'];
|
||||
if (modelUser.email == null) {
|
||||
throw new Exception("Apple signup was not successful. Please try another method");
|
||||
}
|
||||
modelUser.password = Cache().firebaseUid;
|
||||
modelUser.firebaseUid = Cache().firebaseUid;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
} on auth.FirebaseAuthException catch (e) {
|
||||
if (e.code == 'email-already-in-use') {
|
||||
log('The account already exists for that email.');
|
||||
@@ -148,14 +138,11 @@ class UserRepository with Logging {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
Map<String, dynamic> userData = await FirebaseApi().signInWithFacebook();
|
||||
if (userData == null) {
|
||||
throw new Exception("Facebook login was not successful");
|
||||
}
|
||||
modelUser.email = userData['email'];
|
||||
|
||||
await CustomerApi().getUserByEmail(modelUser.email);
|
||||
await CustomerApi().getUserByEmail(modelUser.email!);
|
||||
await Cache().afterFirebaseLogin();
|
||||
} on FacebookAuthException catch (e) {
|
||||
} /* on FacebookAuthException catch (e) {
|
||||
switch (e.errorCode) {
|
||||
case FacebookAuthErrorCode.OPERATION_IN_PROGRESS:
|
||||
throw Exception("You have a previous Facebook login operation in progress");
|
||||
@@ -167,7 +154,8 @@ class UserRepository with Logging {
|
||||
throw Exception("Facebook login failed");
|
||||
break;
|
||||
}
|
||||
} on NotFoundException catch (ex) {
|
||||
} */
|
||||
on NotFoundException catch (ex) {
|
||||
log("FB exception: " + ex.toString());
|
||||
throw Exception("Customer does not exist or the password is wrong");
|
||||
} on Exception catch (e) {
|
||||
@@ -180,12 +168,12 @@ class UserRepository with Logging {
|
||||
final User modelUser = this.user;
|
||||
try {
|
||||
Map<String, dynamic> userData = await FirebaseApi().signInWithGoogle();
|
||||
if (userData == null || userData['email'] == null) {
|
||||
if (userData['email'] == null) {
|
||||
throw new Exception("Google login was not successful");
|
||||
}
|
||||
modelUser.email = userData['email'];
|
||||
|
||||
await CustomerApi().getUserByEmail(modelUser.email);
|
||||
await CustomerApi().getUserByEmail(modelUser.email!);
|
||||
await Cache().afterFirebaseLogin();
|
||||
} on Exception catch (ex) {
|
||||
log("Google exception: " + ex.toString());
|
||||
@@ -196,12 +184,12 @@ class UserRepository with Logging {
|
||||
Future<void> getUserByApple() async {
|
||||
final User modelUser = this.user;
|
||||
Map<String, dynamic> userData = await FirebaseApi().signInWithApple();
|
||||
if (userData == null || userData['email'] == null) {
|
||||
if (userData['email'] == null) {
|
||||
throw new Exception("Apple login was not successful");
|
||||
}
|
||||
modelUser.email = userData['email'];
|
||||
try {
|
||||
await CustomerApi().getUserByEmail(modelUser.email);
|
||||
await CustomerApi().getUserByEmail(modelUser.email!);
|
||||
await Cache().afterFirebaseLogin();
|
||||
} on Exception catch (ex) {
|
||||
log("Apple exception: " + ex.toString());
|
||||
@@ -214,7 +202,7 @@ class UserRepository with Logging {
|
||||
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
|
||||
|
||||
if (rc == FirebaseApi.SIGN_IN_OK) {
|
||||
await CustomerApi().getUserByEmail(modelUser.email);
|
||||
await CustomerApi().getUserByEmail(modelUser.email!);
|
||||
await Cache().afterFirebaseLogin();
|
||||
} else {
|
||||
log("Exception: user not found or password is wrong");
|
||||
@@ -224,6 +212,6 @@ class UserRepository with Logging {
|
||||
|
||||
Future<void> resetPassword() async {
|
||||
final User modelUser = this.user;
|
||||
await FirebaseApi().resetPassword(modelUser.email);
|
||||
await FirebaseApi().resetPassword(modelUser.email!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercise_type_service.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -20,29 +18,29 @@ extension AntagonistExt on Antagonist {
|
||||
}
|
||||
|
||||
class WorkoutTreeRepository with Logging {
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
final LinkedHashMap<String, WorkoutMenuTree> tree = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
SplayTreeMap sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
bool isEnglish;
|
||||
WorkoutType workoutType;
|
||||
final List<WorkoutMenuTree> menuAsExercise = List();
|
||||
bool? isEnglish;
|
||||
WorkoutType? workoutType;
|
||||
final List<WorkoutMenuTree> menuAsExercise = [];
|
||||
|
||||
void createTree() {
|
||||
//if (Cache().getExerciseTree().length > 0 || Cache().getWorkoutMenuTree().length > 0) return;
|
||||
isEnglish = AppLanguage().appLocal == Locale('en');
|
||||
log("** Start creating tree on lang: " +
|
||||
AppLanguage().appLocal.languageCode +
|
||||
" tree length: " +
|
||||
Cache().getExerciseTree().length.toString());
|
||||
List<ExerciseTree>? exerciseTree = Cache().getExerciseTree();
|
||||
List<ExerciseType>? exerciseTypes = Cache().getExerciseTypes();
|
||||
if (exerciseTree == null || exerciseTypes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ExerciseTree> exerciseTree = Cache().getExerciseTree();
|
||||
List<ExerciseType> exerciseTypes = Cache().getExerciseTypes();
|
||||
log("** Start creating tree on lang: ${AppLanguage().appLocal.languageCode}");
|
||||
|
||||
exerciseTree.sort((a, b) => a.sort.compareTo(b.sort));
|
||||
exerciseTree.sort((a, b) => a.sort!.compareTo(b.sort!));
|
||||
|
||||
exerciseTree.forEach((treeItem) async {
|
||||
//log(" -- TreeItem " + treeItem.toJson().toString() + " active " + treeItem.active.toString());
|
||||
if (treeItem.active == true) {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String treeName = isEnglish! ? treeItem.name : treeItem.nameTranslation;
|
||||
|
||||
bool is1RM =
|
||||
treeItem.name.contains("Muscle") || treeItem.name.contains("Shape") || treeItem.name.contains("Strength") ? true : false;
|
||||
@@ -54,7 +52,7 @@ class WorkoutTreeRepository with Logging {
|
||||
if (isRunning == false && treeItem.parentId != 0) {
|
||||
isRunning = isParentRunning(treeItem.parentId);
|
||||
}
|
||||
WorkoutMenuTree parent = getParentItem(treeItem.parentId);
|
||||
WorkoutMenuTree? parent = getParentItem(treeItem.parentId);
|
||||
WorkoutMenuTree menuItem = WorkoutMenuTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
@@ -71,7 +69,7 @@ class WorkoutTreeRepository with Logging {
|
||||
treeItem.name,
|
||||
parent != null ? parent.name : "",
|
||||
parent != null ? parent.nameEnglish : "",
|
||||
treeItem.sort);
|
||||
treeItem.sort!);
|
||||
menuItem = this.setWorkoutTypes(menuItem, treeItem);
|
||||
this.tree[treeItem.name + "_" + treeItem.parentId.toString()] = menuItem;
|
||||
//log("WorkoutMenuTree item ${menuItem.toJson()}");
|
||||
@@ -81,7 +79,7 @@ class WorkoutTreeRepository with Logging {
|
||||
exerciseTypes.forEach((exerciseType) async {
|
||||
if (!(exerciseType.imageUrl.isEmpty || exerciseType.name.isEmpty || exerciseType.nameTranslation.isEmpty) &&
|
||||
exerciseType.active == true) {
|
||||
String exerciseTypeName = isEnglish ? exerciseType.name : exerciseType.nameTranslation;
|
||||
String exerciseTypeName = isEnglish! ? exerciseType.name : exerciseType.nameTranslation;
|
||||
//String assetImage = await _buildImage(exerciseType.imageUrl); //'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
|
||||
if (exerciseType.parents.isNotEmpty) {
|
||||
@@ -95,7 +93,7 @@ class WorkoutTreeRepository with Logging {
|
||||
is1RM = false;
|
||||
exerciseType.setAbility(ExerciseAbility.running);
|
||||
}
|
||||
WorkoutMenuTree parent = getParentItem(parentId);
|
||||
WorkoutMenuTree? parent = getParentItem(parentId);
|
||||
WorkoutMenuTree menuItem = WorkoutMenuTree(
|
||||
exerciseType.exerciseTypeId,
|
||||
parentId,
|
||||
@@ -154,7 +152,7 @@ class WorkoutTreeRepository with Logging {
|
||||
bool isTreeItemRunning = false;
|
||||
|
||||
this.tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItemRunning = isTreeItemRunning || treeItem.isRunning;
|
||||
//log (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
@@ -168,7 +166,7 @@ class WorkoutTreeRepository with Logging {
|
||||
bool isTreeItem1RM = false;
|
||||
|
||||
this.tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItem1RM = isTreeItem1RM || treeItem.is1RM;
|
||||
//log(treeItem.name + " 1RM " + treeItem.is1RM.toString());
|
||||
@@ -204,7 +202,7 @@ class WorkoutTreeRepository with Logging {
|
||||
LinkedHashMap<String, WorkoutMenuTree> getBranch(int parent, {bool filtering = false}) {
|
||||
LinkedHashMap<String, WorkoutMenuTree> branch = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree workoutTree = value;
|
||||
if (parent == workoutTree.parent) {
|
||||
branch[key] = value;
|
||||
}
|
||||
@@ -213,9 +211,9 @@ class WorkoutTreeRepository with Logging {
|
||||
}
|
||||
|
||||
List<WorkoutMenuTree> getBranchList(int parent) {
|
||||
List branch = List<WorkoutMenuTree>();
|
||||
List<WorkoutMenuTree> branch = [];
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree workoutTree = value;
|
||||
if (parent == workoutTree.parent) {
|
||||
branch.add(workoutTree);
|
||||
}
|
||||
@@ -223,10 +221,10 @@ class WorkoutTreeRepository with Logging {
|
||||
return branch;
|
||||
}
|
||||
|
||||
WorkoutMenuTree getParentItem(int parent) {
|
||||
WorkoutMenuTree parentItem;
|
||||
WorkoutMenuTree? getParentItem(int parent) {
|
||||
WorkoutMenuTree? parentItem;
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree workoutTree = value;
|
||||
if (parent == workoutTree.id) {
|
||||
parentItem = workoutTree;
|
||||
}
|
||||
@@ -234,8 +232,8 @@ class WorkoutTreeRepository with Logging {
|
||||
return parentItem;
|
||||
}
|
||||
|
||||
WorkoutMenuTree getMenuItemByExerciseTypeId(int exerciseTypeId) {
|
||||
WorkoutMenuTree menuItem;
|
||||
WorkoutMenuTree? getMenuItemByExerciseTypeId(int exerciseTypeId) {
|
||||
WorkoutMenuTree? menuItem;
|
||||
this.menuAsExercise.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
menuItem = element;
|
||||
@@ -244,41 +242,43 @@ class WorkoutTreeRepository with Logging {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
List<WorkoutMenuTree> getWorkoutTreeAlternatives(WorkoutMenuTree workoutMenuTree) {
|
||||
List<WorkoutMenuTree>? getWorkoutTreeAlternatives(WorkoutMenuTree? workoutMenuTree) {
|
||||
if (workoutMenuTree == null) {
|
||||
return null;
|
||||
}
|
||||
if (workoutMenuTree.exerciseType == null) {
|
||||
return null;
|
||||
}
|
||||
final List<ExerciseType> alternatives = this.getExerciseTypeAlternatives(workoutMenuTree.exerciseTypeId);
|
||||
final List<ExerciseType>? alternatives = this.getExerciseTypeAlternatives(workoutMenuTree.exerciseTypeId);
|
||||
if (alternatives == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<WorkoutMenuTree> list = List();
|
||||
List<WorkoutMenuTree> list = [];
|
||||
alternatives.forEach((element) {
|
||||
final WorkoutMenuTree alternativeMenuItem = this.getMenuItemByExerciseTypeId(element.exerciseTypeId);
|
||||
list.add(alternativeMenuItem);
|
||||
final WorkoutMenuTree? alternativeMenuItem = this.getMenuItemByExerciseTypeId(element.exerciseTypeId);
|
||||
if (alternativeMenuItem != null) {
|
||||
list.add(alternativeMenuItem);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
List<ExerciseType> getExerciseTypeAlternatives(int exerciseTypeId) {
|
||||
List<ExerciseType> getExerciseTypeAlternatives(int? exerciseTypeId) {
|
||||
if (exerciseTypeId == null || exerciseTypeId <= 0) {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
List<ExerciseType> list = [];
|
||||
List<ExerciseType>? exerciseTypes = Cache().getExerciseTypes();
|
||||
if (exerciseTypes != null) {
|
||||
exerciseTypes.forEach((exerciseType) {
|
||||
if (exerciseType.alternatives.isNotEmpty) {
|
||||
exerciseType.alternatives.forEach((childId) {
|
||||
if (childId == exerciseTypeId) {
|
||||
list.add(exerciseType);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
List<ExerciseType> list = List();
|
||||
Cache().getExerciseTypes().forEach((exerciseType) {
|
||||
if (exerciseType.alternatives.isNotEmpty) {
|
||||
exerciseType.alternatives.forEach((childId) {
|
||||
if (childId == exerciseTypeId) {
|
||||
list.add(exerciseType);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ class WorkoutTreeRepository with Logging {
|
||||
void sortByMuscleType() {
|
||||
sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree workoutTree = value;
|
||||
if (!workoutTree.nameEnglish.contains('Muscle Build') &&
|
||||
!workoutTree.nameEnglish.contains('Strength') &&
|
||||
workoutTree.is1RM &&
|
||||
@@ -313,7 +313,7 @@ class WorkoutTreeRepository with Logging {
|
||||
int getMissingTreeIdByName(String name) {
|
||||
int missingId = 0;
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree item = value as WorkoutMenuTree;
|
||||
WorkoutMenuTree item = value;
|
||||
if (item.name == name || name == item.nameEnglish) {
|
||||
missingId = item.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user