WT1.1.2h getProperty fix
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_tree_service.dart';
|
||||
import 'package:aitrainer_app/service/exercisetype_service.dart';
|
||||
import 'package:aitrainer_app/service/property_service.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
@@ -16,19 +17,13 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
|
||||
FieldBlocValidators.required,
|
||||
],
|
||||
);
|
||||
final passwordField = TextFieldBloc(
|
||||
validators: [
|
||||
FieldBlocValidators.required,
|
||||
]
|
||||
);
|
||||
|
||||
final passwordField = TextFieldBloc(validators: [
|
||||
FieldBlocValidators.required,
|
||||
]);
|
||||
|
||||
LoginFormBloc({this.userRepository, this.accountBloc}) {
|
||||
addFieldBlocs(fieldBlocs: [
|
||||
emailField,
|
||||
passwordField
|
||||
]);
|
||||
|
||||
addFieldBlocs(fieldBlocs: [emailField, passwordField]);
|
||||
|
||||
emailField.onValueChanges(onData: (previous, current) async* {
|
||||
userRepository.setEmail(current.value);
|
||||
});
|
||||
@@ -36,26 +31,26 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
|
||||
passwordField.onValueChanges(onData: (previous, current) async* {
|
||||
userRepository.setPassword(current.value);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
try {
|
||||
emitLoading(progress: 30);
|
||||
if ( ! validateEmail(userRepository)) {
|
||||
if (!validateEmail(userRepository)) {
|
||||
emailField.addFieldError(EMAIL_ERROR, isPermanent: true);
|
||||
|
||||
emitFailure(failureResponse: EMAIL_ERROR);
|
||||
} else if ( ! validatePassword(userRepository)) {
|
||||
passwordField.addFieldError( PASSWORD_ERROR, isPermanent: true);
|
||||
} else if (!validatePassword(userRepository)) {
|
||||
passwordField.addFieldError(PASSWORD_ERROR, isPermanent: true);
|
||||
emitFailure(failureResponse: PASSWORD_ERROR);
|
||||
} else {
|
||||
// Emit either Loaded or Error
|
||||
await PropertyApi().getProperties();
|
||||
await userRepository.getUser();
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
if ( Cache().userLoggedIn != null && Cache().userLoggedIn.customerId > 0) {
|
||||
if (Cache().userLoggedIn != null && Cache().userLoggedIn.customerId > 0) {
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
await exerciseRepository.getExercisesByCustomer(Cache().userLoggedIn.customerId);
|
||||
}
|
||||
@@ -64,7 +59,6 @@ class LoginFormBloc extends FormBloc<String, String> with Common {
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
emitFailure(failureResponse: ex.toString());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
-51
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/push_notifications.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/util/session.dart';
|
||||
@@ -113,53 +114,46 @@ Future<Null> main() async {
|
||||
// - https://www.dartlang.org/articles/libraries/zones
|
||||
runZonedGuarded<Future<Null>>(() async {
|
||||
final WorkoutTreeRepository menuTreeRepository = WorkoutTreeRepository();
|
||||
runApp(
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<SessionBloc>(
|
||||
create: (BuildContext context) => SessionBloc(session: Session()),
|
||||
),
|
||||
BlocProvider<MenuBloc>(
|
||||
create: (BuildContext context) => MenuBloc( menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<SettingsBloc>(
|
||||
create: (BuildContext context) => SettingsBloc(),
|
||||
),
|
||||
BlocProvider<AccountBloc>(
|
||||
create: (BuildContext context) => AccountBloc(customerRepository: CustomerRepository()),
|
||||
),
|
||||
BlocProvider<ExercisePlanBloc>(
|
||||
create: (BuildContext context) => ExercisePlanBloc(menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<ExerciseExecutePlanBloc>(
|
||||
create: (BuildContext context) => ExerciseExecutePlanBloc(
|
||||
menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<DevelopmentByMuscleBloc>(
|
||||
create: (BuildContext context) => DevelopmentByMuscleBloc(
|
||||
workoutTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<BodyDevelopmentBloc>(
|
||||
create: (BuildContext context) => BodyDevelopmentBloc(
|
||||
workoutTreeRepository: menuTreeRepository),
|
||||
),
|
||||
],
|
||||
|
||||
child: AitrainerApp(),
|
||||
)
|
||||
);
|
||||
runApp(MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<SessionBloc>(
|
||||
create: (BuildContext context) => SessionBloc(session: Session()),
|
||||
),
|
||||
BlocProvider<MenuBloc>(
|
||||
create: (BuildContext context) => MenuBloc(menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<SettingsBloc>(
|
||||
create: (BuildContext context) => SettingsBloc(),
|
||||
),
|
||||
BlocProvider<AccountBloc>(
|
||||
create: (BuildContext context) => AccountBloc(customerRepository: CustomerRepository()),
|
||||
),
|
||||
BlocProvider<ExercisePlanBloc>(
|
||||
create: (BuildContext context) => ExercisePlanBloc(menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<ExerciseExecutePlanBloc>(
|
||||
create: (BuildContext context) => ExerciseExecutePlanBloc(menuTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<DevelopmentByMuscleBloc>(
|
||||
create: (BuildContext context) => DevelopmentByMuscleBloc(workoutTreeRepository: menuTreeRepository),
|
||||
),
|
||||
BlocProvider<BodyDevelopmentBloc>(
|
||||
create: (BuildContext context) => BodyDevelopmentBloc(workoutTreeRepository: menuTreeRepository),
|
||||
),
|
||||
],
|
||||
child: AitrainerApp(),
|
||||
));
|
||||
}, (error, stackTrace) async {
|
||||
await _reportError(error, stackTrace);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class AitrainerApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
//final FirebaseAnalytics analytics = FirebaseAnalytics();
|
||||
PushNotificationsManager().init();
|
||||
return MaterialApp(
|
||||
localizationsDelegates: [
|
||||
// ... app-specific localization delegate[s] here
|
||||
@@ -178,12 +172,11 @@ class AitrainerApp extends StatelessWidget {
|
||||
// but you should check whether the localization is supported by your app
|
||||
Locale realSupportedLocale = Locale('en', "US");
|
||||
supportedLocales.forEach((supportedLocale) {
|
||||
if ( locale != null && supportedLocale != null &&
|
||||
supportedLocale.countryCode == locale.countryCode ) {
|
||||
if (locale != null && supportedLocale != null && supportedLocale.countryCode == locale.countryCode) {
|
||||
realSupportedLocale = supportedLocale;
|
||||
}
|
||||
});
|
||||
if ( locale != null && realSupportedLocale.countryCode != locale.countryCode ) {
|
||||
if (locale != null && realSupportedLocale.countryCode != locale.countryCode) {
|
||||
//print ("Locale " + locale.countryCode + " not supported on this device :(");
|
||||
}
|
||||
return realSupportedLocale;
|
||||
@@ -219,21 +212,16 @@ class AitrainerApp extends StatelessWidget {
|
||||
initialRoute: 'home',
|
||||
title: 'WorkoutTest',
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.light,
|
||||
//primarySwatch: Colors.transparent,
|
||||
//fontFamily: 'Arial',
|
||||
textTheme: TextTheme(
|
||||
bodyText1: GoogleFonts.openSans(textStyle: TextStyle(fontSize: 14.0)),
|
||||
)
|
||||
),
|
||||
brightness: Brightness.light,
|
||||
//primarySwatch: Colors.transparent,
|
||||
//fontFamily: 'Arial',
|
||||
textTheme: TextTheme(
|
||||
bodyText1: GoogleFonts.openSans(textStyle: TextStyle(fontSize: 14.0)),
|
||||
)),
|
||||
navigatorObservers: [
|
||||
//FirebaseAnalyticsObserver(analytics: analytics),
|
||||
],
|
||||
home: AitrainerHome(),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
class PushNotificationsManager {
|
||||
|
||||
PushNotificationsManager._();
|
||||
|
||||
factory PushNotificationsManager() => _instance;
|
||||
@@ -25,5 +24,3 @@ class PushNotificationsManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,7 @@ class Antagonist {
|
||||
static String biceps = "Biceps";
|
||||
static int bicepsNr = 2;
|
||||
static String triceps = "Triceps";
|
||||
static int tricepsNr =3;
|
||||
static int tricepsNr = 3;
|
||||
static String back = "Back";
|
||||
static int backNr = 4;
|
||||
static String shoulder = "Shoulders";
|
||||
@@ -44,30 +44,29 @@ class WorkoutTreeRepository {
|
||||
Antagonist.calf: Antagonist.calfNr
|
||||
};
|
||||
|
||||
|
||||
Future<void> createTree() async {
|
||||
|
||||
isEnglish = AppLanguage().appLocal == Locale('en');
|
||||
print("** Start creating tree on lang: " + AppLanguage().appLocal.languageCode);
|
||||
|
||||
List<ExerciseTree> exerciseTree = Cache().getExerciseTree();
|
||||
if ( exerciseTree == null || exerciseTree.length == 0) {
|
||||
if (exerciseTree == null || exerciseTree.length == 0) {
|
||||
await ExerciseTreeApi().getExerciseTree();
|
||||
}
|
||||
|
||||
exerciseTree.forEach( (treeItem) async {
|
||||
exerciseTree.forEach((treeItem) async {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
bool is1RM = treeItem.name == 'One Rep Max' ? true : false;
|
||||
if ( is1RM == false && treeItem.parentId != 0) {
|
||||
if (is1RM == false && treeItem.parentId != 0) {
|
||||
is1RM = isParent1RM(treeItem.parentId);
|
||||
}
|
||||
this.tree[treeItem.name] = WorkoutMenuTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
treeName,
|
||||
assetImage, Colors.white,
|
||||
24,
|
||||
assetImage,
|
||||
Colors.white,
|
||||
20,
|
||||
false,
|
||||
0,
|
||||
null,
|
||||
@@ -78,30 +77,17 @@ class WorkoutTreeRepository {
|
||||
});
|
||||
|
||||
List<ExerciseType> exerciseTypes = Cache().getExerciseTypes();
|
||||
if ( exerciseTypes == null || exerciseTypes.length == 0) {
|
||||
if (exerciseTypes == null || exerciseTypes.length == 0) {
|
||||
await ExerciseTypeApi().getExerciseTypes();
|
||||
}
|
||||
|
||||
exerciseTypes.forEach( (exerciseType) {
|
||||
String exerciseTypeName = isEnglish ?
|
||||
exerciseType.name : exerciseType.nameTranslation;
|
||||
exerciseTypes.forEach((exerciseType) {
|
||||
String exerciseTypeName = isEnglish ? exerciseType.name : exerciseType.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
bool is1RM = this.isParent1RM(exerciseType.treeId);
|
||||
exerciseType.is1RM = is1RM;
|
||||
this.tree[exerciseType.name] = WorkoutMenuTree(
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType.treeId,
|
||||
exerciseTypeName,
|
||||
assetImage,
|
||||
Colors.white,
|
||||
16,
|
||||
true,
|
||||
exerciseType.exerciseTypeId,
|
||||
exerciseType,
|
||||
exerciseType.base,
|
||||
is1RM,
|
||||
exerciseType.name
|
||||
);
|
||||
this.tree[exerciseType.name] = WorkoutMenuTree(exerciseType.exerciseTypeId, exerciseType.treeId, exerciseTypeName, assetImage,
|
||||
Colors.white, 16, true, exerciseType.exerciseTypeId, exerciseType, exerciseType.base, is1RM, exerciseType.name);
|
||||
});
|
||||
|
||||
Cache().setWorkoutMenuTree(tree);
|
||||
@@ -114,11 +100,10 @@ class WorkoutTreeRepository {
|
||||
|
||||
this.tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if ( treeItem.id == treeId ) {
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItem1RM = treeItem.is1RM;
|
||||
//print (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return isTreeItem1RM;
|
||||
@@ -128,7 +113,7 @@ class WorkoutTreeRepository {
|
||||
LinkedHashMap branch = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( parent == workoutTree.parent) {
|
||||
if (parent == workoutTree.parent) {
|
||||
branch[key] = value;
|
||||
}
|
||||
});
|
||||
@@ -139,7 +124,7 @@ class WorkoutTreeRepository {
|
||||
List branch = List<WorkoutMenuTree>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( parent == workoutTree.parent) {
|
||||
if (parent == workoutTree.parent) {
|
||||
branch.add(workoutTree);
|
||||
}
|
||||
});
|
||||
@@ -150,7 +135,7 @@ class WorkoutTreeRepository {
|
||||
WorkoutMenuTree parentItem;
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( parent == workoutTree.id) {
|
||||
if (parent == workoutTree.id) {
|
||||
parentItem = workoutTree;
|
||||
}
|
||||
});
|
||||
@@ -161,7 +146,7 @@ class WorkoutTreeRepository {
|
||||
sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree workoutTree = value as WorkoutMenuTree;
|
||||
if ( workoutTree.nameEnglish != 'One Rep Max' && workoutTree.is1RM && workoutTree.exerciseTypeId == 0) {
|
||||
if (workoutTree.nameEnglish != 'One Rep Max' && workoutTree.is1RM && workoutTree.exerciseTypeId == 0) {
|
||||
String treeName = _antagonist[workoutTree.nameEnglish].toString() + ". " + workoutTree.name;
|
||||
sortedTree[treeName] = this.getBranchList(workoutTree.id);
|
||||
}
|
||||
@@ -174,11 +159,10 @@ class WorkoutTreeRepository {
|
||||
int missingId = 0;
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree item = value as WorkoutMenuTree;
|
||||
if ( item.name == name || name == item.nameEnglish ) {
|
||||
if (item.name == name || name == item.nameEnglish) {
|
||||
missingId = item.id;
|
||||
}
|
||||
});
|
||||
return missingId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,12 @@ class CustomerApi {
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
if (customer.firebaseUid == null) {
|
||||
/* if (customer.firebaseUid == null) {
|
||||
await this.updateFirebaseUid(customer.customerId, Cache().firebaseUid);
|
||||
}
|
||||
} */
|
||||
Cache().userLoggedIn = customer;
|
||||
final List properties = await this.getActualProperties(customer.customerId);
|
||||
this._initProperties(properties);
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
}
|
||||
@@ -164,6 +166,9 @@ class CustomerApi {
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<CustomerProperty> properties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
|
||||
properties.forEach((element) {
|
||||
print("Property " + element.toString());
|
||||
});
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ class Session {
|
||||
prefs.setString(Cache.authTokenKey, responseJson['token']);
|
||||
Cache().authToken = responseJson['token'];
|
||||
Cache().firebaseUid = prefs.get(Cache.firebaseUidKey);
|
||||
await PropertyApi().getProperties();
|
||||
if (prefs.get(Cache.customerIdKey) == null) {
|
||||
print("************** Registration");
|
||||
// registration
|
||||
@@ -97,7 +98,6 @@ class Session {
|
||||
} else {
|
||||
// get API customer
|
||||
customerId = prefs.getInt(Cache.customerIdKey);
|
||||
await PropertyApi().getProperties();
|
||||
await CustomerApi().getCustomer(customerId);
|
||||
Cache().startPage = "home";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar_min.dart';
|
||||
@@ -66,7 +67,7 @@ class AccountPage extends StatelessWidget with Trans {
|
||||
textColor: Colors.grey,
|
||||
color: Colors.white,
|
||||
onPressed: () => {
|
||||
if (accountBloc.customerRepository.customer != null)
|
||||
if (accountBloc.customerRepository.customer != null && Cache().userLoggedIn != null)
|
||||
{
|
||||
Navigator.of(context).pushNamed('customerModifyPage'),
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
),
|
||||
Divider(),
|
||||
ToggleSwitch(
|
||||
minWidth: 50.0,
|
||||
minWidth: 80.0,
|
||||
minHeight: 50.0,
|
||||
fontSize: 14.0,
|
||||
initialLabelIndex: customerBloc.customerRepository.customer.sex == "m" ? 0 : 1,
|
||||
|
||||
Reference in New Issue
Block a user