WT1.1.6+3 bodyType animation, bug fixes

This commit is contained in:
bossanyit
2021-02-20 16:48:01 +01:00
parent 3c5360f224
commit cf348cebb0
293 changed files with 2966 additions and 1673 deletions
+40 -4
View File
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
@@ -16,12 +17,47 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
bool loggedIn = false;
int traineeId = 0;
AccountBloc({this.customerRepository}) : super(AccountInitial()) {
if ( Cache().userLoggedIn != null ) {
if (Cache().userLoggedIn != null) {
customerRepository.customer = Cache().userLoggedIn;
loggedIn = true;
}
}
String getAccurateBodyType() {
String bodyType = ("Set your body type");
int _ecto = 0;
int _mezo = 0;
int _endo = 0;
_ecto = customerRepository.getCustomerPropertyValue(PropertyEnum.Ectomorph.toStr()).toInt();
_mezo = customerRepository.getCustomerPropertyValue(PropertyEnum.Mesomorph.toStr()).toInt();
_endo = customerRepository.getCustomerPropertyValue(PropertyEnum.Endomorph.toStr()).toInt();
if (_ecto == 0 && _mezo == 0 && _endo == 0) {
return bodyType;
}
int bodyTypeValue;
if (_ecto < 50) {
bodyTypeValue = (50 + ((50 / (_mezo + _endo)) * _endo)).toInt();
} else if (_endo < 50) {
bodyTypeValue = (0 + ((50 / (_mezo + _ecto)) * _mezo)).toInt();
} else {
// random answers probably
bodyTypeValue = (0 + ((100 / (_endo + _ecto))) * _endo).toInt();
}
print("BodyType value " + bodyTypeValue.toString());
if (bodyTypeValue < 20) {
bodyType = ("Ectomorph");
} else if (bodyTypeValue >= 25 && bodyTypeValue < 40) {
bodyType = ("Ecto") + "-" + ("Mesomorph");
} else if (bodyTypeValue >= 40 && bodyTypeValue < 60) {
bodyType = ("Mesomorph");
} else if (bodyTypeValue >= 60 && bodyTypeValue < 80) {
bodyType = ("Meso") + "-" + ("Endomorph");
} else {
bodyType = ("Endomorph");
}
return bodyType;
}
@override
Stream<AccountState> mapEventToState(
AccountEvent event,
@@ -42,11 +78,11 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
customerRepository.emptyTrainees();
loggedIn = false;
yield AccountLoggedOut();
} else if ( event is AccountGetTrainees) {
} else if (event is AccountGetTrainees) {
yield AccountLoading();
await customerRepository.getTrainees();
yield AccountReady();
} else if ( event is AccountSelectTrainee ) {
} else if (event is AccountSelectTrainee) {
yield AccountLoading();
customerRepository.setTrainee(event.traineeId);
Cache().setTrainee(customerRepository.getTraineeById(event.traineeId));
@@ -55,7 +91,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
this.traineeId = event.traineeId;
yield AccountReady();
}
} on Exception catch(e) {
} on Exception catch (e) {
yield AccountError(message: e.toString());
}
}
+239
View File
@@ -0,0 +1,239 @@
import 'dart:async';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer_property.dart';
import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/service/customer_service.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
part 'bodytype_event.dart';
part 'bodytype_state.dart';
class BodytypeBloc extends Bloc<BodytypeEvent, BodytypeState> {
static const int numberQuestions = 22;
final CustomerRepository repository;
final List<String> questions = List();
final List<int> answers = List();
final weights = List.generate(numberQuestions, (i) => List(3), growable: false);
BodytypeBloc({this.repository}) : super(BodytypeInitial()) {
questions.add("1. Basicly I am skinny and bonny");
questions.add("2. question");
questions.add("3. question");
questions.add("4. question");
questions.add("5. question");
questions.add("6. question");
questions.add("7. question");
questions.add("8. question");
questions.add("9. question");
questions.add("10. question");
questions.add("11. question");
questions.add("12. question");
questions.add("13. question");
questions.add("14. question");
questions.add("15. question");
questions.add("16. question");
questions.add("17. question");
questions.add("18. question");
questions.add("19. question");
questions.add("20. question");
questions.add("21. question");
questions.add("22. question");
for (int i = 0; i < numberQuestions; i++) {
answers.add(0);
}
weights[0] = [0, 3, 7];
weights[1] = [0, 3, 7];
weights[2] = [0, 3, 7];
weights[3] = [0, 3, 7];
weights[4] = [0, 3, 7];
weights[5] = [0, 3, 7];
weights[6] = [0, 3, 7];
weights[7] = [3, 7, 0];
weights[8] = [5, 7, 0];
weights[9] = [0, 7, 3];
weights[10] = [5, 5, 0];
weights[11] = [7, 5, 0];
weights[12] = [7, 5, 0];
weights[13] = [5, 5, 0];
weights[14] = [7, 3, 0];
weights[15] = [7, 3, 0];
weights[16] = [7, 3, 0];
weights[17] = [7, 3, 0];
weights[18] = [7, 0, 0];
weights[19] = [7, 0, 0];
weights[20] = [7, 3, 0];
weights[21] = [7, 3, 0];
final double value = repository.getCustomerPropertyValue(PropertyEnum.Ectomorph.toStr());
if (value != null) {
_ecto = value.toInt();
_mezo = repository.getCustomerPropertyValue(PropertyEnum.Mesomorph.toStr()).toInt();
_endo = repository.getCustomerPropertyValue(PropertyEnum.Endomorph.toStr()).toInt();
print("** Init ecto: " + _ecto.toString() + " mezo: " + _mezo.toString() + " endo: " + _endo.toString());
if (_ecto > 0 && _mezo > 0 && _endo > 0) {
calculateBodyType(init: true);
origBodyTypeValue = bodyTypeValue;
}
}
}
int value = 0;
int step = 1;
int bodyTypeValue = 0;
int origBodyTypeValue = 0;
int _ecto = 0;
int _mezo = 0;
int _endo = 0;
@override
Stream<BodytypeState> mapEventToState(
BodytypeEvent event,
) async* {
try {
if (event is BodytypeClick) {
yield BodytypeLoading();
this.value = event.value;
answers[step - 1] = value;
calculateBodyType();
await saveToDB();
if (step >= questions.length) {
yield BodytypeFinished();
return;
}
step++;
yield BodytypeReady();
} else if (event is BodytypeBack) {
yield BodytypeLoading();
if (step == 1) {
yield BodytypeReady();
return;
}
step--;
this.value = answers[step - 1];
yield BodytypeReady();
}
} on Exception catch (e) {
yield BodytypeError(error: e.toString());
}
}
bool showResults() {
return this.state == BodytypeFinished() || origBodyTypeValue > 0;
}
Future<void> saveToDB() async {
await savePropertyDB(PropertyEnum.Ectomorph.toStr(), _ecto.toDouble());
await savePropertyDB(PropertyEnum.Mesomorph.toStr(), _mezo.toDouble());
await savePropertyDB(PropertyEnum.Endomorph.toStr(), _endo.toDouble());
}
Future<void> savePropertyDB(String name, double value) async {
final now = DateTime.now();
Property property = repository.propertyRepository.getPropertyByName(name);
if (property != null) {
int propertyId = property.propertyId;
CustomerProperty customerProperty = repository.getCustomerProperty(name);
if (customerProperty == null || customerProperty.customerPropertyId == null) {
customerProperty =
CustomerProperty(customerId: Cache().userLoggedIn.customerId, propertyId: propertyId, propertyValue: value, dateAdd: now);
CustomerProperty newProperty = await CustomerApi().addProperty(customerProperty);
repository.setCustomerProperty(name, value, id: newProperty.customerPropertyId);
} else {
customerProperty.propertyValue = value;
customerProperty.dateAdd = now;
await CustomerApi().updateProperty(customerProperty);
repository.setCustomerProperty(name, value);
}
}
}
String getQuestion() {
return questions[step - 1];
}
int getValue() {
return answers[this.step - 1];
}
int getPrevValue() {
return step < 2 ? 0 : answers[this.step - 2];
}
int getBodyTypeValue() {
return bodyTypeValue;
}
void calculateBodyType({bool init = false}) {
if (!init) {
_endo = 0;
_mezo = 0;
_ecto = 0;
for (int index = 0; index < step; index++) {
_endo += getValueByWeight(weights[index][0], answers[index]);
_mezo += getValueByWeight(weights[index][1], answers[index]);
_ecto += getValueByWeight(weights[index][2], answers[index]);
}
print("ecto: " + _ecto.toString() + " mezo: " + _mezo.toString() + " endo: " + _endo.toString());
}
if (_ecto < 50) {
bodyTypeValue = (50 + ((50 / (_mezo + _endo)) * _endo)).toInt();
} else if (_endo < 50) {
bodyTypeValue = (0 + ((50 / (_mezo + _ecto)) * _mezo)).toInt();
} else {
// random answers probably
bodyTypeValue = (0 + ((100 / (_endo + _ecto))) * _endo).toInt();
}
origBodyTypeValue = 0;
print("bodyTypeValue: " + bodyTypeValue.toString());
}
int getValueByWeight(int weight, int answer) {
if (answer == 4) {
if (weight > 3 && weight < 7) {
return ((weight - (5 - answer) * 1.25)).round();
} else if (weight >= 7) {
return ((weight - (5 - answer) * 2)).round();
} else {
return (weight + (5 - answer) * 1.25).round();
}
} else if (answer == 3) {
if (weight > 3 && weight < 7) {
return ((weight - (5 - answer))).round();
} else if (weight >= 7) {
return ((weight - (5 - answer) * 2)).round();
} else {
return ((weight + (5 - answer) * 1.5)).round();
}
} else if (answer == 2) {
if (weight > 3 && weight < 7) {
return ((weight - (5 - answer))).round();
} else if (weight >= 7) {
return ((weight - (5 - answer) * 2)).round();
} else if (weight == 3) {
return ((weight + (5 - answer) * 0.25)).round();
} else {
return ((weight + (5 - answer) * 1.75)).round();
}
} else if (answer == 1) {
if (weight > 3 && weight < 7) {
return ((weight - (5 - answer))).round();
} else if (weight >= 7) {
return ((weight - (5 - answer) * 1.85)).round();
} else if (weight == 3) {
return weight;
} else {
return ((weight + (5 - answer) * 1.85)).round();
}
} else {
return weight;
}
}
}
+28
View File
@@ -0,0 +1,28 @@
part of 'bodytype_bloc.dart';
abstract class BodytypeEvent extends Equatable {
const BodytypeEvent();
@override
List<Object> get props => [];
}
class BodytypeLoad extends BodytypeEvent {
const BodytypeLoad();
}
class BodytypeSave extends BodytypeEvent {
const BodytypeSave();
}
class BodytypeClick extends BodytypeEvent {
final int value;
const BodytypeClick({this.value});
@override
List<Object> get props => [value];
}
class BodytypeBack extends BodytypeEvent {
const BodytypeBack();
}
+32
View File
@@ -0,0 +1,32 @@
part of 'bodytype_bloc.dart';
abstract class BodytypeState extends Equatable {
const BodytypeState();
@override
List<Object> get props => [];
}
class BodytypeInitial extends BodytypeState {
const BodytypeInitial();
}
class BodytypeLoading extends BodytypeState {
const BodytypeLoading();
}
class BodytypeReady extends BodytypeState {
const BodytypeReady();
}
class BodytypeFinished extends BodytypeState {
const BodytypeFinished();
}
class BodytypeError extends BodytypeState {
final String error;
const BodytypeError({this.error});
@override
List<Object> get props => [error];
}
-129
View File
@@ -1,129 +0,0 @@
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class CustomerChangeFormBloc extends FormBloc<String, String> {
final CustomerRepository customerRepository;
int weight = 60;
int birthYear = 1990;
final emailField = TextFieldBloc(
validators: [
FieldBlocValidators.required,
],
);
final firstNameField = TextFieldBloc(
validators: [
FieldBlocValidators.required,
],
);
final nameField = TextFieldBloc();
final passwordField = TextFieldBloc(
validators: [
//FieldBlocValidators.confirmPassword(passwordField),
],
);
final birthYearField = InputFieldBloc<int, Object>(initialValue: 1990);
final weightField = InputFieldBloc<int, Object>(initialValue: 60);
final genderField = InputFieldBloc<int, Object>(initialValue: 0);
final goalField = TextFieldBloc();
CustomerChangeFormBloc({this.customerRepository}) {
addFieldBlocs(fieldBlocs: [
emailField,
firstNameField,
nameField,
passwordField,
birthYearField,
weightField,
genderField,
goalField,
]);
emailField.updateInitialValue(customerRepository.customer.email);
firstNameField.updateInitialValue(customerRepository.customer.firstname);
nameField.updateInitialValue(customerRepository.customer.name);
birthYearField.updateInitialValue(customerRepository.customer.birthYear);
weightField.updateInitialValue(customerRepository.customer.getProperty("weight").toInt());
int initialGender = customerRepository.getGenderByDBValue(customerRepository.sex) == "m" ? 0 : 1;
genderField.updateInitialValue(initialGender);
firstNameField.onValueChanges(onData: (previous, current) async* {
customerRepository.setFirstName(current.value);
});
nameField.onValueChanges(onData: (previous, current) async* {
customerRepository.setName(current.value);
});
/*birthYearField.onValueChanges(onData: (previous, current) async* {
customerRepository.setBirthYear(current.valueToInt);
});
weightField.onValueChanges(onData: (previous, current) async* {
customerRepository.setWeight(current.valueToInt);
});
customerRepository.genders.forEach((element) {
genderField.addItem(element.name);
});*/
genderField.onValueChanges(onData: (previous, current) async* {
String dbValue = customerRepository.getGenderByName(current.value.toString());
customerRepository.setSex(dbValue);
});
}
int getGender() {
return customerRepository.customer.sex == "M" ? 0 : 1;
}
void switchGender(int index) {
String dbValue;
if (index == 0) {
dbValue = customerRepository.getGenderByName("Man");
} else if (index == 1) {
dbValue = customerRepository.getGenderByName("Woman");
}
customerRepository.setSex(dbValue);
genderField.add(UpdateFieldBlocValue(dbValue));
}
void changeWeight(int value) {
customerRepository.setWeight(value);
weight = value;
weightField.updateValue(value);
}
changeBirthYear(int value) {
customerRepository.setBirthYear(value);
birthYear = value;
birthYearField.updateValue(value);
}
@override
void onSubmitting() async {
try {
emitLoading(progress: 30);
// Emit either Loaded or Error
await customerRepository.saveCustomer();
emitSuccess(canSubmitAgain: true);
} on Exception catch (ex) {
emitFailure(failureResponse: ex.toString());
}
}
@override
Future<void> close() {
emailField.close();
firstNameField.close();
nameField.close();
passwordField.close();
birthYearField.close();
weightField.close();
genderField.close();
goalField.close();
return super.close();
}
}
@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_device.dart';
import 'package:aitrainer_app/repository/customer_exercise_device_repository.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
@@ -17,6 +19,7 @@ class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, Custo
if (repository.getDevices().isEmpty) {
repository.setDevices(Cache().getCustomerDevices());
}
Track().track(TrackingEvent.exercise_device);
}
@override
@@ -29,7 +32,6 @@ class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, Custo
yield CustomerExerciseDeviceReady();
} else if (event is CustomerExerciseDeviceAdd) {
yield CustomerExerciseDeviceLoading();
//await Future.delayed(const Duration(seconds: 2), () => "2");
await repository.addDevice(event.device);
Cache().initBadges();
yield CustomerExerciseDeviceReady();
@@ -9,7 +9,9 @@ import 'package:aitrainer_app/repository/workout_tree_repository.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/calculate.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/group_data.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
@@ -282,7 +284,9 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
double basePercent = 0;
@override
DevelopmentByMuscleBloc({this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
DevelopmentByMuscleBloc({this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial()) {
Track().track(TrackingEvent.my_muscle_development);
}
Future<void> getData() async {
workoutTreeRepository.sortedTree = null;
@@ -33,6 +33,7 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
exerciseRepository.setUnitQuantity(unitQuantity);
exerciseRepository.setQuantity(quantity);
print("init quantity: " + quantity.toString());
}
@override
@@ -40,6 +41,7 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
try {
if (event is ExerciseControlLoad) {
yield ExerciseControlLoading();
print("init quantity: " + quantity.toString());
step = 1;
yield ExerciseControlReady();
} else if (event is ExerciseControlQuantityChange) {
@@ -49,6 +51,18 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
quantity = event.quantity;
}
//yield ExerciseControlReady();
} else if (event is ExerciseControlUnitQuantityChange) {
yield ExerciseControlLoading();
if (event.step == step) {
this.unitQuantity = event.quantity;
exerciseRepository.setUnitQuantity(event.quantity);
unitQuantity = event.quantity;
quantity = calculateQuantityByUnitQuantity();
exerciseRepository.setQuantity(quantity);
origQuantity = quantity;
}
yield ExerciseControlReady();
} else if (event is ExerciseControlSubmit) {
yield ExerciseControlLoading();
if (event.step == step) {
@@ -57,7 +71,7 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
quantity = origQuantity;
if (exerciseRepository.exercise.quantity == null) {
exerciseRepository.setQuantity(12);
exerciseRepository.setQuantity(quantity);
}
exerciseRepository.end = DateTime.now();
await exerciseRepository.addExercise();
@@ -88,4 +102,19 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
return percent75 ? average * this.percentToCalculate : average;
}
double calculateQuantityByUnitQuantity() {
final double rmWendler = initialRM;
final double rmOconner = initialRM;
final double weight = exerciseRepository.exercise.unitQuantity;
final double repeatWendler = (rmWendler - weight) / 0.0333 / weight;
final double repeatOconner = (rmOconner / weight - 1) * 40;
print("Weight: " +
weight.toString() +
" repeatWendler: " +
repeatWendler.toStringAsFixed(0) +
" repeat Oconner: " +
repeatOconner.toStringAsFixed(0));
return repeatWendler;
}
}
@@ -18,6 +18,12 @@ class ExerciseControlQuantityChange extends ExerciseControlEvent {
const ExerciseControlQuantityChange({this.quantity, this.step});
}
class ExerciseControlUnitQuantityChange extends ExerciseControlEvent {
final double quantity;
final int step;
const ExerciseControlUnitQuantityChange({this.quantity, this.step});
}
class ExerciseControlSubmit extends ExerciseControlEvent {
final int step;
const ExerciseControlSubmit({this.step});
@@ -5,9 +5,10 @@ import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:meta/meta.dart';
part 'exercise_execute_plan_add_event.dart';
@@ -55,7 +56,7 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
try {
if (event is ExerciseExecutePlanAddLoad) {
yield ExerciseExecutePlanAddLoading();
Flurry.logEvent("ExecuteExercisePlanOpen");
Track().track(TrackingEvent.my_exercise_plan_execute_open);
yield ExerciseExecutePlanAddReady();
} else if (event is ExerciseExecutePlanAddChangeQuantity) {
yield ExerciseExecutePlanAddLoading();
@@ -73,7 +74,7 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
workoutTree.executed = true;
await exerciseRepository.addExercise();
Flurry.logEvent("ExecuteExercisePlanSave");
Track().track(TrackingEvent.my_exercise_plan_execute_save);
step++;
scrollOffset = step * 200.0;
planBloc.add(ExerciseByPlanLoad());
+5 -4
View File
@@ -1,9 +1,10 @@
import 'dart:async';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:meta/meta.dart';
part 'exercise_log_event.dart';
@@ -20,17 +21,17 @@ class ExerciseLogBloc extends Bloc<ExerciseLogEvent, ExerciseLogState> {
try {
if (event is ExerciseLogLoad) {
yield ExerciseLogLoading();
Flurry.logEvent("exerciseLog");
Track().track(TrackingEvent.exercise_log_open);
yield ExerciseLogReady();
} else if (event is ExerciseLogDelete) {
yield ExerciseLogLoading();
exerciseRepository.exerciseList.remove(event.exercise);
await exerciseRepository.deleteExercise(event.exercise);
Flurry.logEvent("exerciseDelete");
Track().track(TrackingEvent.exercise_log_delete);
yield ExerciseLogReady();
} else if (event is ExerciseResult) {
yield ExerciseLogLoading();
Flurry.logEvent("exerciseResult");
Track().track(TrackingEvent.exercise_log_result);
yield ExerciseLogReady();
}
} on Exception catch (e) {
+4 -4
View File
@@ -8,9 +8,10 @@ import 'package:aitrainer_app/model/fitness_state.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
@@ -352,7 +353,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
changedWeight = false;
this.changedSizes = false;
Cache().initBadges();
Flurry.logEvent("Sizes");
Track().track(TrackingEvent.sizes);
yield ExerciseNewReady();
} else if (event is ExerciseNewSizeChange) {
yield ExerciseNewLoading();
@@ -366,8 +367,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
await exerciseRepository.addExercise();
menuBloc.add(MenuTreeDown(parent: 0));
Cache().initBadges();
Flurry.logEvent("newExercise");
Flurry.logEvent("newExercise " + exerciseRepository.exerciseType.name);
Track().track(TrackingEvent.exercise_new, eventValue: exerciseRepository.exerciseType.name);
yield ExerciseNewReady();
} else if (event is ExerciseNewBMIAnimate) {
yield ExerciseNewLoading();
@@ -4,9 +4,10 @@ import 'package:aitrainer_app/model/model_change.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:meta/meta.dart';
part 'exercise_plan_event.dart';
@@ -48,7 +49,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
try {
if (event is ExercisePlanLoad) {
yield ExercisePlanLoading();
Flurry.logEvent("exercisePlan");
Track().track(TrackingEvent.my_custom_exercise_plan);
await this.getData();
yield ExercisePlanReady();
}
@@ -98,7 +99,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
exercisePlanRepository.saveExercisePlan();
Flurry.logEvent("SaveExercisePlan");
Track().track(TrackingEvent.my_custom_exercise_plan_save);
}
yield ExercisePlanReady();
+13 -17
View File
@@ -5,13 +5,13 @@ import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/customer_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/exercise_type_service.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter/material.dart';
part 'login_event.dart';
@@ -51,7 +51,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
yield LoginLoading();
await userRepository.getUser();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Flurry.logEvent("Login");
Track().track(TrackingEvent.login, eventValue: "email");
Cache().setLoginType(LoginType.email);
yield LoginSuccess();
} else if (event is LoginFB) {
@@ -59,24 +59,21 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
Cache().setLoginType(LoginType.fb);
await userRepository.getUserByFB();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Flurry.logEvent("Login");
Flurry.logEvent("LoginFB");
Track().track(TrackingEvent.login, eventValue: "FB");
yield LoginSuccess();
} else if (event is LoginGoogle) {
yield LoginLoading();
Cache().setLoginType(LoginType.google);
await userRepository.getUserByGoogle();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Flurry.logEvent("Login");
Flurry.logEvent("LoginGoogle");
Track().track(TrackingEvent.login, eventValue: "Google");
yield LoginSuccess();
} else if (event is LoginApple) {
yield LoginLoading();
Cache().setLoginType(LoginType.apple);
await userRepository.getUserByApple();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
Flurry.logEvent("Login");
Flurry.logEvent("LoginApple");
Track().track(TrackingEvent.login, eventValue: "Apple");
yield LoginSuccess();
} else if (event is RegistrationSubmit) {
yield LoginLoading();
@@ -87,7 +84,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
await userRepository.addUser();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
await saveCustomer();
Flurry.logEvent("Registration");
Track().track(TrackingEvent.registration, eventValue: "email");
Cache().setLoginType(LoginType.email);
yield LoginSuccess();
} else if (event is RegistrationFB) {
@@ -100,8 +97,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
await userRepository.addUserFB();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
await saveCustomer();
Flurry.logEvent("RegistrationFB");
Flurry.logEvent("Registration");
Track().track(TrackingEvent.registration, eventValue: "FB");
yield LoginSuccess();
} else if (event is RegistrationGoogle) {
yield LoginLoading();
@@ -113,8 +109,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
await userRepository.addUserGoogle();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
await saveCustomer();
Flurry.logEvent("RegistrationGoogle");
Flurry.logEvent("Registration");
Track().track(TrackingEvent.registration, eventValue: "Google");
yield LoginSuccess();
} else if (event is RegistrationApple) {
yield LoginLoading();
@@ -124,10 +119,11 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
}
Cache().setLoginType(LoginType.apple);
await userRepository.addUserApple();
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
await saveCustomer();
Flurry.logEvent("RegistrationApple");
Flurry.logEvent("Registration");
Track().track(TrackingEvent.registration);
Track().track(TrackingEvent.registration, eventValue: "Apple");
yield LoginSuccess();
} else if (event is DataProtectionClicked) {
yield LoginLoading();
+6 -5
View File
@@ -7,9 +7,11 @@ import 'package:aitrainer_app/model/product.dart';
import 'package:aitrainer_app/model/product_test.dart';
import 'package:aitrainer_app/model/purchase.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/service/purchase.dart';
import 'package:aitrainer_app/service/purchase_service.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/purchases.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
@@ -32,8 +34,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
if (event is SalesLoad) {
yield SalesLoading();
log("Load Sales");
Common.sendMessage("Salespage Load");
Flurry.logEvent("SalesPageOpen");
Track().track(TrackingEvent.sales_page);
//await PlatformPurchaseApi().initPurchasePlatform();
await RevenueCatPurchases().getOfferings();
this.getProductSet();
@@ -45,7 +46,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
yield SalesLoading();
final int productId = event.productId;
log("Requesting purchase for: " + productId.toString());
Flurry.logEvent("PurchaseRequest");
Track().track(TrackingEvent.purchase_request);
final Product selectedProduct = this.getSelectedProduct(productId);
log("SelectedProduct for purchase " + selectedProduct.toString());
await RevenueCatPurchases().makePurchase(selectedProduct);
@@ -55,7 +56,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
purchase.purchaseSum = 0;
purchase.currency = "EUR";
await PurchaseApi().savePurchase(purchase);
Flurry.logEvent("PurchaseSuccessful");
Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString());
Common.sendMessage("Purchase: " + purchase.toJson().toString());
}
yield SalesSuccessful();
-4
View File
@@ -2,13 +2,10 @@ import 'dart:async';
import 'package:aitrainer_app/bloc/settings/settings_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/service/exercise_tree_service.dart';
import 'package:aitrainer_app/service/exercisetype_service.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/session.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flurry/flurry.dart';
part 'session_event.dart';
part 'session_state.dart';
@@ -32,7 +29,6 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
String lang = AppLanguage().appLocal.languageCode;
log("Change lang to $lang");
settingsBloc.add(SettingsChangeLanguage(language: lang));
Flurry.logEvent("Enter");
yield SessionReady();
}
} on Exception catch (ex) {
+4
View File
@@ -4,6 +4,8 @@ import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
@@ -35,6 +37,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
if (event is SettingsChangeLanguage) {
yield SettingsLoading();
await _changeLang(event.language);
Track().track(TrackingEvent.settings_lang);
yield SettingsReady(_locale);
} else if (event is SettingsGetLanguage) {
await AppLanguage().fetchLocale();
@@ -44,6 +47,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
yield SettingsLoading();
final bool live = event.live;
Cache().setServer(live);
Track().track(TrackingEvent.settings_server);
yield SettingsReady(_locale);
} else if (event is SettingsSetHardware) {
yield SettingsLoading();