diff --git a/README.md b/README.md index dae89af..a8abbe6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ Workout Test and Diet 4 You Common Util Functions + +### Version 1.1.0 + +- Flutter 3.10, dart fix + ### Version 1.0.29 - gpt4 model diff --git a/lib/example/lib/main.dart b/lib/example/lib/main.dart index 9756922..99e8c41 100644 --- a/lib/example/lib/main.dart +++ b/lib/example/lib/main.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:workouttest_util/model/cache.dart'; import 'package:workouttest_util/service/customer_service.dart'; -import 'package:workouttest_util/service/openai_service.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/lib/model/cache.dart b/lib/model/cache.dart index 4f7e367..b47cac4 100644 --- a/lib/model/cache.dart +++ b/lib/model/cache.dart @@ -481,7 +481,7 @@ class Cache with Logging { _exercisesTrainee = null; _traineeExercisePlan = null; _exercises = []; - _myExercisesPlanDetails = LinkedHashMap(); + _myExercisesPlanDetails = LinkedHashMap(); log("Trainees is null? ${_trainee == null}"); Future prefs = SharedPreferences.getInstance(); await setPreferences(prefs, SharePrefsChange.logout, 0, ""); @@ -637,7 +637,7 @@ class Cache with Logging { void initBadges() { CustomerRepository customerRepository = CustomerRepository(); - _badges = LinkedHashMap(); + _badges = LinkedHashMap(); if (userLoggedIn == null) { return; } diff --git a/lib/repository/exercise_device_repository.dart b/lib/repository/exercise_device_repository.dart index 2cf49e7..29fbab9 100644 --- a/lib/repository/exercise_device_repository.dart +++ b/lib/repository/exercise_device_repository.dart @@ -6,7 +6,7 @@ class ExerciseDeviceRepository { List _devices = []; List getDevices() { - return this._devices; + return _devices; } void setDevices(List list) { @@ -14,15 +14,15 @@ class ExerciseDeviceRepository { } Future> getDBDevices() async { - this._devices = await ExerciseDeviceApi().getDevices(); - return this._devices; + _devices = await ExerciseDeviceApi().getDevices(); + return _devices; } bool isGym(int deviceId) { bool isGym = false; - _devices.forEach((element) { + for (var element in _devices) { isGym = isGymElement(element.name); - }); + } return isGym; } @@ -42,11 +42,11 @@ class ExerciseDeviceRepository { if (_devices.isEmpty) { _devices = Cache().getDevices()!; } - _devices.forEach((element) { + for (var element in _devices) { if (isGymElement(element.name)) { gymDevices.add(element); } - }); + } return gymDevices; } } diff --git a/lib/repository/training_plan_repository.dart b/lib/repository/training_plan_repository.dart index f566969..e463042 100644 --- a/lib/repository/training_plan_repository.dart +++ b/lib/repository/training_plan_repository.dart @@ -20,21 +20,21 @@ class TrainingPlanRepository with Common, Logging { final List? exerciseTree = Cache().getExerciseTree(); int? parentId; if (exerciseTree != null) { - exerciseTree.forEach((element) { + for (var element in exerciseTree) { if (element.internalName == parent) { parentId = element.treeId; parentTree = element; } - }); + } } final List? plans = Cache().getTrainingPlans(); if (plans != null && parentId != null) { - plans.forEach((element) { + for (var element in plans) { if (element.treeId == parentId) { resultList.add(element); } - }); + } } return resultList; } @@ -48,12 +48,12 @@ class TrainingPlanRepository with Common, Logging { log(" **** Activate Plan: $trainingPlanId"); // 1. deactivate if (Cache().getCustomerTrainingPlans() != null) { - Cache().getCustomerTrainingPlans()!.forEach((plan) { + for (var plan in Cache().getCustomerTrainingPlans()!) { plan.active = false; if (plan.customerTrainingPlanId != null) { //TrainingPlanApi().updateCustomerTrainingPlan(plan, plan.customerTrainingPlanId!); } - }); + } } CustomerTrainingPlan plan = CustomerTrainingPlan(); @@ -72,14 +72,14 @@ class TrainingPlanRepository with Common, Logging { // 3 calculate weights int index = 0; int exerciseTypeIdOrig = 0; - trainingPlan.details!.forEach((elem) { + for (var elem in trainingPlan.details!) { List list = createDetail(plan, elem, exerciseTypeIdOrig, index); exerciseTypeIdOrig = elem.exerciseTypeId; - list.forEach((element) { + for (var element in list) { plan.details.add(element); index++; - }); - }); + } + } Cache().myTrainingPlan = plan; @@ -251,21 +251,21 @@ class TrainingPlanRepository with Common, Logging { // reverse return a.dateAdd!.compareTo(b.dateAdd!); }); - exercises.forEach((exercise) { + for (var exercise in exercises) { if (exercise.exerciseTypeId == exerciseTypeId && exercise.dateAdd!.compareTo(dt) >= 0) { detail.weight = weight; lastExercise1RM = exercise; //print("last exercise: $exercise"); } - }); + } - if (lastExercise1RM == null || lastExercise1RM!.unitQuantity == null) { + if (lastExercise1RM == null || lastExercise1RM.unitQuantity == null) { detail.weight = weight; detail.isTest = true; return detail; } - double oneRepMax = calculateMax1RMSameDay(lastExercise1RM!); + double oneRepMax = calculateMax1RMSameDay(lastExercise1RM); // Common.calculate1RM(lastExercise1RM!.unitQuantity!, lastExercise1RM!.quantity!); //print("Exercise $exerciseTypeId - 1RM : $oneRepMax"); weight = oneRepMax * Common.get1RMPercent(detail.repeats!); @@ -286,7 +286,7 @@ class TrainingPlanRepository with Common, Logging { List exercises = Cache().getExercises()!; double max1RM = 0.0; - exercises.forEach((exercise) { + for (var exercise in exercises) { if (actual.exerciseTypeId == exercise.exerciseTypeId && actual.dateAdd!.year == exercise.dateAdd!.year && actual.dateAdd!.month == exercise.dateAdd!.month && @@ -296,7 +296,7 @@ class TrainingPlanRepository with Common, Logging { max1RM = oneRepMax; } } - }); + } return max1RM; } @@ -307,11 +307,11 @@ class TrainingPlanRepository with Common, Logging { return 0; } int originalRepeats = 0; - plan.details!.forEach((element) { + for (var element in plan.details!) { if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) { originalRepeats = element.repeats ?? 0; } - }); + } return originalRepeats; } @@ -321,11 +321,11 @@ class TrainingPlanRepository with Common, Logging { return 0; } double originalWeight = 0; - plan.details!.forEach((element) { + for (var element in plan.details!) { if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) { originalWeight = element.weight ?? 0; } - }); + } return originalWeight; } @@ -371,11 +371,11 @@ class TrainingPlanRepository with Common, Logging { // 1.b get the original detail's repeat int originalRepeats = detail.repeats!; - plan.details!.forEach((element) { + for (var element in plan.details!) { if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) { originalRepeats = element.repeats ?? 0; } - }); + } // 2 get recalculated repeats recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble()); diff --git a/lib/service/customer_service.dart b/lib/service/customer_service.dart index 23a4815..13de861 100644 --- a/lib/service/customer_service.dart +++ b/lib/service/customer_service.dart @@ -35,7 +35,7 @@ class CustomerApi with Logging { Future deactivateCustomer(int customerId) async { log(" ===== deactivate : $customerId"); await _client.post("customers/deactivate/$customerId", ""); - } + } Future addCustomer(Customer customer) async { customer.dateAdd = DateTime.now(); @@ -85,7 +85,7 @@ class CustomerApi with Logging { final String responseBody = await _client.get("customers/find_by_email/$email", ""); Customer customer; try { - customer = Customer.fromJson(jsonDecode(responseBody)); + customer = Customer.fromJson(jsonDecode(responseBody)); if (customer.firebaseUid == null) { await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!); } @@ -128,32 +128,32 @@ class CustomerApi with Logging { if (properties != null) { // reset Properties - properties.forEach((property) { + for (var property in properties) { CustomerProperty customerProperty = CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId!, dateAdd: DateTime.now(), propertyValue: 0); customer.properties[property.propertyName] = customerProperty; - }); + } - customerProperties!.forEach((customerProperty) { - properties.forEach((property) { + for (var customerProperty in customerProperties!) { + for (var property in properties) { if (customerProperty.propertyId == property.propertyId) { customer.properties[property.propertyName] = customerProperty; } - }); - }); + } + } } } Future getTrainee(int customerId) async { String body = ""; Customer customer; - log(" ===== get Trainee customer by id: " + customerId.toString()); + log(" ===== get Trainee customer by id: $customerId"); try { - final String responseBody = await _client.get("customers/" + customerId.toString(), body); + final String responseBody = await _client.get("customers/$customerId", body); customer = Customer.fromJson(jsonDecode(responseBody)); - log(" --- Trainee: " + customer.toJson().toString()); + log(" --- Trainee: ${customer.toJson()}"); } catch (exception) { - log("Exception: " + exception.toString()); + log("Exception: $exception"); throw Exception(exception); } return customer; @@ -164,11 +164,11 @@ class CustomerApi with Logging { log("Get trainees list"); try { String body = ""; - final String responseBody = await _client.get("customers/trainees/" + trainerId.toString(), body); + final String responseBody = await _client.get("customers/trainees/$trainerId", body); final Iterable json = jsonDecode(responseBody); trainees = json.map((customer) => Customer.fromJson(customer)).toList(); } catch (exception) { - log("Exception: " + exception.toString()); + log("Exception: $exception"); throw Exception(exception); } return trainees; @@ -195,45 +195,45 @@ class CustomerApi with Logging { } Future addProperty(CustomerProperty property) async { - String body = JsonEncoder().convert(property.toJson()); - log(" ===== add new customer property: " + body); + String body = const JsonEncoder().convert(property.toJson()); + log(" ===== add new customer property: $body"); CustomerProperty customerProperty; String? responseBody; try { responseBody = await _client.post("customer_property", body); - log(" responseBody: " + responseBody); + log(" responseBody: $responseBody"); int? status = jsonDecode(responseBody)['status']; if (status != null) { - throw new Exception(jsonDecode(responseBody)['error']); + throw Exception(jsonDecode(responseBody)['error']); } else { customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody)); } } on FormatException { - throw new Exception(responseBody); + throw Exception(responseBody); } on Exception catch (e) { - throw new Exception(e); + throw Exception(e); } return customerProperty; } Future updateProperty(CustomerProperty property) async { - String body = JsonEncoder().convert(property.toJson()); + String body = const JsonEncoder().convert(property.toJson()); CustomerProperty? customerProperty; - log(" ===== update customer property: " + body); + log(" ===== update customer property: $body"); String? responseBody; try { - responseBody = await _client.post("customer_property/update/" + property.customerPropertyId.toString(), body); - log(" responseBody: " + responseBody); + responseBody = await _client.post("customer_property/update/${property.customerPropertyId}", body); + log(" responseBody: $responseBody"); int? status = jsonDecode(responseBody)['status']; if (status != null) { - throw new Exception(jsonDecode(responseBody)['error']); + throw Exception(jsonDecode(responseBody)['error']); } else { customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody)); } } on FormatException { - throw new Exception(responseBody); + throw Exception(responseBody); } on Exception catch (e) { - throw new Exception(e); + throw Exception(e); } return customerProperty; } diff --git a/lib/service/exercise_tree_service.dart b/lib/service/exercise_tree_service.dart index a1df753..97b6f4b 100644 --- a/lib/service/exercise_tree_service.dart +++ b/lib/service/exercise_tree_service.dart @@ -51,7 +51,7 @@ class ExerciseTreeApi with Logging { int treeIndex = 0; copyList.forEach((element) async { int index = 0; - exerciseTreeParents.forEach((parent) { + for (var parent in exerciseTreeParents) { if (parent.exerciseTreeChildId == element.treeId) { if (index > 0) { ExerciseTree newElement = element.copy(parent.exerciseTreeParentId); @@ -64,7 +64,7 @@ class ExerciseTreeApi with Logging { } index++; } - }); + } treeIndex++; }); return exerciseTree; diff --git a/lib/service/package_service.dart b/lib/service/package_service.dart index 9aee85c..9f593ad 100644 --- a/lib/service/package_service.dart +++ b/lib/service/package_service.dart @@ -134,7 +134,7 @@ class PackageApi { int treeIndex = 0; copyList.forEach((element) async { int index = 0; - exerciseTreeParents.forEach((parent) { + for (var parent in exerciseTreeParents) { if (parent.exerciseTreeChildId == element.treeId) { if (index > 0) { ExerciseTree newElement = element.copy(parent.exerciseTreeParentId); @@ -148,7 +148,7 @@ class PackageApi { } index++; } - }); + } treeIndex++; }); diff --git a/pubspec.yaml b/pubspec.yaml index f00cefc..4e3e7fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: workouttest_util description: Workout Test app and web functions. -version: 1.0.29 +version: 1.1.0 environment: sdk: ">=2.18.6 <3.0.0"