wt1.1a flutter_bloc
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
|
||||
class GenderItem {
|
||||
GenderItem(this.dbValue,this.name);
|
||||
final String dbValue;
|
||||
String name;
|
||||
}
|
||||
|
||||
class CustomerRepository {
|
||||
Customer customer;
|
||||
//List<CustomerRepository> customerList = List<CustomerRepository>();
|
||||
bool visibleDetails = false;
|
||||
List<GenderItem> genders;
|
||||
|
||||
CustomerRepository({this.customer}) {
|
||||
customer = Customer();
|
||||
genders = [
|
||||
GenderItem("m", "Man"),
|
||||
GenderItem("w", "Woman"),
|
||||
];
|
||||
}
|
||||
|
||||
String getGenderByName(String name) {
|
||||
String dbValue;
|
||||
genders.forEach((element) {
|
||||
if (element.name == name) {
|
||||
dbValue = element.dbValue;
|
||||
}
|
||||
});
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
String getGenderByDBValue(String dbValue) {
|
||||
String name;
|
||||
genders.forEach((element) {
|
||||
if (element.dbValue == dbValue) {
|
||||
name = element.name;
|
||||
}
|
||||
});
|
||||
return name;
|
||||
}
|
||||
|
||||
String get name {
|
||||
return this.customer.name != null ? this.customer.name : "";
|
||||
}
|
||||
|
||||
String get firstName {
|
||||
return this.customer.firstname != null ? this.customer.firstname : "";
|
||||
}
|
||||
|
||||
String get sex {
|
||||
return this.customer.sex == "m" ? "Man" : "Woman";
|
||||
}
|
||||
|
||||
int get birthYear {
|
||||
return this.customer.birthYear;
|
||||
}
|
||||
|
||||
String get goal {
|
||||
return this.customer.goal;
|
||||
}
|
||||
|
||||
String get fitnessLevel {
|
||||
return this.customer.fitnessLevel;
|
||||
}
|
||||
|
||||
String get bodyType {
|
||||
return this.customer.bodyType;
|
||||
}
|
||||
|
||||
setName(String name) {
|
||||
this.customer.name = name;
|
||||
}
|
||||
setFirstName(String firstName) {
|
||||
this.customer.firstname = firstName;
|
||||
}
|
||||
|
||||
setPassword( String password ) {
|
||||
this.customer.password = password;
|
||||
}
|
||||
|
||||
setEmail(String email) {
|
||||
this.customer.email = email;
|
||||
}
|
||||
|
||||
|
||||
setSex(String sex) {
|
||||
this.customer.sex = sex;
|
||||
}
|
||||
|
||||
setWeight( int weight) {
|
||||
this.customer.weight = weight;
|
||||
}
|
||||
|
||||
setBirthYear( int birthYear ) {
|
||||
this.customer.birthYear = birthYear;
|
||||
}
|
||||
|
||||
setFitnessLevel( String level ) {
|
||||
this.customer.fitnessLevel = level;
|
||||
}
|
||||
|
||||
setGoal( String goal ) {
|
||||
this.customer.goal = goal;
|
||||
}
|
||||
|
||||
setBodyType(String bodyType) {
|
||||
this.customer.bodyType = bodyType;
|
||||
}
|
||||
|
||||
createNew() {
|
||||
this.customer = Customer();
|
||||
}
|
||||
|
||||
Customer getCustomer() {
|
||||
return this.customer;
|
||||
}
|
||||
|
||||
void setCustomer ( Customer customer ) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
Future<void> addCustomer() async {
|
||||
final Customer modelCustomer = customer;
|
||||
await CustomerApi().addCustomer(modelCustomer);
|
||||
}
|
||||
|
||||
Future<void> saveCustomer() async {
|
||||
final Customer modelCustomer = customer;
|
||||
await CustomerApi().saveCustomer(modelCustomer);
|
||||
}
|
||||
|
||||
/* Future<List<CustomerRepository>> getCustomers() async {
|
||||
final results = await CustomerApi().getRealCustomers("");
|
||||
this.customerList = results.map((item) => CustomerRepository(customer: item)).toList();
|
||||
return this.customerList;
|
||||
}
|
||||
|
||||
addNewCustomerToList(CustomerRepository customerViewModel) {
|
||||
customerList.add(customerViewModel);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
|
||||
class ExerciseRepository {
|
||||
Exercise exercise;
|
||||
Customer customer;
|
||||
ExerciseType exerciseType;
|
||||
|
||||
double rmWendler = 0;
|
||||
double rmMcglothlin = 0;
|
||||
double rmLombardi = 0;
|
||||
double rmMayhew = 0;
|
||||
double rmOconner = 0;
|
||||
double rmWathen = 0;
|
||||
|
||||
createNew() {
|
||||
this.exercise = Exercise();
|
||||
exercise.dateAdd = DateTime.now();
|
||||
}
|
||||
|
||||
setQuantity(double quantity) {
|
||||
if ( this.exercise == null ) {
|
||||
this.createNew();
|
||||
}
|
||||
this.exercise.quantity = quantity;
|
||||
}
|
||||
|
||||
setUnitQuantity(double unitQuantity) {
|
||||
if ( this.exercise == null ) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.unitQuantity = unitQuantity;
|
||||
}
|
||||
|
||||
setUnit( String unit) {
|
||||
if ( this.exercise == null ) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.unit = unit;
|
||||
}
|
||||
|
||||
setDatetimeExercise(DateTime datetimeExercise) {
|
||||
if ( this.exercise == null ) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.dateAdd = datetimeExercise;
|
||||
}
|
||||
|
||||
double get unitQuantity {
|
||||
return this.exercise.unitQuantity;
|
||||
}
|
||||
|
||||
double get quantity {
|
||||
return this.exercise.quantity;
|
||||
}
|
||||
|
||||
Exercise getExercise() {
|
||||
return this.exercise;
|
||||
}
|
||||
|
||||
Future<void> addExercise() async {
|
||||
final Exercise modelExercise = this.exercise;
|
||||
modelExercise.customerId = this.customer.customerId;
|
||||
modelExercise.exerciseTypeId = this.exerciseType.exerciseTypeId;
|
||||
await ExerciseApi().addExercise(modelExercise);
|
||||
}
|
||||
|
||||
|
||||
setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
setExerciseType( ExerciseType exerciseType) {
|
||||
this.exerciseType = exerciseType;
|
||||
}
|
||||
|
||||
/*
|
||||
Future<List<ExerciseRepository>> getExercisesByCustomer( int customerId ) async {
|
||||
final results = await ExerciseApi().getExercisesByCustomer(customerId);
|
||||
this.exerciseList = results.map((item) => ExerciseRepository(exercise: item)).toList();
|
||||
return this.exerciseList;
|
||||
} */
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'dart:collection';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/auth.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MenuTreeRepository {
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutTree>();
|
||||
|
||||
Future<void> createTree() async {
|
||||
|
||||
final AppLanguage appLanguage = AppLanguage();
|
||||
bool isEnglish = appLanguage.appLocal == Locale('en');
|
||||
|
||||
List<ExerciseTree> exerciseTree = Auth().getExerciseTree();
|
||||
if ( exerciseTree == null || exerciseTree.length == 0) {
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
}
|
||||
|
||||
exerciseTree.forEach( (treeItem) async {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
this.tree[treeItem.name] = WorkoutTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
treeName,
|
||||
assetImage, Colors.white,
|
||||
32,
|
||||
false,
|
||||
0,
|
||||
null
|
||||
);
|
||||
});
|
||||
|
||||
List<ExerciseType> exerciseTypes = Auth().getExerciseTypes();
|
||||
if ( exerciseTypes == null || exerciseTypes.length == 0) {
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
}
|
||||
|
||||
exerciseTypes.forEach( (exerciseType) {
|
||||
String exerciseTypeName = isEnglish ?
|
||||
exerciseType.name : exerciseType.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
this.tree[exerciseType.name] = WorkoutTree(
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType.treeId,
|
||||
exerciseTypeName,
|
||||
assetImage,
|
||||
Colors.white,
|
||||
16,
|
||||
true,
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
LinkedHashMap getBranch(int parent) {
|
||||
LinkedHashMap branch = LinkedHashMap<String, WorkoutTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutTree workoutTree = value as WorkoutTree;
|
||||
if ( parent == workoutTree.parent) {
|
||||
branch[key] = value;
|
||||
}
|
||||
});
|
||||
return branch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:aitrainer_app/model/user.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
|
||||
class UserRepository {
|
||||
User user;
|
||||
|
||||
UserRepository() {
|
||||
this.createNewUser();
|
||||
}
|
||||
|
||||
setEmail(String email) {
|
||||
this.user.email = email;
|
||||
}
|
||||
|
||||
setPassword(String password) {
|
||||
this.user.password = password;
|
||||
}
|
||||
|
||||
createNewUser() {
|
||||
this.user = User();
|
||||
}
|
||||
|
||||
Future<void> addUser() async {
|
||||
final User modelUser = this.user;
|
||||
await CustomerApi().addUser(modelUser);
|
||||
}
|
||||
|
||||
Future<void> getUser() async {
|
||||
final User modelUser = this.user;
|
||||
await CustomerApi().getUser(modelUser);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user