v1.0.0 outsourced from aitrainer_app

This commit is contained in:
Tibor Bossanyi (Freelancer)
2023-01-28 12:53:16 +01:00
commit ca96abf8c0
87 changed files with 7189 additions and 0 deletions
+801
View File
@@ -0,0 +1,801 @@
import 'dart:collection';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:workouttest_util/model/customer.dart';
import 'package:workouttest_util/model/customer_activity.dart';
import 'package:workouttest_util/model/customer_property.dart';
import 'package:workouttest_util/model/customer_training_plan.dart';
import 'package:workouttest_util/model/description.dart';
import 'package:workouttest_util/model/evaluation.dart';
import 'package:workouttest_util/model/exercise_plan.dart';
import 'package:workouttest_util/model/exercise_plan_detail.dart';
import 'package:workouttest_util/model/exercise_plan_template.dart';
import 'package:workouttest_util/model/exercise_tree.dart';
import 'package:workouttest_util/model/exercise.dart';
import 'package:workouttest_util/model/faq.dart';
import 'package:workouttest_util/model/model_change.dart';
import 'package:workouttest_util/model/product.dart' as wt_product;
import 'package:workouttest_util/model/product.dart';
import 'package:workouttest_util/model/property.dart';
import 'package:workouttest_util/model/purchase.dart';
import 'package:workouttest_util/model/split_test.dart';
import 'package:workouttest_util/model/sport.dart';
import 'package:workouttest_util/model/training_plan.dart';
import 'package:workouttest_util/model/training_plan_day.dart';
import 'package:workouttest_util/model/tutorial.dart';
import 'package:workouttest_util/model/workout_menu_tree.dart';
import 'package:workouttest_util/repository/customer_repository.dart';
import 'package:workouttest_util/service/firebase_api.dart';
import 'package:workouttest_util/service/package_service.dart';
import 'package:workouttest_util/util/enums.dart';
import 'package:workouttest_util/util/env.dart';
import 'package:workouttest_util/util/track.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:posthog_session/posthog_session.dart';
// ignore: depend_on_referenced_packages
import 'package:shared_preferences/shared_preferences.dart';
import 'package:workouttest_util/model/exercise_type.dart';
// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';
import '../util/logging.dart';
import 'customer_exercise_device.dart';
import 'exercise_device.dart';
enum SharePrefsChange {
login,
registration,
logout,
}
/*
Auth flow of the app
1. During the login screen the authentication will be executed
- if not successful: message: Network error, try again later
- if successful
- get the stored shared preferences and customer id
- if customer_id not present -> registration page
- if present, check if the expiration_date > 10 days -> login page
- else get the API customer by the stored customer_id
- After registration / login store the preferences:
- AuthToken
- customer_id
- last_store_date
- is_registered
- is_logged_in
*/
enum ActivityDone {
tutorialExecuteFirstTest,
tutorialBasic,
tutorialBasicChestPress,
tutorialBasicLegPress,
tutorialDevelopment,
isExerciseLogSeen,
isMuscleDevelopmentSeen,
isBodyTypeSeen,
exerciseSaveTestTip,
exerciseSaveTrainingTip,
exerciseSaveTestsetTip
}
extension ActivityDoneExt on ActivityDone {
String toStr() => toString().split(".").last;
bool equalsTo(ActivityDone value) => toString() == value.toString();
bool equalsStringTo(String value) => toStr() == value;
ActivityDone? searchByString(String activityString) {
ActivityDone? activity;
for (var element in ActivityDone.values) {
if (element.equalsStringTo(activityString)) {
activity = element;
}
}
return activity;
}
}
class Cache with Logging {
static final Cache _singleton = Cache._internal();
// Keys to store and fetch data from SharedPreferences
static const String authTokenKey = "auth_token";
static const String customerIdKey = "customer_id";
static const String firebaseUidKey = "firebase_uid";
static const String lastStoreDateKey = "last_date";
static const String isRegisteredKey = "is_registered";
static const String isLoggedInKey = "is_logged_in";
static const String langKey = "lang";
static const String serverKey = "live";
static const String hardwareKey = "hardware";
static const String loginTypeKey = "login_type";
static const String timerDisplayKey = "timer_display";
static const String activeExercisePlanKey = "active_exercise_plan";
static const String activeExercisePlanDateKey = "active_exercise_plan_date";
static const String activeExercisePlanDetailsKey = "active_exercise_details_plan";
static const String myTrainingPlanKey = "myTrainingPlan";
static String baseUrlLive = 'https://api.workouttest.org/api/';
static String baseUrlTest = 'https://apitest.workouttest.org/api/';
late String baseUrl;
static const String mediaUrl = 'https://admin.workouttest.org/media/';
static const String username = 'bosi';
static const String password = 'andio2009';
String authToken = "";
AccessToken? accessTokenFacebook;
Customer? userLoggedIn;
String? firebaseUid;
String? firebaseMessageToken;
LoginType? loginType;
PackageInfo? packageInfo;
bool hasPurchased = false;
bool firstLoad = true;
List<ExerciseType>? _exerciseTypes;
List<ExerciseTree>? _exerciseTree;
List<Evaluation>? _evaluations;
List<Exercise>? _exercises;
ExercisePlan? _myExercisePlan;
List<Property>? _properties;
List<Sport>? _sports;
List<wt_product.Product>? _products;
List<Purchase> _purchases = [];
List<SplitTest> _splitTests = [];
List<TrainingPlanDay> _trainingPlanDays = [];
List<ExercisePlanTemplate> _exercisePlanTemplates = [];
ExercisePlan? activeExercisePlan;
CustomerTrainingPlan? myTrainingPlan;
List<ExercisePlanDetail>? activeExercisePlanDetails;
List<ExerciseDevice>? _devices;
List<CustomerExerciseDevice>? _customerDevices;
List<CustomerActivity>? _customerActivities;
List<CustomerTrainingPlan>? _customerTrainingPlans;
List<CustomerProperty>? _customerPropertyAll;
List<Tutorial>? _tutorials;
List<Description>? _descriptions;
List<Faq>? _faqs;
List<TrainingPlan>? _trainingPlans;
LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
LinkedHashMap<String, WorkoutMenuTree> _tree = LinkedHashMap<String, WorkoutMenuTree>();
double _percentExercises = -1;
Customer? _trainee;
List<Exercise>? _exercisesTrainee;
ExercisePlan? _traineeExercisePlan;
FirebaseRemoteConfig? remoteConfig;
LinkedHashMap<String, int> _badges = LinkedHashMap();
List? deviceLanguages;
String startPage = "home";
late String testEnvironment;
bool liveServer = true;
bool? hasHardware = false;
HashMap<String, bool> activitiesDone = HashMap();
factory Cache() {
return _singleton;
}
Cache._internal() {
String testEnv = EnvironmentConfig.test_env;
testEnvironment = testEnv;
print("testEnv $testEnv");
if (testEnv == "1") {
baseUrl = baseUrlTest;
liveServer = false;
}
for (var element in ActivityDone.values) {
activitiesDone[element.toStr()] = false;
}
}
void setTestBaseUrl() {
baseUrl = baseUrlTest;
}
String getAuthToken() {
return authToken;
}
Future<void> deleteCustomerId(int customerId) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
sharedPreferences.remove(Cache.customerIdKey);
}
Future<void> saveActiveExercisePlan(ExercisePlan exercisePlan, List<ExercisePlanDetail> exercisePlanDetails) async {
activeExercisePlan = exercisePlan;
activeExercisePlanDetails = exercisePlanDetails;
String exercisePlanJson = const JsonEncoder().convert(exercisePlan.toJson());
String detailsJson = jsonEncode(exercisePlanDetails.map((i) => i.toJsonWithExerciseList()).toList()).toString();
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
final DateTime now = DateTime.now();
sharedPreferences.setString(Cache.activeExercisePlanKey, exercisePlanJson);
sharedPreferences.setString(Cache.activeExercisePlanDetailsKey, detailsJson);
String savingDay = DateFormat("yyyy-MM-dd HH:mm:ss").format(now);
sharedPreferences.setString(Cache.activeExercisePlanDateKey, savingDay);
}
Future<void> saveMyTrainingPlan() async {
if (myTrainingPlan == null) {
return;
}
String myTrainingPlanJson = const JsonEncoder().convert(myTrainingPlan!.toJsonWithDetails());
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.setString(Cache.myTrainingPlanKey, myTrainingPlanJson);
}
Future<void> deleteMyTrainingPlan() async {
if (myTrainingPlan == null) {
return;
}
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.remove(Cache.myTrainingPlanKey);
}
Future<void> getMyTrainingPlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
final String? savedTrainingPlanJson = sharedPreferences.getString(Cache.myTrainingPlanKey);
if (savedTrainingPlanJson == null) {
return;
}
//String jsonPlan = savedTrainingPlanJson.replaceAllMapped(RegExp(r'[a-zA-Z]+\:'), (Match m) => "\"${m[0]}\"");
Map<String, dynamic> map;
try {
map = JsonDecoder().convert(savedTrainingPlanJson);
//print("Training plan: $savedTrainingPlanJson");
this.myTrainingPlan = CustomerTrainingPlan.fromJsonWithDetails(map);
} on Exception catch (e) {
print(e.toString());
}
}
Future<void> deleteActiveExercisePlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.remove(Cache.activeExercisePlanDateKey);
this.activeExercisePlan = null;
this.activeExercisePlanDetails = null;
}
Future<void> getActiveExercisePlan() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
final savedPlanDateString = sharedPreferences.getString(Cache.activeExercisePlanDateKey);
if (savedPlanDateString == null) {
return;
}
DateFormat format = DateFormat("yyyy-MM-dd HH:mm:ss");
DateTime savedPlanDate;
savedPlanDate = format.parse(savedPlanDateString);
print("Saved plan: $savedPlanDate");
final DateTime now = DateTime.now();
final DateTime added = savedPlanDate.add(Duration(days: 1));
if (added.isBefore(now)) {
return;
}
String? exercisePlanJson = sharedPreferences.getString(Cache.activeExercisePlanKey);
if (exercisePlanJson != null) {
final Map<String, dynamic> map = JsonDecoder().convert(exercisePlanJson);
this.activeExercisePlan = ExercisePlan.fromJson(map);
}
String? detailsJson = sharedPreferences.getString(Cache.activeExercisePlanDetailsKey);
if (detailsJson != null) {
Iterable json = jsonDecode(detailsJson);
this.activeExercisePlanDetails = json.map((details) => ExercisePlanDetail.fromJsonWithExerciseList(details)).toList();
}
}
Future<void> setServer(bool live) async {
if (this.testEnvironment == "1") {
liveServer = false;
live = false;
}
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
liveServer = live;
sharedPreferences.setBool(Cache.serverKey, live);
}
void getHardware(SharedPreferences prefs) {
final bool? hasHardware = prefs.getBool(Cache.hardwareKey);
this.hasHardware = hasHardware;
if (hasHardware == null) {
this.hasHardware = false;
}
}
Future<bool> selectedHardwareBefore() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
final bool? selectedHardware = sharedPreferences.getBool(Cache.hardwareKey);
return selectedHardware == null;
}
Future<void> setHardware(bool hasHardware) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
sharedPreferences.setBool(Cache.hardwareKey, hasHardware);
this.hasHardware = hasHardware;
}
void setServerAddress(SharedPreferences prefs) {
if (this.testEnvironment == "1") {
baseUrl = baseUrlTest;
print("TestEnv $baseUrl");
return;
}
final bool? live = prefs.getBool(Cache.serverKey);
if (live == null) {
baseUrl = baseUrlLive;
print("Live Env $baseUrl");
liveServer = true;
return;
}
liveServer = live;
if (live) {
baseUrl = baseUrlLive;
} else {
baseUrl = baseUrlTest;
}
print("Env $baseUrl");
}
Future<void> setLoginTypeFromPrefs() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
final String? loginType = sharedPreferences.getString(Cache.loginTypeKey);
LoginType type = LoginType.email;
if (loginType == LoginType.apple.toString()) {
type = LoginType.apple;
} else if (loginType == LoginType.google.toString()) {
type = LoginType.google;
} else if (loginType == LoginType.fb.toString()) {
type = LoginType.fb;
} else if (loginType == LoginType.email.toString()) {
type = LoginType.email;
}
//print("LoginType: " + loginType == null ? "NULL" : loginType);
Cache().setLoginType(type);
}
static String? getToken(SharedPreferences prefs) {
return prefs.getString(authTokenKey);
}
String getBaseUrl() {
return baseUrl;
}
static String getMediaUrl() {
return mediaUrl;
}
afterRegistration(Customer customer) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
userLoggedIn = customer;
final String uid = Cache().firebaseUid!;
SharedPreferences sharedPreferences = await prefs;
sharedPreferences.setString(Cache.loginTypeKey, Cache().getLoginType().toString());
await setPreferences(prefs, SharePrefsChange.registration, customer.customerId!, uid);
}
afterLogin(Customer customer) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
userLoggedIn = customer;
SharedPreferences sharedPreferences = await prefs;
sharedPreferences.setString(Cache.loginTypeKey, Cache().getLoginType().toString());
await setPreferences(prefs, SharePrefsChange.login, customer.customerId!, Cache().firebaseUid!);
}
afterFirebaseLogin() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
sharedPreferences.setString(Cache.loginTypeKey, Cache().getLoginType().toString());
await setPreferences(prefs, SharePrefsChange.login, userLoggedIn!.customerId!, Cache().firebaseUid!);
}
afterFacebookLogin() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
sharedPreferences.setString(Cache.loginTypeKey, Cache().getLoginType().toString());
await setPreferences(prefs, SharePrefsChange.login, userLoggedIn!.customerId!, Cache().firebaseUid!);
}
logout() async {
if (this.accessTokenFacebook != null) {
await FirebaseApi().logOutFacebook();
}
userLoggedIn = null;
firebaseUid = null;
authToken = "";
_trainee = null;
_percentExercises = -1;
_exercisesTrainee = null;
_traineeExercisePlan = null;
_exercises = [];
_myExercisesPlanDetails = LinkedHashMap();
log("Trainees is null? " + (_trainee == null).toString());
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
await setPreferences(prefs, SharePrefsChange.logout, 0, "");
}
Future<void> setPreferences(Future<SharedPreferences> prefs, SharePrefsChange type, int customerId, String firebaseUid) async {
SharedPreferences sharedPreferences;
sharedPreferences = await prefs;
DateTime now = DateTime.now();
sharedPreferences.setString(Cache.lastStoreDateKey, now.toString());
if (type == SharePrefsChange.registration) {
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setBool(Cache.isRegisteredKey, true);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
await initCustomer(customerId);
} else if (type == SharePrefsChange.login) {
sharedPreferences.setInt(Cache.customerIdKey, customerId);
sharedPreferences.setString(Cache.firebaseUidKey, firebaseUid);
sharedPreferences.setBool(Cache.isLoggedInKey, true);
await initCustomer(customerId);
} else if (type == SharePrefsChange.logout) {
sharedPreferences.setBool(Cache.isLoggedInKey, false);
sharedPreferences.setInt(Cache.customerIdKey, 0);
sharedPreferences.setString(Cache.firebaseUidKey, "");
sharedPreferences.setString(authTokenKey, "");
}
initBadges();
}
void setExerciseTypes(List<ExerciseType> exerciseTypes) {
this._exerciseTypes = exerciseTypes;
}
void setExerciseTree(List<ExerciseTree> exerciseTree) {
this._exerciseTree = exerciseTree;
}
void setExercises(List<Exercise> exercises) => this._exercises = exercises;
void setExercisesTrainee(List<Exercise> exercises) {
this._exercisesTrainee = exercises;
}
void setWorkoutMenuTree(LinkedHashMap<String, WorkoutMenuTree> tree) {
this._tree = tree;
}
List<ExerciseType>? getExerciseTypes() => this._exerciseTypes;
ExerciseType? getExerciseTypeById(int exerciseTypeId) {
ExerciseType? exerciseType;
if (_exerciseTypes != null) {
this._exerciseTypes!.forEach((element) {
if (element.exerciseTypeId == exerciseTypeId) {
exerciseType = element;
}
});
}
return exerciseType;
}
List<ExerciseTree>? getExerciseTree() => this._exerciseTree;
List<Exercise>? getExercises() => this._exercises;
List<Exercise>? getExercisesTrainee() => this._exercisesTrainee;
LinkedHashMap<String, WorkoutMenuTree> getWorkoutMenuTree() => this._tree;
void setPercentExercises(double percent) => this._percentExercises = percent;
double getPercentExercises() => this._percentExercises;
void addExercise(Exercise exercise) => _exercises!.add(exercise);
void addExerciseTrainee(Exercise exercise) => _exercisesTrainee!.add(exercise);
Customer? getTrainee() => this._trainee;
void setTrainee(Customer trainee) => _trainee = trainee;
void setTraineeExercisePlan(ExercisePlan exercisePlan) => this._traineeExercisePlan = exercisePlan;
ExercisePlan? getTraineesExercisePlan() => this._traineeExercisePlan;
void setMyExercisePlan(ExercisePlan exercisePlan) => _myExercisePlan = exercisePlan;
ExercisePlan? getMyExercisePlan() => _myExercisePlan;
void setMyExercisePlanDetails(LinkedHashMap<int, ExercisePlanDetail> listExercisePlanDetail) =>
_myExercisesPlanDetails = listExercisePlanDetail;
void addToMyExercisePlanDetails(ExercisePlanDetail detail) => _myExercisesPlanDetails[detail.exerciseTypeId] = detail;
LinkedHashMap<int, ExercisePlanDetail> getMyExercisePlanDetails() => _myExercisesPlanDetails;
void resetMyExercisePlanDetails() => _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
void updateMyExercisePlanDetail(ExercisePlanDetail detail) {
this.addToMyExercisePlanDetails(detail);
}
void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => this.deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId);
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) =>
this._myExercisesPlanDetails[detail.exerciseTypeId]!.change = ModelChange.deleted;
void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) {
this._myExercisesPlanDetails[exerciseTypeId]!.change = ModelChange.delete;
}
void setProperties(List<Property> properties) => this._properties = properties;
List<Property>? getProperties() => _properties;
List<Sport>? getSports() => _sports;
void setSports(List<Sport> sports) => this._sports = sports;
void setDevices(List<ExerciseDevice> devices) => this._devices = devices;
List<ExerciseDevice>? getDevices() => this._devices;
void setCustomerDevices(List<CustomerExerciseDevice> devices) => this._customerDevices = devices;
List<CustomerExerciseDevice>? getCustomerDevices() => this._customerDevices;
LinkedHashMap getBadges() => _badges;
void setBadge(String key, bool inc) {
if (inc) {
if (_badges[key] != null) {
_badges[key] = _badges[key]! + 1;
} else {
_badges[key] = 1;
}
} else {
if (_badges[key] != null) {
if (_badges[key] == 1) {
_badges.remove(key);
} else {
_badges[key] = _badges[key]! - 1;
}
}
}
}
void setBadgeNr(String key, int counter) {
if (_badges[key] != null) {
_badges[key] = _badges[key]! + counter;
} else {
_badges[key] = counter;
}
}
void initBadges() {
CustomerRepository customerRepository = CustomerRepository();
_badges = LinkedHashMap();
if (userLoggedIn == null) {
return;
}
customerRepository.setCustomer(userLoggedIn!);
int _ecto = customerRepository.getCustomerPropertyValue(PropertyEnum.Ectomorph.toStr()).toInt();
int _mezo = customerRepository.getCustomerPropertyValue(PropertyEnum.Mesomorph.toStr()).toInt();
int _endo = customerRepository.getCustomerPropertyValue(PropertyEnum.Endomorph.toStr()).toInt();
//print("endo " + _endo.toString() + " mezo " + _mezo.toString());
if (this.userLoggedIn != null) {
if (this.userLoggedIn!.birthYear == null || this.userLoggedIn!.birthYear == 0) {
setBadge("personalData", true);
setBadge("account", true);
}
if (this._customerDevices == null || this._customerDevices!.isEmpty) {
setBadge("customerDevice", true);
setBadge("account", true);
}
if (userLoggedIn!.properties.isEmpty) {
setBadge("personalData", true);
setBadge("bodyType", true);
setBadge("Sizes", true);
setBadge("BMI", true);
setBadge("BMR", true);
setBadgeNr("My Body", 3);
setBadgeNr("home", 3);
} else if (customerRepository.getWeight() == 0) {
setBadge("BMI", true);
setBadge("BMR", true);
setBadge("My Body", true);
setBadgeNr("home", 1);
}
if (_ecto == 0 && _mezo == 0 && _endo == 0) {
setBadge("account", true);
setBadge("bodyType", true);
}
if (this._exercises == null || this._exercises!.isEmpty) {
setBadge("home", true);
setBadge("Custom Tests", true);
setBadge("Start Training", true);
}
if (customerRepository.getHeight() == 0) {
setBadge("BMI", true);
setBadge("BMR", true);
setBadge("My Body", true);
setBadgeNr("home", 1);
}
if (userLoggedIn!.goal == null) {
setBadge("Goal", true);
setBadge("account", true);
}
if (userLoggedIn!.fitnessLevel == null) {
setBadge("FitnessLevel", true);
setBadge("account", true);
}
if (this._exercises != null && this._exercises!.isNotEmpty) {
if (!activitiesDone[ActivityDone.isExerciseLogSeen.toStr()]!) {
setBadge("exerciseLog", true);
setBadge("development", true);
}
if (!activitiesDone[ActivityDone.isMuscleDevelopmentSeen.toStr()]!) {
setBadge("muscleDevelopment", true);
setBadge("development", true);
}
}
}
log("Badges: " + _badges.toString());
}
List<Product>? get products => _products;
void setProducts(List<wt_product.Product> value) => _products = value;
List<Purchase> get purchases => _purchases;
setPurchases(List<Purchase> value) => _purchases = value;
Future<void> initCustomer(int customerId) async {
log(" *** initCustomer");
try {
await PackageApi().getCustomerPackage(customerId);
} on Exception catch (_) {
return;
}
if (kReleaseMode) {
//FlurryData.setUserId(customerId.toString());
//FlutterUxcam.setUserProperty("username", customerId.toString());
//FlutterUxcam.setUserIdentity(customerId.toString());
//Smartlook.setUserIdentifier(customerId.toString());
//Smartlook.instance.
Track().track(TrackingEvent.enter);
MatomoTracker.instance.setVisitorUserId(customerId.toString());
MatomoTracker.instance.trackEvent(eventCategory: "wt", action: TrackingEvent.enter.enumToString());
Posthog().identify(userId: customerId.toString());
Posthog().capture(eventName: TrackingEvent.enter.enumToString());
}
await Future.forEach(ActivityDone.values, (element) async {
ActivityDone activity = element as ActivityDone;
await isActivityDonePrefs(activity);
});
print("Firebase token save: $firebaseMessageToken");
if (firebaseMessageToken != null) {
userLoggedIn!.firebaseRegToken = firebaseMessageToken;
CustomerRepository customerRepository = CustomerRepository();
customerRepository.customer = userLoggedIn;
customerRepository.saveCustomer();
}
await getMyTrainingPlan();
Cache().startPage = "home";
}
AccessToken? get getAccessTokenFacebook => accessTokenFacebook;
set setAccessTokenFacebook(AccessToken accessTokenFacebook) => this.accessTokenFacebook = accessTokenFacebook;
LoginType? getLoginType() => loginType;
void setLoginType(LoginType type) => this.loginType = type;
List get exercisePlanTemplates => this._exercisePlanTemplates;
setExercisePlanTemplates(value) => this._exercisePlanTemplates = value;
isActivityDonePrefs(ActivityDone activity) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
if (sharedPreferences.getBool(activity.toStr()) != null) {
activitiesDone[activity.toStr()] = sharedPreferences.getBool(activity.toStr())!;
}
return activitiesDone[activity.toStr()]!;
}
setActivityDonePrefs(ActivityDone activity) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
activitiesDone[activity.toStr()] = true;
sharedPreferences.setBool(activity.toStr(), true);
}
bool isActivityDone(ActivityDone activity) => activitiesDone[activity.toStr()] == true;
List<Evaluation>? get evaluations => this._evaluations;
set evaluations(List<Evaluation>? value) => this._evaluations = value;
List<CustomerActivity>? get customerActivities => this._customerActivities;
setCustomerActivities(List<CustomerActivity>? value) => this._customerActivities = value;
List<Tutorial>? get tutorials => this._tutorials;
setTutorials(List<Tutorial>? value) => this._tutorials = value;
FirebaseRemoteConfig? getRemoteConfig() => this.remoteConfig;
setRemoteConfig(FirebaseRemoteConfig? remoteConfig) => this.remoteConfig = remoteConfig;
List<Description>? getDescriptions() => this._descriptions;
setDescriptions(List<Description>? value) => this._descriptions = value;
List<Faq>? getFaqs() => this._faqs;
setFaqs(List<Faq>? value) => this._faqs = value;
List<TrainingPlan>? getTrainingPlans() => this._trainingPlans;
setTrainingPlans(List<TrainingPlan>? value) => this._trainingPlans = value;
List<CustomerTrainingPlan>? getCustomerTrainingPlans() => this._customerTrainingPlans;
setCustomerTrainingPlans(value) => this._customerTrainingPlans = value;
List<SplitTest> getSplitTests() => this._splitTests;
setSplitTests(value) => this._splitTests = value;
List<TrainingPlanDay> getTrainingPlanDays() => this._trainingPlanDays;
setTrainingPlanDays(value) => this._trainingPlanDays = value;
List<CustomerProperty>? getCustomerPropertyAll() => this._customerPropertyAll;
setCustomerPropertyAll(value) => this._customerPropertyAll = value;
addCustomerProperty(CustomerProperty property) {
if (this._customerPropertyAll == null) {
this._customerPropertyAll = [];
}
this._customerPropertyAll!.add(property);
}
}
+128
View File
@@ -0,0 +1,128 @@
import 'dart:collection';
import 'package:intl/intl.dart';
import 'customer_property.dart';
class Customer {
String? name;
String? email;
String? firstname;
String? sex;
int? age;
String? active;
int? customerId;
String? password;
int? birthYear;
String? goal;
String? fitnessLevel;
String? bodyType;
int? admin;
int? trainer;
int? dataPolicyAllowed;
String? firebaseUid;
DateTime? dateAdd;
DateTime? dateChange;
int? emailSubscription;
int? sportId;
DateTime? syncedDate;
DateTime? trialDate;
String? firebaseRegToken;
String? lang;
int? lifeLong;
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
Customer(
{this.customerId,
this.name,
this.firstname,
this.email,
this.sex,
this.age,
this.active,
this.password,
this.birthYear,
this.bodyType,
this.fitnessLevel,
this.goal,
this.admin,
this.trainer,
this.dataPolicyAllowed,
this.firebaseUid,
this.dateAdd,
this.dateChange}) {
dateAdd = DateTime.now();
dateChange = DateTime.now();
}
Customer.fromJson(Map json) {
this.customerId = json['customerId'];
this.name = json['name'];
this.firstname = json['firstname'];
this.email = json['email'];
this.sex = json['sex'];
this.age = json['age'];
this.active = json['active'];
this.birthYear = json['birthYear'];
this.bodyType = json['bodyType'];
this.fitnessLevel = json['fitnessLevel'];
this.goal = json['goal'];
this.admin = json['admin'];
this.lifeLong = json['lifeLong'];
this.trainer = json['trainer'];
this.firebaseUid = json['firebaseUid'];
this.firebaseRegToken = json['firebaseRegToken'];
this.lang = json['lang'];
this.dataPolicyAllowed = json['dataPolicyAllowed'];
this.emailSubscription = json['emailSubscription'];
this.sportId = json['sportId'];
this.syncedDate = json['syncedDate'] == null ? null : DateTime.parse(json['syncedDate']);
this.trialDate = json['trialDate'] == null ? null : DateTime.parse(json['trialDate']);
this.dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']);
this.dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']);
}
Map<String, dynamic> toJson() => {
"name": name,
"firstname": firstname,
"email": email,
"age": age,
"sex": sex,
"active": 'Y',
"password": password,
"birthYear": birthYear,
"bodyType": bodyType,
"fitnessLevel": fitnessLevel,
"goal": goal,
"admin": admin,
"trainer": trainer,
"dataPolicyAllowed": dataPolicyAllowed,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"dateChange": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateChange!),
"emailSubscription": this.emailSubscription,
"sportId": this.sportId,
"syncedDate": this.syncedDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(this.syncedDate!),
"trialDate": this.trialDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(this.trialDate!),
"firebaseRegToken": this.firebaseRegToken,
"lang": this.lang,
"lifeLong": this.lifeLong,
};
@override
String toString() => this.toJson().toString();
double getProperty(String propertyName) {
if (this.properties[propertyName] == null) {
return 0;
} else {
return this.properties[propertyName]!.propertyValue;
}
}
setProperty(String propertyName, double value) {
this.properties[propertyName]!.propertyValue = value;
}
}
+30
View File
@@ -0,0 +1,30 @@
import 'package:intl/intl.dart';
class CustomerActivity {
late int activityId;
late int customerId;
late String type;
late DateTime? dateAdd;
bool? skipped;
CustomerActivity.fromJson(Map json) {
activityId = json['activityId'];
customerId = json['custoemrId'];
type = json['type'];
skipped = json['skipped'];
this.dateAdd = DateTime.parse(json['dateAdd']);
}
Map<String, dynamic> toJson() => {
'activityId': this.activityId,
'customerId': this.customerId,
'type': this.type,
'skipped': this.skipped,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
};
@override
String toString() {
return this.toJson().toString();
}
}
+42
View File
@@ -0,0 +1,42 @@
import 'package:intl/intl.dart';
class CustomerExerciseDevice {
int? customerExerciseDeviceId;
late int exerciseDeviceId;
late int customerId;
late bool favourite;
late DateTime dateAdd;
late String change;
CustomerExerciseDevice({required this.exerciseDeviceId, required this.customerId, required this.favourite}) {
dateAdd = DateTime.now();
}
CustomerExerciseDevice.fromJson(Map json) {
this.customerExerciseDeviceId = json['customerExerciseDeviceId'];
this.exerciseDeviceId = json['exerciseDeviceId'];
this.customerId = json['customerId'];
this.favourite = json['favourite'] == 1 ? true : false;
this.dateAdd = DateTime.parse(json['dateAdd']);
}
Map<String, dynamic> toJson() {
if (customerExerciseDeviceId == null) {
return {
"exerciseDeviceId": exerciseDeviceId,
"customerId": customerId,
"favourite": favourite == true ? 1 : 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
};
} else {
return {
"customerExerciseDeviceId": customerExerciseDeviceId,
"exerciseDeviceId": exerciseDeviceId,
"customerId": customerId,
"favourite": favourite == true ? 1 : 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
};
}
}
}
+69
View File
@@ -0,0 +1,69 @@
import 'package:intl/intl.dart';
class CustomerProperty {
int? customerPropertyId;
late int propertyId;
late int customerId;
DateTime? dateAdd;
String? dateYmd;
String? dateYm;
String? dateY;
late double propertyValue;
bool newData = false;
CustomerProperty(
{required this.propertyId,
required this.customerId,
required this.dateAdd,
required this.propertyValue});
CustomerProperty.fromJson(Map json) {
this.customerPropertyId = json['customerPropertyId'];
this.propertyId = json['propertyId'];
this.customerId = json['customerId'];
this.dateAdd = DateTime.parse(json['dateAdd']);
if (this.dateAdd != null) {
dateYmd = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
dateYm = DateFormat('yyyy-MM').format(this.dateAdd!);
dateY = DateFormat('yyyy').format(this.dateAdd!);
}
this.propertyValue = json['propertyValue'];
print("Json $json, ${this.toString()}");
}
Map<String, dynamic> toJson() {
if (customerPropertyId != null) {
return {
"customerPropertyId": this.customerPropertyId,
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue
};
} else {
return {
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue
};
}
}
String toString() {
Map<String, dynamic> json = {
"customerPropertyId": this.customerPropertyId,
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue,
"dateYmd": this.dateYmd,
"dateYm": this.dateYm,
"dateY": this.dateY,
};
return json.toString();
}
}
+97
View File
@@ -0,0 +1,97 @@
import 'dart:collection';
import 'dart:convert';
// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';
import 'package:workouttest_util/repository/exercise_type_repository.dart';
import 'package:workouttest_util/model/customer_training_plan_details.dart';
enum CustomerTrainingPlanType { custom, template, none }
extension CustomerTrainingPlanTypeExt on CustomerTrainingPlanType {
String toStr() => toString().split(".").last;
bool equalsTo(CustomerTrainingPlanType type) => toString() == type.toString();
bool equalsStringTo(String type) => toStr() == type;
}
class CustomerTrainingPlan {
int? customerTrainingPlanId;
int? customerId;
int? trainingPlanId;
DateTime? dateAdd;
bool? active;
String? status;
String? name;
CustomerTrainingPlanType type = CustomerTrainingPlanType.none;
CustomerTrainingPlan();
List<CustomerTrainingPlanDetails> details = [];
HashMap<String, List<CustomerTrainingPlanDetails>> days = HashMap();
CustomerTrainingPlan.fromJson(Map json) {
customerTrainingPlanId = json['customerTrainingPlanId'];
customerId = json['customerId'];
trainingPlanId = json['trainingPlanId'];
dateAdd = DateTime.parse(json['dateAdd']);
active = json['active'];
status = json['status'];
name = json['name'];
}
CustomerTrainingPlan.fromJsonWithDetails(Map json) {
customerTrainingPlanId = json['customerTrainingPlanId'];
customerId = json['customerId'];
trainingPlanId = json['trainingPlanId'];
dateAdd = json['dateAdd'] != null ? DateTime.parse(json['dateAdd']) : DateTime.now();
active = json['active'];
status = json['status'];
name = json['name'];
try {
final String details = json['details'];
String jsonDetails = details.replaceAllMapped(RegExp(r'([a-zA-Z]+)\:'), (Match m) => "\"${m[1]}\":");
jsonDetails = jsonDetails.replaceAllMapped(RegExp(r'\: ([a-zA-Z /]+)'), (Match m) => ":\"${m[1]}\"");
jsonDetails =
jsonDetails.replaceAllMapped(RegExp(r'([0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})'), (Match m) => "\"${m[0]}\"");
print("detail: $jsonDetails");
Iterable iterable = jsonDecode(jsonDetails);
this.details = iterable.map((detail) => CustomerTrainingPlanDetails.fromJsonWithExerciseList(detail)).toList();
this.details.forEach((detail) {
detail.alternatives = ExerciseTypeRepository.getExerciseTypeAlternatives(detail.exerciseTypeId);
});
} on Exception catch (e) {
print("JsonDecode error " + e.toString());
}
}
Map<String, dynamic> toJson() => {
"customerTrainingPlanId": customerTrainingPlanId,
"customerId": customerId,
"trainingPlanId": trainingPlanId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
"name": name,
"active": active,
"status": status
};
Map<String, dynamic> toJsonWithDetails() => {
"customerTrainingPlanId": customerTrainingPlanId,
"customerId": customerId,
"trainingPlanId": trainingPlanId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!).toString(),
"name": name,
"active": active,
"status": status,
'details': details.isEmpty ? [].toString() : details.map((detail) => detail.toJsonWithExercises()).toList().toString(),
};
@override
String toString() => toJson().toString();
}
@@ -0,0 +1,162 @@
import 'package:workouttest_util/model/cache.dart';
import 'package:workouttest_util/model/exercise.dart';
import 'package:workouttest_util/model/exercise_plan_detail.dart';
import 'package:workouttest_util/model/exercise_type.dart';
import 'package:workouttest_util/repository/training_plan_day_repository.dart';
class CustomerTrainingPlanDetails {
/// customerTrainingPlanDetails
int? customerTrainingPlanDetailsId;
/// trainingPlanDetailsId
int? trainingPlanDetailsId;
/// exerciseTypeId
int? exerciseTypeId;
/// set
int? set;
/// repeats
int? repeats;
/// weight
double? weight;
int? restingTime;
bool? parallel;
String? day;
int? dayId;
/// exerciseType
ExerciseType? exerciseType;
ExercisePlanDetailState state = ExercisePlanDetailState.start;
List<Exercise> exercises = [];
bool isTest = false;
double baseOneRepMax = -1;
List<ExerciseType> alternatives = [];
CustomerTrainingPlanDetails();
CustomerTrainingPlanDetails.fromJson(Map json) {
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.set = json['set'];
this.repeats = json['repeats'];
this.weight = json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'];
this.day = json['day'];
}
CustomerTrainingPlanDetails.fromJsonWithExerciseList(Map json) {
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'] == "null" || json['customerTrainingPlanDetailsId'] == null
? 0
: json['customerTrainingPlanDetailsId'];
this.trainingPlanDetailsId = json['trainingPlanDetailsId'] == "null" ? 0 : json['trainingPlanDetailsId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.set = json['set'];
this.repeats = json['repeats'] == "null" ? -1 : json['repeats'];
this.weight = json['weight'] == "null" ? 0 : json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'] == "false"
? false
: json['parallel'] == "true"
? true
: null;
this.dayId = json['dayId'] == "null" ? null : json['dayId'];
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
this.day = trainingPlanDayRepository.getNameById(this.dayId);
try {
Iterable iterable = json['exercises'];
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
} on Exception catch (e) {
print("JsonDecode error " + e.toString());
}
if (json['state'] == ExercisePlanDetailState.finished.toStr()) {
this.state = ExercisePlanDetailState.finished;
} else if (json['state'] == ExercisePlanDetailState.inProgress.toStr()) {
this.state = ExercisePlanDetailState.inProgress;
} else if (json['state'] == ExercisePlanDetailState.skipped.toStr()) {
this.state = ExercisePlanDetailState.skipped;
} else {
this.state = ExercisePlanDetailState.start;
}
this.isTest = json['isTest'] == "true" ? true : false;
this.exerciseType = Cache().getExerciseTypeById(exerciseTypeId!);
this.baseOneRepMax = json['baseOneRepMax'] == null ? 0 : json['baseOneRepMax'];
}
ExerciseType? getExerciseType() => exerciseType;
Map<String, dynamic> toJson() => {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"exerciseTypeId": this.exerciseTypeId,
"set": this.set,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
"day": this.day == null ? '1.' : this.day,
};
Map<String, dynamic> toJsonWithExercises() {
final Map<String, dynamic> jsonMap = {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"trainingPlanDetailsId": this.trainingPlanDetailsId,
"exerciseTypeId": this.exerciseTypeId,
"set": this.set,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
'exercises': exercises.isEmpty ? [].toString() : exercises.map((exercise) => exercise.toJson()).toList().toString(),
'state': this.state.toStr(),
"isTest": this.isTest,
"dayId": this.dayId,
"baseOneRepMax": this.baseOneRepMax,
};
//print("Detail toJson $jsonMap");
return jsonMap;
}
@override
String toString() => this.toJsonWithExercises().toString();
void copy(CustomerTrainingPlanDetails from) {
this.customerTrainingPlanDetailsId = from.customerTrainingPlanDetailsId;
this.trainingPlanDetailsId = from.trainingPlanDetailsId;
this.exerciseTypeId = from.exerciseTypeId;
this.exerciseType = from.exerciseType;
this.set = from.set;
this.repeats = from.repeats;
this.weight = from.weight;
this.restingTime = from.restingTime;
this.parallel = from.parallel;
this.exercises = from.exercises;
this.state = from.state;
this.isTest = from.isTest;
this.day = from.day;
this.dayId = from.dayId;
this.baseOneRepMax = from.baseOneRepMax;
if (from.exercises.length == 0) {
this.exercises = [];
}
if (from.alternatives.length > 0) {
from.alternatives.forEach((alternative) {
this.alternatives.add(alternative);
});
}
}
}
@@ -0,0 +1,30 @@
class CustomerTrainingPlanExercise {
int? customerTrainingPlanExerciseId;
int? customerTrainingPlanDetailsId;
int? customerId;
int? exerciseId;
double? weight;
int? repeats;
CustomerTrainingPlanExercise();
CustomerTrainingPlanExercise.fromJson(Map json) {
this.customerTrainingPlanExerciseId = json['customerTrainingPlanExerciseId'];
this.customerTrainingPlanDetailsId = json['customerTrainingPlanDetailsId'];
this.customerId = json['customerId'];
this.exerciseId = json['exerciseId'];
this.repeats = json['repeats'];
this.weight = json['weight'];
}
Map<String, dynamic> toJson() => {
"customerTrainingPlanDetailsId": this.customerTrainingPlanDetailsId,
"customerId": this.customerId,
"exerciseId": this.exerciseId,
"weight": this.weight,
"repeats": this.repeats
};
@override
String toString() => this.toJson().toString();
}
+40
View File
@@ -0,0 +1,40 @@
import 'package:workouttest_util/util/app_language.dart';
import 'dart:ui';
class Description {
late int descriptionId;
late String name;
late String description;
int? version;
DateTime? validFrom;
DateTime? validTo;
String? descriptionTranslation;
Description.fromJson(Map json) {
this.descriptionId = json['descriptionId'];
this.name = json['name'];
this.description = json['description'];
this.version = json['version'];
this.validFrom = json['validFrom'];
this.validTo = json['validTo'];
if (json['translations'] != null && json['translations'].length > 0) {
this.descriptionTranslation =
AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['descriptionTranslation'] : json['description'];
}
}
Map<String, dynamic> toJson() => {
"descriptionId": this.descriptionId,
"name": this.name,
"description": this.description,
"version": this.version,
"validFrom": this.validFrom,
"validTo": this.validTo,
"descriptionTranslation": this.descriptionTranslation
};
@override
String toString() => this.toJson().toString();
}
+28
View File
@@ -0,0 +1,28 @@
import 'package:workouttest_util/model/evaluation_attribute.dart';
class Evaluation {
int? evaluationId;
late String name;
int? exerciseTypeId;
String? unit;
late List attributes;
Evaluation.fromJson(Map json) {
evaluationId = json['evaluationId'];
name = json['name'];
exerciseTypeId = json['exerciseTypeId'];
unit = json['unit'];
this.attributes = json['attributes'].map((attr) => EvaluationAttribute.fromJson(attr)).toList();
}
@override
String toString() {
Map<String, dynamic> json = {
'evaluationId': this.evaluationId,
'name': this.name,
'exerciseTypeId': this.exerciseTypeId,
'unit': this.unit
};
return json.toString();
}
}
+41
View File
@@ -0,0 +1,41 @@
class EvaluationAttribute {
late int evaluationAttrId;
int? evaluationId;
late String name;
late String sex;
late int ageMin;
late int ageMax;
late double valueMin;
late double valueMax;
late String evaluationText;
String? suggestion;
EvaluationAttribute.fromJson(Map json) {
evaluationAttrId = json['evaluationAttrId'];
evaluationId = json['evaluationId'];
name = json['name'];
sex = json['sex'];
ageMin = json['ageMin'];
ageMax = json['ageMax'];
valueMin = json['valueMin'];
valueMax = json['valueMax'];
evaluationText = json['evaluation_text'];
suggestion = json['suggestion'];
}
@override
String toString() {
Map<String, dynamic> json = {
'evaluationAttrId': this.evaluationAttrId,
'evaluationId': this.evaluationId,
'name': this.name,
'sex': this.sex,
'ageMin': this.ageMin,
'ageMax': this.ageMax,
'valueMin': this.valueMin,
'valueMax': this.valueMax,
'evaluation_text': this.evaluationText,
};
return json.toString();
}
}
+68
View File
@@ -0,0 +1,68 @@
import 'package:intl/intl.dart';
class Exercise {
int? exerciseId;
int? exerciseTypeId;
int? customerId;
double? quantity;
String? unit;
double? unitQuantity;
DateTime? dateAdd;
int? exercisePlanDetailId;
int? trainingPlanDetailsId;
String? datePart;
double? calculated;
String? summary;
Exercise({this.exerciseTypeId, this.customerId, this.quantity, this.dateAdd});
Exercise.fromJson(Map json) {
this.exerciseId = json['exerciseId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.customerId = json['customerId'];
this.quantity = json['quantity'];
this.unit = json['unit'];
this.unitQuantity = json['unitQuantity'];
this.dateAdd = DateTime.parse(json['dateAdd']);
this.datePart = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
this.calculated = quantity;
this.exercisePlanDetailId = json['exercisePlanDetailId'] == "null" ? null : json['exercisePlanDetailId'];
this.trainingPlanDetailsId = json['trainingPlanDetailsId'] == "null" ? null : json['trainingPlanDetailsId'];
}
Map<String, dynamic> toJson() => {
"exerciseTypeId": exerciseTypeId,
"customerId": customerId,
"quantity": quantity,
"unit": unit,
"unitQuantity": unitQuantity,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"exercisePlanDetailId": exercisePlanDetailId,
"trainingPlanDetailsId": trainingPlanDetailsId,
};
Map<String, dynamic> toJsonDatePart() => {
"exerciseTypeId": exerciseTypeId,
"customerId": customerId,
"quantity": quantity,
'calculated': calculated,
"unit": unit,
"unitQuantity": unitQuantity,
"datePart": this.datePart,
};
Exercise copy() {
Exercise newExercise =
Exercise(exerciseTypeId: this.exerciseTypeId, customerId: this.customerId, quantity: this.quantity, dateAdd: this.dateAdd);
newExercise.unit = this.unit;
newExercise.unitQuantity = this.unitQuantity;
newExercise.exercisePlanDetailId = this.exercisePlanDetailId;
return newExercise;
}
@override
String toString() {
return this.toJson().toString();
}
}
+25
View File
@@ -0,0 +1,25 @@
enum ExerciseAbility { oneRepMax, endurance, running, mini_test_set, paralell_test, training, training_execute, none }
extension ExerciseAbilityExt on ExerciseAbility {
String enumToString() => this.toString().split(".").last;
bool equalsTo(ExerciseAbility ability) => this.toString() == ability.toString();
bool equalsStringTo(String ability) => this.enumToString() == ability;
String get description {
switch (this) {
case ExerciseAbility.endurance:
return "Endurance";
case ExerciseAbility.oneRepMax:
return "One Rep Max";
case ExerciseAbility.running:
return "Running";
case ExerciseAbility.mini_test_set:
return "Compact Test";
case ExerciseAbility.paralell_test:
return "Custom Test";
case ExerciseAbility.training:
return "Training";
default:
return "Compact Test";
}
}
}
+21
View File
@@ -0,0 +1,21 @@
class ExerciseDevice {
late int exerciseDeviceId;
late String name;
late String description;
late String imageUrl;
late String nameTranslation;
late int sort;
late bool place;
bool? isGym;
ExerciseDevice.fromJson(Map json) {
this.exerciseDeviceId = json['exerciseDeviceId'];
this.name = json['name'];
this.description = json['description'];
this.imageUrl = json['imageUrl'];
this.nameTranslation = json['translations'][0]['name'];
this.sort = json['sort'];
this.place = json['place'] == 1 ? true : false;
}
}
+70
View File
@@ -0,0 +1,70 @@
import 'package:intl/intl.dart';
class ExercisePlan {
int? exercisePlanId;
late int customerId;
late String name;
String? description;
late bool private;
late DateTime? dateAdd;
late DateTime dateUpd;
String? type;
int? exercisePlanTemplateId;
ExercisePlan(String name, int customerId) {
this.customerId = customerId;
this.name = name;
this.dateUpd = DateTime.now();
}
ExercisePlan.fromJson(Map json) {
this.exercisePlanId = json['exercisePlanId'];
this.customerId = json['customerId'];
this.name = json['name'];
this.private = json['private'];
this.description = json['description'];
this.dateAdd = (json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']))!;
this.dateUpd = (json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']))!;
this.type = json['type'];
this.exercisePlanTemplateId = json['exercisePlanTemplateId'];
}
Map<String, dynamic> toJson() {
String? formattedDateAdd;
if (dateAdd != null) {
formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd!);
}
String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd);
if (exercisePlanId == null) {
return {
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
} else {
return {
"exercisePlanId": exercisePlanId,
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
}
}
@override
String toString() {
Map<String, dynamic> json = toJson();
return json.toString();
}
}
+91
View File
@@ -0,0 +1,91 @@
import 'dart:convert';
import 'package:workouttest_util/model/exercise.dart';
import 'package:workouttest_util/model/exercise_type.dart';
enum ExercisePlanDetailState { start, inProgress, skipped, finished, extra }
extension ExericisePlanDetailStateExt on ExercisePlanDetailState {
bool equalsTo(ExercisePlanDetailState state) => this.toString() == state.toString();
bool equalsStringTo(String state) => this.toString() == state;
String toStr() => this.toString().split(".").last;
}
class ExercisePlanDetail {
int? exercisePlanDetailId;
int? exercisePlanId;
late int exerciseTypeId;
int? serie;
int? repeats;
String? weightEquation;
/// List<Exercise>
List<Exercise>? exercises;
/// bool finished
bool? finished;
ExercisePlanDetailState state = ExercisePlanDetailState.start;
ExerciseType? exerciseType;
String? change; // 1: update -1:delete 0: new
ExercisePlanDetail(int exerciseTypeId) {
this.exerciseTypeId = exerciseTypeId;
}
ExercisePlanDetail.fromJson(Map json) {
this.exercisePlanDetailId = json['exercisePlanDetailId'];
this.exercisePlanId = json['exercisePlanId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.serie = json['serie'];
this.repeats = json['repeats'];
this.weightEquation = json['weightEquation'];
}
ExercisePlanDetail.fromJsonWithExerciseList(Map json) {
this.exercisePlanDetailId = json['exercisePlanDetailId'];
this.exercisePlanId = json['exercisePlanId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.serie = json['serie'];
this.repeats = json['repeats'];
this.weightEquation = json['weightEquation'];
try {
final String exercises = json['exercises'];
String jsonExercises = exercises.replaceAllMapped(
RegExp(r'([a-zA-Z]+|[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})'), (Match m) => "\"${m[0]}\"");
jsonExercises = jsonExercises.replaceAll(r'\"null\"', 'null');
//print("Exercises $jsonExercises");
Iterable iterable = jsonDecode(jsonExercises);
this.exercises = iterable.map((exercise) => Exercise.fromJson(exercise)).toList();
} on Exception catch (e) {
print("JsonDecode error " + e.toString());
}
}
Map<String, dynamic> toJson() => {
"exercisePlanId": exercisePlanId == null ? 0 : exercisePlanId,
"exerciseTypeId": exerciseTypeId,
"serie": serie,
"repeats": repeats,
"weightEquation": weightEquation
};
Map<String, dynamic> toJsonWithExerciseList() => {
"exercisePlanDetailId": exercisePlanDetailId,
"exercisePlanId": exercisePlanId,
"exerciseTypeId": exerciseTypeId,
"serie": serie,
"repeats": repeats,
"weightEquation": weightEquation,
'exercises': exercises == null ? [].toString() : exercises!.map((exercise) => exercise.toJson()).toList().toString(),
};
@override
String toString() {
Map<String, dynamic> json = toJsonWithExerciseList();
return json.toString();
}
}
+50
View File
@@ -0,0 +1,50 @@
import 'dart:ui';
import 'package:workouttest_util/util/app_language.dart';
class ExercisePlanTemplate {
late int? exercisePlanTemplateId;
late String name;
late String description;
late String templateType;
late String nameTranslation;
late String descriptionTranslation;
List<int> exerciseTypes = [];
ExercisePlanTemplate.fromJson(Map json) {
this.exercisePlanTemplateId = json['exercisePlanId'];
this.name = json['name'];
this.description = json['description'];
this.templateType = json['templateType'];
if (json['translations'].length > 0) {
this.nameTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['name'] : json['name'];
this.descriptionTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['description'] : json['description'];
}
if (json['details'] != null && (json['details']).length > 0) {
final List details = json['details'];
details.sort((a, b) {
if (a['sort'] == null || b['sort'] == null) {
return a['exercisePlanTemplateDetailId'] < b['exercisePlanTemplateDetailId'] ? -1 : 1;
} else {
return a['sort'] < b['sort'] ? -1 : 1;
}
});
details.forEach((element) {
exerciseTypes.add(element['exerciseTypeId']);
});
}
}
Map<String, dynamic> toJson() {
return {
"exercisePlanTemplateId": exercisePlanTemplateId,
"name": name,
"description": "description",
"templateType": templateType,
"nameTranslation": nameTranslation,
"descriptionTranslation": descriptionTranslation,
"exerciseTypes": exerciseTypes.toString()
};
}
}
+46
View File
@@ -0,0 +1,46 @@
import 'package:workouttest_util/model/result.dart';
import 'package:intl/intl.dart';
class ExerciseResult {
late int? exerciseResultId;
late int customerId;
late int exerciseId;
late int exercisePlanId;
late String resultType;
late double value;
late DateTime dateFrom;
late DateTime? dateTo;
ResultExt? resultExtension;
ExerciseResult();
Map<String, dynamic> toJson() {
String? formattedDateTo;
if (dateTo != null) {
formattedDateTo = DateFormat('yyyy-MM-dd HH:mm').format(dateTo!);
}
return {
"customerId": customerId,
"exerciseId": exerciseId,
"exercisePlanId": exercisePlanId,
"resultType": resultType,
"value": value,
"dateFrom": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateFrom),
"dateTo": formattedDateTo,
};
}
ExerciseResult.fromJson(Map json) {
this.exerciseResultId = json['exerciseResultId'];
this.exerciseId = json['exerciseId'];
this.exercisePlanId = json['exercisePlanId'];
this.customerId = json['customerId'];
this.resultType = json['resultType'];
this.value = json["value"];
this.dateFrom = DateTime.parse(json['dateFrom']);
this.dateTo = DateTime.parse(json['dateTo']);
this.resultExtension = ResultExt(itemString: this.resultType);
}
}
+76
View File
@@ -0,0 +1,76 @@
class ExerciseTree {
/// treeId
late int treeId;
/// parentId
late int parentId;
/// name
late String name;
/// imageUrl
late String imageUrl;
/// active
late bool active;
/// nameTranslation
late String nameTranslation;
/// sort
int? sort;
String? internalName;
String? description;
String? descriptionTranslation;
ExerciseTree();
ExerciseTree.fromJson(Map json) {
this.treeId = json['treeId'];
this.name = json['name'];
this.parentId = 0;
this.imageUrl = json['imageUrl'];
this.active = json['active'];
this.nameTranslation = json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['name'] : this.name;
this.descriptionTranslation =
json['translations'] != null && (json['translations']).length > 0 && json['translations'][0]['description'] != null
? json['translations'][0]['description']
: this.description;
this.sort = 99;
this.internalName = json['internalName'];
}
Map<String, dynamic> toJson() {
return {
"treeId": treeId,
"parentId": parentId,
"name": name,
"description": description,
"imageUrl": imageUrl,
"active": active.toString(),
"nameTranslation": nameTranslation,
"descriptionTranslation": descriptionTranslation,
"sort": sort,
};
}
@override
String toString() => this.toJson().toString();
ExerciseTree copy(int parentId) {
ExerciseTree newTree = ExerciseTree();
newTree.treeId = this.treeId;
newTree.name = this.name;
newTree.imageUrl = this.imageUrl;
newTree.nameTranslation = this.nameTranslation;
if (parentId != -1) {
newTree.parentId = parentId;
}
newTree.active = this.active;
newTree.sort = this.sort == null ? 99 : this.sort;
return newTree;
}
}
+13
View File
@@ -0,0 +1,13 @@
class ExerciseTreeParents {
late int exerciseTreeParentsId;
late int exerciseTreeParentId;
late int exerciseTreeChildId;
late int sort;
ExerciseTreeParents.fromJson(Map json) {
this.exerciseTreeParentsId = json['exerciseTreeParentsId'];
this.exerciseTreeParentId = json['exerciseTreeParentId'];
this.exerciseTreeChildId = json['exerciseTreeChildId'];
this.sort = json['sort'];
}
}
+134
View File
@@ -0,0 +1,134 @@
import 'package:workouttest_util/model/exercise_ability.dart';
import 'package:workouttest_util/util/app_language.dart';
import 'package:workouttest_util/util/enums.dart';
import 'package:flutter/material.dart';
class ExerciseType {
///exerciseTypeId
late int exerciseTypeId;
/// name
late String name;
/// description
late String description;
/// unit
late String unit;
/// unitQuantity
String? unitQuantity;
/// unitQuantityUnit
String? unitQuantityUnit;
///active
late bool active;
/// base
late bool base;
late bool buddyWarning;
/// imageUrl
String imageUrl = "";
/// nameTranslation
String nameTranslation = "";
/// descriptionTranslation
String descriptionTranslation = "";
/// devices[]
List<int> devices = [];
/// parents[]
List<int> parents = [];
/// alternatives []
List<int> alternatives = [];
/// ability
ExerciseAbility? ability;
/// TrainingPlanState - whether the exercise_type exists in the
/// custom training plan
ExerciseTypeTrainingPlanState trainingPlanState = ExerciseTypeTrainingPlanState.none;
ExerciseType({required this.name, required this.description});
ExerciseType.fromJson(Map json) {
this.exerciseTypeId = json['exerciseTypeId'];
//this.treeId = json['treeId'];
this.name = json['name'];
this.description = json['description'];
this.unit = json['unit'];
this.unitQuantity = json['unitQuantity'];
this.unitQuantityUnit = json['unitQuantityUnit'];
this.active = json['active'];
this.base = json['base'];
this.buddyWarning = json['buddyWarning'];
if (json['images'].length > 0) {
this.imageUrl = json['images'][0]['url'];
}
if (json['translations'].length > 0) {
this.nameTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['name'] : json['name'];
this.descriptionTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['description'] : json['description'];
}
if (json['devices'].length > 0) {
final List jsonDevices = json['devices'];
jsonDevices.forEach((device) {
this.devices.add(device['exerciseDeviceId']);
});
}
if (json['parents'].length > 0) {
final List jsonParents = json['parents'];
jsonParents.forEach((parent) {
this.parents.add(parent['exerciseTreeId']);
});
}
if (json['alternatives'].length > 0) {
final List jsonAlternatives = json['alternatives'];
jsonAlternatives.forEach((alternative) {
this.alternatives.add(alternative['exerciseTypeChildId']);
});
}
}
Map<String, dynamic> toJson() => {
"name": name,
"description": description,
"unit": unit,
"unitQuantity": unitQuantity,
"unitQuantityUnit": unitQuantityUnit,
"active": active,
"base": base,
"buddyWarning": buddyWarning,
"devices": this.devices.toString(),
"nameTranslation": this.nameTranslation,
"parents": this.parents.toString()
};
void setAbility(ExerciseAbility ability) {
this.ability = ability;
}
ExerciseAbility getAbility() {
return this.ability!;
}
bool is1RM() {
return this.ability!.equalsTo(ExerciseAbility.oneRepMax);
}
@override
String toString() {
return this.toJson().toString();
}
}
+11
View File
@@ -0,0 +1,11 @@
class ExerciseTypeDevice {
late int exerciseTypeDeviceId;
late int exerciseDeviceId;
ExerciseTypeDevice();
ExerciseTypeDevice.fromJson(Map json) {
this.exerciseTypeDeviceId = json['exerciseTypeDeviceId'];
this.exerciseDeviceId = json['exerciseDeviceId'];
}
}
+37
View File
@@ -0,0 +1,37 @@
import 'dart:collection';
class Faq {
late int faqId;
late String name;
late String description;
int? sort;
HashMap<String, String> nameTranslations = HashMap();
HashMap<String, String> descriptionTranslations = HashMap();
Faq.fromJson(Map json) {
this.faqId = json['faqId'];
this.name = json['name'];
this.description = json['description'];
this.sort = json['sort'];
nameTranslations['en'] = name;
descriptionTranslations['en'] = description;
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
nameTranslations[translation['languageCode']] = translation['nameTranslation'];
descriptionTranslations[translation['languageCode']] = translation['descriptionTranslation'];
});
}
}
Map<String, dynamic> toJson() => {
"faqId": this.faqId,
"name": this.name,
"description": this.description,
"nameTranslation": this.nameTranslations.toString(),
};
@override
String toString() => this.toJson().toString();
}
+67
View File
@@ -0,0 +1,67 @@
class FitnessState {
late final String value;
late final String stateText;
late final String explanation;
static String beginner = "beginner";
static String intermediate = "intermediate";
static String advanced = "advanced";
static String professional = "professional";
FitnessState({required this.value, required this.stateText, required this.explanation});
bool isEqual(FitnessState? state) {
if (state == null) {
return false;
}
return state.value == this.value;
}
@override
String toString() {
return stateText;
}
}
class FitnessItem {
static final FitnessItem _singleton = FitnessItem._internal();
List<FitnessState> elements = [];
factory FitnessItem() {
return _singleton;
}
FitnessItem._internal() {
elements.add(FitnessState(
value: FitnessState.beginner, stateText: _capitalize(FitnessState.beginner), explanation: "I am " + FitnessState.beginner));
elements.add(FitnessState(
value: FitnessState.intermediate,
stateText: _capitalize(FitnessState.intermediate),
explanation: "I am " + FitnessState.intermediate));
elements.add(FitnessState(
value: FitnessState.advanced, stateText: _capitalize(FitnessState.advanced), explanation: "I am " + FitnessState.advanced));
elements.add(FitnessState(
value: FitnessState.professional,
stateText: _capitalize(FitnessState.professional),
explanation: "I am " + FitnessState.professional));
}
String _capitalize(String value) {
return "${value[0].toUpperCase()}${value.substring(1)}";
}
List<FitnessState> toList() => elements;
FitnessState? getItem(String? value) {
if (value == null || value.length == 0) {
return elements[0];
}
FitnessState? selected;
elements.forEach((element) {
if (element.value == value) {
selected = element;
}
});
return selected;
}
}
+46
View File
@@ -0,0 +1,46 @@
class Mautic {
late int formId;
String? firstname;
String? lastname;
String? email;
String? fitnessLevel;
String? goal;
int? databaseId;
String? subscriptionDate;
String? language;
String? purchaseDate;
String? exerciseDate;
String? trialDate;
Map<String, dynamic> toJson() => {
"formId": formId,
"firstname": firstname,
"lastname": lastname,
"email": email,
"fitnessLevel": fitnessLevel,
"goal": goal,
"databaseId": databaseId,
"subscriptionDate": subscriptionDate,
"lang": language
};
String toForm() {
String form = "mauticform[formId]=$formId";
form += email == null ? "" : "&mauticform[email]=$email";
form += lastname == null ? "" : "&mauticform[f_name]=$lastname";
form += firstname == null ? "" : "&mauticform[firstname]=$firstname";
form += fitnessLevel == null ? "" : "&mauticform[fitness_level]=$fitnessLevel";
form += goal == null ? "" : "&mauticform[goal]=$goal";
form += subscriptionDate == null ? "" : "&mauticform[subscribed]=$subscriptionDate";
form += databaseId == null ? "" : "&mauticform[databaseid]=$databaseId";
form += language == null ? "" : "&mauticform[lang]=$language";
form += purchaseDate == null ? "" : "&mauticform[purchase_date]=$purchaseDate";
form += exerciseDate == null ? "" : "&mauticform[last_exercise]=$exerciseDate";
form += trialDate == null ? "" : "&mauticform[trialdate]=$trialDate";
return form;
}
@override
String toString() => this.toJson().toString();
}
+7
View File
@@ -0,0 +1,7 @@
class ModelChange {
static const String add = "add";
static const String delete = "delete";
static const String update = "update";
static const String deleted = "deleted";
static const String saved = "saved";
}
+53
View File
@@ -0,0 +1,53 @@
class Product {
late int productId;
late String name;
late String description;
late String type;
late String appVersion;
late int sort;
late int productSet;
late DateTime validFrom;
late DateTime? validTo;
late String? productIdIos;
late String? productIdAndroid;
late double? priceIos;
late double? priceAndroid;
String? localizedPrice;
Product.fromJson(Map json) {
this.productId = json['productId'];
this.name = json['name'];
this.description = json['description'];
this.type = json['type'];
this.appVersion = json['appVersion'];
this.sort = json['sort'];
this.productSet = json['productSet'];
this.validFrom = (json['validFrom'] == null ? null : DateTime.parse(json['validFrom']))!;
this.validTo = json['validTo'] == null ? null : DateTime.parse(json['validTo']);
this.productIdIos = json['productIdIos'];
this.productIdAndroid = json['productIdAndroid'];
this.priceIos = json['priceIos'];
this.priceAndroid = json['priceAndroid'];
}
@override
String toString() {
Map<String, dynamic> json = {
'productId': this.productId,
'name': this.name,
'description': this.description,
'type': this.type,
'appVersion': this.appVersion,
'sort': this.sort,
'productSet': this.productSet,
'validFrom': this.validFrom,
'validTo': validTo,
'productIdIos': this.productIdIos,
'productIdAndroid': this.productIdAndroid,
'priceIos': this.priceIos,
'priceAndroid': this.priceAndroid,
'localizedPrice': this.localizedPrice
};
return json.toString();
}
}
+28
View File
@@ -0,0 +1,28 @@
class Property {
late int propertyId;
late String propertyName;
late String propertyUnit;
late String propertyNameTranslation;
int? top;
int? left;
double? value;
Property.fromJson(Map json) {
this.propertyId = json['propertyId'];
this.propertyName = json['propertyName'];
this.propertyUnit = json['propertyUnit'];
this.propertyNameTranslation =
json['translations'] != null && (json['translations']).length > 0
? json['translations'][0]['propertyName']
: this.propertyName;
}
String toString() {
Map<String, dynamic> json = {
"propertyId": propertyId,
"propertyName": propertyName,
"propertyUnit": propertyUnit
};
return json.toString();
}
}
+31
View File
@@ -0,0 +1,31 @@
import 'package:intl/intl.dart';
class Purchase {
int? purchaseId;
late int customerId;
late int productId;
late DateTime dateAdd;
late double purchaseSum;
late String currency;
Purchase({required this.customerId, required this.productId});
Purchase.fromJson(Map json) {
this.purchaseId = json['purchaseId'];
this.customerId = json['customerId'];
this.productId = json['productId'];
this.dateAdd = DateTime.parse(json['dateAdd']);
this.purchaseSum = json['purchaseSum'];
this.currency = json['currency'];
}
Map<String, dynamic> toJson() => {
"purchaseId": purchaseId,
"customerId": customerId,
"productId": productId,
"purchaseSum": purchaseSum,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
"currency": currency,
};
}
+101
View File
@@ -0,0 +1,101 @@
enum ResultItem {
calorie,
development_percent_bodypart,
distance,
fatburn_percent,
bpm_avg,
bpm_min,
bpm_max,
speed_max,
reps_volume,
steps,
//time,
weight_volume
}
extension ResultItemExt on ResultItem {
static const ResultItemDesc = {
ResultItem.calorie: "Calorie",
ResultItem.development_percent_bodypart: "Development in %",
ResultItem.distance: "Distance",
ResultItem.bpm_avg: "Average BPM",
ResultItem.bpm_min: "Min BPM",
ResultItem.bpm_max: "Max BPM",
ResultItem.speed_max: "Max speed",
ResultItem.reps_volume: "Repeats volume",
ResultItem.steps: "Steps",
//ResultItem.time: "Time",
ResultItem.weight_volume: "Weight volume",
ResultItem.fatburn_percent: "Fatburn %",
};
static const ResultItemImg = {
ResultItem.calorie: "pict_calorie.png",
ResultItem.development_percent_bodypart: "pic_development_by_bodypart_percent.png",
ResultItem.distance: "pict_distance_m.png",
ResultItem.bpm_avg: "pict_hravg_bpm.png",
ResultItem.bpm_min: "pict_hrmin_bpm.png",
ResultItem.bpm_max: "pict_hrmax_bpm.png",
ResultItem.speed_max: "pict_maxspeed_kmh.png",
ResultItem.reps_volume: "pict_reps_volumen_db.png",
ResultItem.steps: "pict_steps.png",
//ResultItem.time: "pict_time_h.png",
ResultItem.weight_volume: "pict_weight_volumen_tonna.png",
ResultItem.fatburn_percent: "pict_fatburn_percent.png",
};
static const HardwareData = {
ResultItem.calorie: true,
ResultItem.development_percent_bodypart: false,
ResultItem.distance: true,
ResultItem.bpm_avg: true,
ResultItem.bpm_min: true,
ResultItem.bpm_max: true,
ResultItem.speed_max: true,
ResultItem.reps_volume: false,
ResultItem.steps: true,
//ResultItem.time: false,
ResultItem.weight_volume: false,
ResultItem.fatburn_percent: true,
};
bool equals(ResultItem item) => this.toString() == item.toString();
bool equalsString(String item) => this.description == item;
String? get description => ResultItemDesc[this];
String? get image => ResultItemImg[this];
bool? get isHardware => HardwareData[this];
String? displayString() => description;
}
class ResultExt {
late final String itemString;
late ResultItem item;
double data = 0;
int? exerciseId;
DateTime? dateFrom;
DateTime? dateTo;
ResultExt({required this.itemString}) {
ResultItem.values.forEach((element) {
if (element.equalsString(itemString)) {
item = element;
}
});
}
String? getDescription() => item.description;
String getImage() => "asset/image/" + item.image!;
bool? isHardware() => item.isHardware;
int? get getExerciseId => exerciseId;
set setExerciseId(int exerciseId) => this.exerciseId = exerciseId;
set setDateFrom(DateTime dateFrom) => this.dateFrom = dateFrom;
DateTime? get getDateFrom => dateFrom;
set setDateTo(DateTime dateTo) => this.dateTo = dateTo;
DateTime? get getDateTo => dateTo;
bool equals(ResultItem item) => this.item.equals(item);
bool equalsString(String item) => this.item.equalsString(item);
}
+36
View File
@@ -0,0 +1,36 @@
class SplitTest {
late int testId;
late String name;
late String remoteConfigKey;
late String remoteConfigValue;
late String testValue;
String? source;
late bool active;
DateTime? validTo;
SplitTest.fromJson(Map json) {
this.testId = json['testId'];
this.name = json['name'];
this.remoteConfigKey = json['remoteConfigKey'];
this.remoteConfigValue = json['remoteConfigValue'];
this.testValue = json['testValue'];
this.source = json['source'];
this.active = json['active'];
this.validTo = json['validTo'] == null ? null : DateTime.parse(json['validTo']);
}
@override
String toString() {
Map<String, dynamic> json = {
'productId': this.testId,
'name': this.name,
'remoteConfigKey': this.remoteConfigKey,
'remoteConfigValue': this.remoteConfigValue,
'testValue': this.testValue,
'source': this.source,
'active': this.active,
'validTo': validTo,
};
return json.toString();
}
}
+30
View File
@@ -0,0 +1,30 @@
import 'dart:collection';
class Sport {
late int sportId;
late String name;
HashMap<String, String> nameTranslations = HashMap();
Sport.fromJson(Map json) {
this.sportId = json['sportId'];
this.name = json['name'];
nameTranslations['en'] = name;
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
nameTranslations[translation['languageCode']] = translation['sportName'];
});
}
}
Map<String, dynamic> toJson() => {
"sportId": sportId,
"name": name,
};
@override
String toString() {
return this.toJson().toString();
}
}
+24
View File
@@ -0,0 +1,24 @@
import 'dart:io';
import 'package:workouttest_util/model/cache.dart';
import 'package:intl/intl.dart';
class Tracking {
late int customerId;
late DateTime dateAdd;
late String event;
String? eventValue;
late String area;
late String platform;
late String version;
Map<String, dynamic> toJson() => {
"customerId": customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd),
"event": event,
"eventValue": eventValue,
"area": Platform.localeName,
"platform": Platform.isAndroid ? "Android" : "iOS",
"version": Cache().packageInfo != null ? Cache().packageInfo!.version + "+" + Cache().packageInfo!.buildNumber : ""
};
}
@@ -0,0 +1,33 @@
import 'package:workouttest_util/model/exercise_plan_detail.dart';
import 'package:workouttest_util/model/exercise_type.dart';
import 'package:flutter/material.dart';
enum TrainingEvaluationExerciseType { weightBased, repeatBased, secondBased }
extension TrainingEvaluationExerciseTypeExt on TrainingEvaluationExerciseType {
String toStr() => this.toString().split(".").last;
bool equalsTo(TrainingEvaluationExerciseType value) => this.toString() == value.toString();
bool equalsStringTo(String value) => this.toString() == value;
}
class TrainingEvaluationExercise {
late int exerciseTypeId;
late String name;
late TrainingEvaluationExerciseType type;
late ExerciseType exerciseType;
int? repeats;
int? maxRepeats;
double? totalLift;
double? maxTotalLift;
double? oneRepMax;
double? max1RM;
late double? trend;
late String trendText;
late Color trendColor;
late ExercisePlanDetailState state;
}
+74
View File
@@ -0,0 +1,74 @@
import 'dart:collection';
import 'package:workouttest_util/model/training_plan_detail.dart';
class TrainingPlan {
late int trainingPlanId;
String? type;
late String name;
String? internalName;
String? description;
late bool free;
late bool active;
int? treeId;
HashMap<String, String> nameTranslations = HashMap();
HashMap<String, String> descriptionTranslations = HashMap();
List<TrainingPlanDetail>? details;
TrainingPlan.fromJson(Map<String, dynamic> json) {
this.trainingPlanId = json['trainingPlanId'];
this.name = json['name'];
this.type = json['type'];
this.internalName = json['internalName'];
this.description = json['description'];
this.free = json['free'];
this.active = json['active'];
this.treeId = json['treeId'];
nameTranslations['en'] = name;
descriptionTranslations['en'] = description ?? "";
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
nameTranslations[translation['languageCode']] = translation['nameTranslation'];
descriptionTranslations[translation['languageCode']] = translation['descriptionTranslation'];
});
}
if (json['details'] != null && json['details'].length > 0) {
details = json['details'].map<TrainingPlanDetail>((detail) => TrainingPlanDetail.fromJson(detail)).toList();
if (details != null && details!.isNotEmpty) {
details!.sort((a, b) {
if (a.sort == 0 || b.sort == 0) {
if (a.trainingPlanDetailId <= b.trainingPlanDetailId) {
return -1;
} else {
return 1;
}
}
if (a.sort <= b.sort) {
return -1;
} else {
return 1;
}
});
}
}
}
Map<String, dynamic> toJson() => {
"trainingPlanId": this.trainingPlanId,
"treeId": this.treeId,
"name": this.name,
"type": this.type,
"internalName": this.internalName,
"free": this.free,
"active": this.active,
"description": this.description,
"nameTranslation": this.nameTranslations.toString(),
};
@override
String toString() => this.toJson().toString();
}
+29
View File
@@ -0,0 +1,29 @@
import 'dart:collection';
class TrainingPlanDay {
late int dayId;
late String name;
HashMap<String, String> nameTranslations = HashMap();
TrainingPlanDay.fromJson(Map json) {
this.dayId = json['dayId'];
this.name = json['name'];
nameTranslations['en'] = name;
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
nameTranslations[translation['languageCode']] = translation['nameTranslation'];
});
}
}
Map<String, dynamic> toJson() => {
"dayId": this.dayId,
"name": this.name,
"nameTranslation": this.nameTranslations.toString(),
};
@override
String toString() => this.toJson().toString();
}
+44
View File
@@ -0,0 +1,44 @@
class TrainingPlanDetail {
late int trainingPlanDetailId;
int? trainingPlanId;
late int exerciseTypeId;
late int sort;
late int set;
int? repeats;
double? weight;
int? restingTime;
bool? parallel;
int? dayId;
String? day;
String? summary;
TrainingPlanDetail.fromJson(Map<String, dynamic> json) {
this.trainingPlanDetailId = json['trainingPlanDetailId'];
this.trainingPlanId = json['trainingPlanId'];
this.exerciseTypeId = json['exerciseTypeId'];
this.sort = json['sort'];
this.set = json['set'];
this.repeats = json['repeats'];
this.weight = json['weight'];
this.restingTime = json['restingTime'];
this.parallel = json['parallel'];
this.dayId = json['dayId'];
}
Map<String, dynamic> toJson() => {
"trainingPlanDetailId": this.trainingPlanDetailId,
"trainingPlanId": this.trainingPlanId,
"exerciseType": this.exerciseTypeId,
"sort": this.sort,
"repeats": this.repeats,
"weight": this.weight,
"restingTime": this.restingTime,
"parallel": this.parallel,
"dayId": this.dayId,
"day": this.day,
"summary": this.summary,
};
@override
String toString() => this.toJson().toString();
}
+29
View File
@@ -0,0 +1,29 @@
import 'package:workouttest_util/model/exercise.dart';
import 'package:flutter/material.dart';
class TrainingResult {
final Exercise? exercise;
final String eventName;
final DateTime from;
final DateTime to;
Color background;
Color color;
final bool isAllDay;
final bool isTest;
final bool isExercise;
String? summary;
bool search = false;
TrainingResult({
required this.eventName,
required this.from,
required this.to,
required this.background,
required this.color,
required this.isAllDay,
required this.exercise,
required this.isTest,
required this.isExercise,
this.summary,
});
}
+37
View File
@@ -0,0 +1,37 @@
import 'package:workouttest_util/model/tutorial_step.dart';
enum TutorialEnum { basic, development, training }
class Tutorial {
late int tutorialId;
late String name;
List<TutorialStep>? steps;
Tutorial.fromJson(Map<String, dynamic> json) {
this.tutorialId = json['tutorialId'];
this.name = json['name'];
if (json['steps'] != null && json['steps'].length > 0) {
steps = json['steps'].map<TutorialStep>((step) => TutorialStep.fromJson(step)).toList();
if (steps != null) {
steps!.sort((a, b) {
if (a.step == null || b.step == null) {
return -1;
} else {
if (a.step! <= b.step!) {
return -1;
} else {
return 1;
}
}
});
}
}
}
Map<String, dynamic> toJson() => {'tutorialId': this.tutorialId, 'name': this.name, 'steps': steps.toString()};
@override
String toString() => this.toJson().toString();
}
+98
View File
@@ -0,0 +1,98 @@
import 'dart:ui';
import 'dart:convert';
import 'package:workouttest_util/util/app_language.dart';
enum TutorialEnum { basic, development, training }
class TutorialStepAction {
late String direction;
late int top;
late int left;
late bool showBubble;
late int bubbleX;
late int bubbleY;
late int bubbleWidth;
late int bubbleHeight;
late bool showCheckText;
late int parent;
TutorialStepAction.fromJson(Map json) {
this.direction = json['direction'];
this.top = json['top'];
this.left = json['left'];
this.showBubble = json['show_bubble'];
this.bubbleX = json['bubble_x'];
this.bubbleY = json['bubble_y'];
this.bubbleWidth = json['bubble_width'];
this.bubbleHeight = json['bubble_height'];
this.showCheckText = json['show_check_text'];
this.parent = json['parent'];
}
Map<String, dynamic> toJson() => {
"direction": this.direction,
"top": this.top,
"left": this.left,
"showBubble": this.showBubble,
"bubbleX": this.bubbleX,
"bubbleY": this.bubbleY,
"bubbleWidth": this.bubbleWidth,
"bubbleHeight": this.bubbleHeight,
"showCheckText": this.showCheckText,
"parent": this.parent,
};
@override
String toString() => this.toJson().toString();
}
class TutorialStep {
int? tutorialStepId;
int? tutorialId;
int? step;
String? tutorialText;
String? direction;
String? checkText;
String? condition;
String? branch;
int? parentId;
TutorialStepAction? action;
String? tutorialTextTranslation;
String? errorTextTranslation;
TutorialStep.fromJson(Map json) {
this.tutorialStepId = json['tutorialStepId'];
this.tutorialId = json['tutorialId'];
this.step = json['step'];
this.tutorialText = json['tutorialText'];
this.checkText = json['checkText'];
this.condition = json['condition'];
if (this.condition != null) {
this.condition = condition!.replaceAll(r'\\', "replace");
this.action = TutorialStepAction.fromJson(jsonDecode(condition!));
}
if (json['translations'] != null && json['translations'].length > 0) {
this.tutorialTextTranslation =
AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['tutorialText'] : json['tutorialText'];
this.errorTextTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['errorText'] : json['errorText'];
}
}
Map<String, dynamic> toJson() => {
"tutorialStepId": this.tutorialStepId,
"tutorialId": this.tutorialId,
"step": this.step,
"tutorialText": this.tutorialText,
"checkText": this.checkText,
"tutorialTextTranslation": this.tutorialTextTranslation,
"errorTextTranslation": this.errorTextTranslation,
"condition": this.condition,
"action": this.action != null ? this.action!.toJson() : ""
};
@override
String toString() => this.toJson().toString();
}
+14
View File
@@ -0,0 +1,14 @@
class User {
String? email;
String? password;
int? customerId;
String? firebaseUid;
User();
Map<String, dynamic> toJson() => {
"username": email,
"password": password,
"firebaseUid": firebaseUid,
};
}
+86
View File
@@ -0,0 +1,86 @@
import 'dart:ui';
import 'exercise_type.dart';
enum WorkoutType { endurance, oneRepMax, cardio, staticExercise }
extension WorkoutTypeExt on WorkoutType {
static const WorkoutTypeMenu = {
WorkoutType.endurance: "Endurance",
WorkoutType.cardio: "Cardio",
WorkoutType.oneRepMax: "One Rep Max",
WorkoutType.staticExercise: "Static"
};
bool equals(WorkoutType type) => this.toString() == type.toString();
bool equalsString(String type) => this.toString() == type;
String? get menu => WorkoutTypeMenu[this];
}
class WorkoutMenuTree {
late int id;
late int parent;
late String name;
late String imageName;
late Color color;
late double fontSize;
late bool child;
late int exerciseTypeId;
ExerciseType? exerciseType;
late bool base;
late bool is1RM;
late bool isRunning;
List<WorkoutType> workoutTypes = [];
bool selected = false;
bool executed = false;
late String exerciseDetail;
late String nameEnglish;
late String parentName;
late String parentNameEnglish;
late int sort;
late String internalName;
WorkoutMenuTree(
this.id,
this.parent,
this.name,
this.imageName,
this.color,
this.fontSize,
this.child,
this.exerciseTypeId,
this.exerciseType,
this.base,
this.is1RM,
this.isRunning,
this.nameEnglish,
this.parentName,
this.parentNameEnglish,
this.sort,
this.internalName);
Map<String, dynamic> toJson() {
return {
"id": id,
"parent": parent,
"name": name,
"imageName": imageName,
"color": color.toString(),
"fontSize": fontSize.toString(),
"child": child.toString(),
"exerciseTypeId": exerciseTypeId.toString(),
"base": base.toString(),
"is1RM": is1RM.toString(),
"isRunning": isRunning.toString(),
"sort": sort,
"internalName": internalName,
};
}
@override
String toString() {
return this.toJson().toString();
}
}