diff --git a/i18n/en.json b/i18n/en.json index 3a79c96..cd0dd01 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -555,5 +555,12 @@ "in your calendar": "in your calendar", "Development of My Sizes":"Development of My Sizes", "Date": "Date", - "Muscle development":"Muscle development" + "My Training Logs":"My Training Logs", + "Muscle development":"Muscle development", + "Size development":"Size development", + "Red icon means you have not saved this size.":"Red icon means you have not saved this size.", + "Tap on the green icon to see your development in a diagram":"Tap on the green icon to see your development in a diagram", + "Data Privacy":"Data Privacy", + "Feedback email":"Feedback email" + } \ No newline at end of file diff --git a/i18n/hu.json b/i18n/hu.json index 1917c6a..ad8cccc 100644 --- a/i18n/hu.json +++ b/i18n/hu.json @@ -479,7 +479,7 @@ "The safe and exact execution of this exercise you need a training buddy or a trainer": "A gyakorlat biztonságos és maximális pontosságú végrehajtásához edzőtárs vagy edző segítsége szükséges", "Execution at your own risk!": "Végrehajtás CSAK saját felelőségre!", "With the registration I accept the data policy and the terms of use.": "A regisztrációval elfogadom az adatkezelési szabályzatot és a felhasználási feltételeket.", - "Terms Of Use": "Felh. feltételek", + "Terms Of Use": "Felhasználási feltételek", "Execute at least 3 sets with maximum repeats, without resting time, with decreasing the weight.": "Végezz legalább 3 sorozatot pihenés nélkül és maximális ismétlésszámmal úgy, hogy folyamatosan csökkented a súlyt a szettek között.", "The goal is to completly exhaust your muscle without lifting a ridiculous weight end the end.": "Cél, hogy a végén nevetségesen kis súlyt se bírj megmozdítani és elérd a maximális bedurranást.", "DROP": "VETKŐZÉS", @@ -555,6 +555,12 @@ "in your calendar": "jelöltük a naptárban", "Development of My Sizes":"Méretek fejlődése", "Date": "Dátum", - "Muscle development":"Izom fejlődése" + "My Training Logs":"Edzésnaplóm", + "Muscle development":"Izom fejlődése", + "Size development":"Méreteid fejlődése", + "Red icon means you have not saved this size.":"A piros ikon mutatja, hogy arról méretről nincs még adatod.", + "Tap on the green icon to see your development in a diagram":"Kattints a zöld ikonra, és megmutatjuk a fejlődésed egy diagrammon", + "Data Privacy":"Adatkezelés", + "Feedback email":"Visszajelzés emailben" } \ No newline at end of file diff --git a/lib/bloc/account/account_bloc.dart b/lib/bloc/account/account_bloc.dart index 9b4f89b..dcf3a02 100644 --- a/lib/bloc/account/account_bloc.dart +++ b/lib/bloc/account/account_bloc.dart @@ -1,9 +1,6 @@ -import 'dart:async'; - 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'; @@ -17,12 +14,60 @@ class AccountBloc extends Bloc { bool loggedIn = false; int traineeId = 0; AccountBloc({required this.customerRepository}) : super(AccountInitial()) { + _load(); + on(_onAccountChange); + on(_onLoginChange); + on(_onLoginFinished); + on(_onLogout); + on(_onGetTrainees); + on(_onSelectTrainees); + } + + void _load() { if (Cache().userLoggedIn != null) { customerRepository.customer = Cache().userLoggedIn!; loggedIn = true; } } + void _onAccountChange(AccountChangeCustomer event, Emitter emit) { + emit(AccountLoading()); + emit(AccountReady()); + } + + void _onLoginChange(AccountLogin event, Emitter emit) { + emit(AccountLoading()); + emit(AccountReady()); + } + + void _onLoginFinished(AccountLogInFinished event, Emitter emit) { + emit(AccountLoading()); + customerRepository.customer = event.customer; + this.loggedIn = true; + emit(AccountLoggedIn()); + } + + void _onLogout(AccountLogout event, Emitter emit) async { + emit(AccountLoading()); + await Cache().logout(); + customerRepository.customer = null; + customerRepository.emptyTrainees(); + loggedIn = false; + emit(AccountReady()); + } + + void _onGetTrainees(AccountGetTrainees event, Emitter emit) async { + emit(AccountLoading()); + await customerRepository.getTrainees(); + emit(AccountReady()); + } + + void _onSelectTrainees(AccountSelectTrainee event, Emitter emit) async { + emit(AccountLoading()); + await customerRepository.getTrainees(); + emit(AccountReady()); + } + String getAccurateBodyType() { String bodyType = ("Set your body type"); int _ecto = 0; @@ -57,42 +102,4 @@ class AccountBloc extends Bloc { } return bodyType; } - - @override - Stream mapEventToState( - AccountEvent event, - ) async* { - try { - if (event is AccountChangeCustomer) { - // route to Customer Change page - yield AccountReady(); - } else if (event is AccountLogin) { - //route to Login Page - } else if (event is AccountLogInFinished) { - customerRepository.customer = event.customer; - this.loggedIn = true; - yield AccountLoggedIn(); - } else if (event is AccountLogout) { - await Cache().logout(); - customerRepository.customer = null; - customerRepository.emptyTrainees(); - loggedIn = false; - yield AccountLoggedOut(); - } else if (event is AccountGetTrainees) { - yield AccountLoading(); - await customerRepository.getTrainees(); - yield AccountReady(); - } else if (event is AccountSelectTrainee) { - yield AccountLoading(); - customerRepository.setTrainee(event.traineeId); - Cache().setTrainee(customerRepository.getTraineeById(event.traineeId)!); - ExerciseRepository exerciseRepository = ExerciseRepository(); - await exerciseRepository.getExercisesByCustomer(event.traineeId); - this.traineeId = event.traineeId; - yield AccountReady(); - } - } on Exception catch (e) { - yield AccountError(message: e.toString()); - } - } } diff --git a/lib/bloc/body_development/body_development_bloc.dart b/lib/bloc/body_development/body_development_bloc.dart index 67054b5..1cab930 100644 --- a/lib/bloc/body_development/body_development_bloc.dart +++ b/lib/bloc/body_development/body_development_bloc.dart @@ -1,14 +1,16 @@ import 'dart:async'; +import 'package:aitrainer_app/bloc/development_diagram/development_diagram_bloc.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_repository.dart'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:meta/meta.dart'; +import 'package:flutter/material.dart'; part 'body_development_event.dart'; - part 'body_development_state.dart'; +enum DiagramDateFilterGroup { l3m, fm_lm, l3t, yearly } + class BodyDevelopmentBloc extends Bloc { final WorkoutTreeRepository workoutTreeRepository; final ExerciseRepository exerciseRepository = ExerciseRepository(); @@ -16,28 +18,50 @@ class BodyDevelopmentBloc extends Bloc radarTicks = []; List radarFeatures = []; List> radarData = []; + DiagramGroup group = DiagramGroup.sumMass; + DiagramDateFilterGroup filter = DiagramDateFilterGroup.l3t; @override - BodyDevelopmentBloc({required this.workoutTreeRepository}) : super(BodyDevelopmentInitial()); + BodyDevelopmentBloc({required this.workoutTreeRepository}) : super(BodyDevelopmentInitial()) { + on(_onLoad); + on(_onDateFilterChange); + on(_onGroupChange); + } + + List defaultGraphColors = [ + Colors.green, + Colors.blue, + Colors.red, + Colors.orange, + ]; Future getData() async { radarTicks = [20, 40, 60, 80, 100]; - radarFeatures = ["Mell", "Bicepsz", "Tricepsz", "Hát", "Váll"]; + radarFeatures = ["Mell", "Bicepsz", "Tricepsz", "Hát", "Váll", "Core", "Comb", "Vádli"]; radarData = [ - [80, 95, 45, 67, 83] + [80, 95, 45, 67, 83, 40, 56, 78], + [82, 90, 56, 77, 82, 40, 50, 87], + [86, 92, 58, 70, 80, 49, 52, 87], ]; } - @override - Stream mapEventToState(BodyDevelopmentEvent event) async* { - try { - if (event is BodyDevelopmentLoad) { - yield BodyDevelopmentLoading(); - await getData(); - yield BodyDevelopmentReady(); - } - } on Exception catch (e) { - yield BodyDevelopmentError(message: e.toString()); - } + void _onLoad(BodyDevelopmentLoad event, Emitter emit) { + emit(BodyDevelopmentLoading()); + getData(); + emit(BodyDevelopmentReady()); + } + + void _onDateFilterChange(BodyDevelopmentChangeDate event, Emitter emit) { + emit(BodyDevelopmentLoading()); + this.filter = event.filter; + getData(); + emit(BodyDevelopmentReady()); + } + + void _onGroupChange(BodyDevelopmentChangeGroup event, Emitter emit) { + emit(BodyDevelopmentLoading()); + this.group = event.group; + getData(); + emit(BodyDevelopmentReady()); } } diff --git a/lib/bloc/body_development/body_development_event.dart b/lib/bloc/body_development/body_development_event.dart index 7e55235..4aaf24d 100644 --- a/lib/bloc/body_development/body_development_event.dart +++ b/lib/bloc/body_development/body_development_event.dart @@ -1,7 +1,7 @@ part of 'body_development_bloc.dart'; @immutable -abstract class BodyDevelopmentEvent extends Equatable{ +abstract class BodyDevelopmentEvent extends Equatable { const BodyDevelopmentEvent(); @override List get props => []; @@ -10,3 +10,13 @@ abstract class BodyDevelopmentEvent extends Equatable{ class BodyDevelopmentLoad extends BodyDevelopmentEvent { const BodyDevelopmentLoad(); } + +class BodyDevelopmentChangeGroup extends BodyDevelopmentEvent { + final DiagramGroup group; + const BodyDevelopmentChangeGroup({required this.group}); +} + +class BodyDevelopmentChangeDate extends BodyDevelopmentEvent { + final DiagramDateFilterGroup filter; + const BodyDevelopmentChangeDate({required this.filter}); +} diff --git a/lib/bloc/body_type/bodytype_bloc.dart b/lib/bloc/body_type/bodytype_bloc.dart index 0212cbb..a83d7ac 100644 --- a/lib/bloc/body_type/bodytype_bloc.dart +++ b/lib/bloc/body_type/bodytype_bloc.dart @@ -20,6 +20,35 @@ class BodytypeBloc extends Bloc { final weights = List.generate(numberQuestions, (i) => []..length = 3, growable: false); BodytypeBloc({required this.repository}) : super(BodytypeInitial()) { + this._load(); + on(_onBodyTypeClick); + on(_onBodyTypeClickBack); + } + + void _onBodyTypeClick(BodytypeClick event, Emitter emit) async { + emit(BodytypeLoading()); + this.value = event.value; + answers[step - 1] = value; + calculateBodyType(); + await saveToDB(); + if (step >= questions.length) { + emit(BodytypeFinished()); + return; + } + step++; + emit(BodytypeReady()); + } + + void _onBodyTypeClickBack(BodytypeBack event, Emitter emit) async { + if (step == 1) { + emit(BodytypeReady()); + return; + } + step--; + this.value = answers[step - 1]; + } + + void _load() { questions.add("1. Basicly I am skinny and bonny"); questions.add("2. question"); questions.add("3. question"); @@ -90,38 +119,6 @@ class BodytypeBloc extends Bloc { int _mezo = 0; int _endo = 0; - @override - Stream 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; } diff --git a/lib/bloc/customer_change/customer_change_bloc.dart b/lib/bloc/customer_change/customer_change_bloc.dart index 26192ca..2867071 100644 --- a/lib/bloc/customer_change/customer_change_bloc.dart +++ b/lib/bloc/customer_change/customer_change_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/sport.dart'; import 'package:aitrainer_app/repository/customer_repository.dart'; @@ -21,6 +19,176 @@ class CustomerChangeBloc extends Bloc double weight = 60; double height = 170; CustomerChangeBloc({required this.customerRepository}) : super(CustomerChangeInitial()) { + this._load(); + on(_onLoad); + on(_onGoalChange); + on(_onChangePasswordObscure); + on(_onFitnessChange); + on(_onBirthyearChange); + on(_onWeightChange); + on(_onHeightChange); + on(_onBodytypeChange); + on(_onEmailChange); + on(_onPasswordChange); + on(_onFirstNameChange); + on(_onNameChange); + on(_onGenderChange); + on(_onSportChange); + on(_onSaveFitness); + on(_onSaveGoal); + on(_onSaveSex); + on(_onSaveWeight); + on(_onSaveHeight); + on(_onSave); + } + + void _onLoad(CustomerLoad event, Emitter emit) async { + emit(CustomerChangeLoading()); + emit(CustomerDataChanged()); + } + + void _onGoalChange(CustomerGoalChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setGoal(event.goal); + emit(CustomerDataChanged()); + } + + void _onChangePasswordObscure(CustomerChangePasswordObscure event, Emitter emit) { + emit(CustomerChangeLoading()); + visiblePassword = !visiblePassword; + emit(CustomerDataChanged()); + } + + void _onFitnessChange(CustomerFitnessChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setFitnessLevel(event.fitness); + selectedFitnessItem = event.fitness; + emit(CustomerDataChanged()); + } + + void _onBirthyearChange(CustomerBirthYearChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setBirthYear(event.year); + year = event.year; + emit(CustomerDataChanged()); + } + + void _onWeightChange(CustomerWeightChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setWeight(event.weight); + weight = event.weight.toDouble(); + emit(CustomerDataChanged()); + } + + void _onHeightChange(CustomerHeightChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setHeight(event.height); + height = event.height.toDouble(); + emit(CustomerDataChanged()); + } + + void _onBodytypeChange(CustomerBodyTypeChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setBodyType(event.bodyType); + emit(CustomerDataChanged()); + } + + void _onEmailChange(CustomerEmailChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setEmail(event.email); + emit(CustomerDataChanged()); + } + + void _onPasswordChange(CustomerPasswordChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setPassword(event.password); + emit(CustomerDataChanged()); + } + + void _onFirstNameChange(CustomerFirstNameChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setFirstName(event.firstName); + emit(CustomerDataChanged()); + } + + void _onNameChange(CustomerNameChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setName(event.name); + emit(CustomerDataChanged()); + } + + void _onGenderChange(CustomerGenderChange event, Emitter emit) { + emit(CustomerChangeLoading()); + customerRepository.setSex(event.gender == 0 ? "m" : "w"); + emit(CustomerDataChanged()); + } + + void _onSportChange(CustomerSportChange event, Emitter emit) { + emit(CustomerChangeLoading()); + selectedSport = event.sport; + print("Selected Sport $selectedSport"); + emit(CustomerDataChanged()); + } + + void _onSaveFitness(CustomerSaveFitness event, Emitter emit) { + emit(CustomerChangeLoading()); + if (customerRepository.customer!.fitnessLevel == null) { + throw Exception("Please select your fitness level"); + } + emit(CustomerSaveSuccess()); + } + + void _onSaveGoal(CustomerSaveGoal event, Emitter emit) { + emit(CustomerChangeLoading()); + if (customerRepository.customer!.goal == null) { + throw Exception("Please select your goal"); + } + emit(CustomerSaveSuccess()); + } + + void _onSaveSex(CustomerSaveSex event, Emitter emit) { + emit(CustomerChangeLoading()); + if (customerRepository.customer!.sex == null) { + throw Exception("Please select your biologial gender"); + } + emit(CustomerSaveSuccess()); + } + + void _onSaveWeight(CustomerSaveWeight event, Emitter emit) { + emit(CustomerChangeLoading()); + emit(CustomerSaveSuccess()); + } + + void _onSaveHeight(CustomerSaveHeight event, Emitter emit) { + emit(CustomerChangeLoading()); + emit(CustomerSaveSuccess()); + } + + void _onSave(CustomerSave event, Emitter emit) async { + emit(CustomerSaving()); + if (validation()) { + if (selectedFitnessItem != null) { + customerRepository.setFitnessLevel(selectedFitnessItem!); + } + if (selectedSport != null) { + customerRepository.customer!.sportId = selectedSport!.sportId; + } + + if (customerRepository.customer!.lang == null) { + customerRepository.customer!.lang = AppLanguage().appLocal.languageCode; + } + + await customerRepository.saveCustomer(); + MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); + await mauticRepository.sendMauticDataChange(); + Cache().initBadges(); + emit(CustomerSaveSuccess()); + } else { + emit(CustomerSaveError(message: "Please provide the necessary information")); + } + } + + void _load() { if (this.customerRepository.customer == null) { this.customerRepository.createNew(); } @@ -38,119 +206,6 @@ class CustomerChangeBloc extends Bloc Sport? selectedSport; String? selectedFitnessItem; - @override - Stream mapEventToState( - CustomerChangeEvent event, - ) async* { - try { - print("Event: $event"); - if (event is CustomerLoad) { - yield CustomerChangeLoading(); - yield CustomerDataChanged(); - } else if (event is CustomerGoalChange) { - yield CustomerChangeLoading(); - customerRepository.setGoal(event.goal); - yield CustomerDataChanged(); - } else if (event is CustomerChangePasswordObscure) { - yield CustomerChangeLoading(); - visiblePassword = !visiblePassword; - yield CustomerDataChanged(); - } else if (event is CustomerFitnessChange) { - yield CustomerChangeLoading(); - customerRepository.setFitnessLevel(event.fitness); - selectedFitnessItem = event.fitness; - yield CustomerDataChanged(); - } else if (event is CustomerBirthYearChange) { - yield CustomerChangeLoading(); - customerRepository.setBirthYear(event.year); - year = event.year; - yield CustomerDataChanged(); - } else if (event is CustomerWeightChange) { - //yield CustomerChangeLoading(); - customerRepository.setWeight(event.weight); - weight = event.weight.toDouble(); - yield CustomerDataChanged(); - } else if (event is CustomerHeightChange) { - yield CustomerChangeLoading(); - customerRepository.setHeight(event.height); - height = event.height.toDouble(); - yield CustomerDataChanged(); - } else if (event is CustomerBodyTypeChange) { - customerRepository.setBodyType(event.bodyType); - yield CustomerDataChanged(); - } else if (event is CustomerEmailChange) { - customerRepository.setEmail(event.email); - yield CustomerDataChanged(); - } else if (event is CustomerPasswordChange) { - customerRepository.setPassword(event.password); - yield CustomerDataChanged(); - } else if (event is CustomerFirstNameChange) { - customerRepository.setFirstName(event.firstName); - yield CustomerDataChanged(); - } else if (event is CustomerNameChange) { - customerRepository.setName(event.name); - yield CustomerDataChanged(); - } else if (event is CustomerGenderChange) { - yield CustomerChangeLoading(); - customerRepository.setSex(event.gender == 0 ? "m" : "w"); - yield CustomerDataChanged(); - } else if (event is CustomerSportChange) { - yield CustomerChangeLoading(); - selectedSport = event.sport; - print("Selected Sport $selectedSport"); - yield CustomerDataChanged(); - } else if (event is CustomerSaveFitness) { - yield CustomerChangeLoading(); - if (customerRepository.customer!.fitnessLevel == null) { - throw Exception("Please select your fitness level"); - } - yield CustomerSaveSuccess(); - } else if (event is CustomerSaveGoal) { - yield CustomerChangeLoading(); - if (customerRepository.customer!.goal == null) { - throw Exception("Please select your goal"); - } - yield CustomerSaveSuccess(); - } else if (event is CustomerSaveSex) { - yield CustomerChangeLoading(); - if (customerRepository.customer!.sex == null) { - throw Exception("Please select your biologial gender"); - } - yield CustomerSaveSuccess(); - } else if (event is CustomerSaveWeight) { - yield CustomerChangeLoading(); - yield CustomerSaveSuccess(); - } else if (event is CustomerSaveHeight) { - yield CustomerChangeLoading(); - yield CustomerSaveSuccess(); - } else if (event is CustomerSave) { - yield CustomerSaving(); - if (validation()) { - if (selectedFitnessItem != null) { - customerRepository.setFitnessLevel(selectedFitnessItem!); - } - if (selectedSport != null) { - customerRepository.customer!.sportId = selectedSport!.sportId; - } - - if (customerRepository.customer!.lang == null) { - customerRepository.customer!.lang = AppLanguage().appLocal.languageCode; - } - - await customerRepository.saveCustomer(); - MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); - await mauticRepository.sendMauticDataChange(); - Cache().initBadges(); - yield CustomerSaveSuccess(); - } else { - yield CustomerSaveError(message: "Please provide the necessary information"); - } - } - } on Exception catch (e) { - yield CustomerSaveError(message: e.toString()); - } - } - bool validation() { if (customerRepository.customer == null) throw Exception("Customer object not defined"); return true; diff --git a/lib/bloc/customer_exercise_device/customer_exercise_device_bloc.dart b/lib/bloc/customer_exercise_device/customer_exercise_device_bloc.dart index ae71d51..fea3ebf 100644 --- a/lib/bloc/customer_exercise_device/customer_exercise_device_bloc.dart +++ b/lib/bloc/customer_exercise_device/customer_exercise_device_bloc.dart @@ -1,5 +1,3 @@ -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'; @@ -16,36 +14,38 @@ class CustomerExerciseDeviceBloc extends Bloc? devices; CustomerExerciseDeviceBloc({required this.repository, required this.devices}) : super(CustomerExerciseDeviceInitial()) { + _load(); + on(_onLoad); + on(_onDeviceAdd); + on(_onDeviceRemove); + } + + void _onLoad(CustomerExerciseDeviceLoad event, Emitter emit) { + emit(CustomerExerciseDeviceLoading()); + emit(CustomerExerciseDeviceReady()); + } + + void _onDeviceAdd(CustomerExerciseDeviceAdd event, Emitter emit) async { + emit(CustomerExerciseDeviceLoading()); + await repository.addDevice(event.device); + Cache().initBadges(); + emit(CustomerExerciseDeviceReady()); + } + + void _onDeviceRemove(CustomerExerciseDeviceRemove event, Emitter emit) async { + emit(CustomerExerciseDeviceLoading()); + await repository.removeDevice(event.device); + Cache().initBadges(); + emit(CustomerExerciseDeviceReady()); + } + + void _load() { if (repository.getDevices().isEmpty) { repository.setDevices(Cache().getCustomerDevices()!); } Track().track(TrackingEvent.exercise_device); } - @override - Stream mapEventToState( - CustomerExerciseDeviceEvent event, - ) async* { - try { - if (event is CustomerExerciseDeviceLoad) { - yield CustomerExerciseDeviceLoading(); - yield CustomerExerciseDeviceReady(); - } else if (event is CustomerExerciseDeviceAdd) { - yield CustomerExerciseDeviceLoading(); - await repository.addDevice(event.device); - Cache().initBadges(); - yield CustomerExerciseDeviceReady(); - } else if (event is CustomerExerciseDeviceRemove) { - yield CustomerExerciseDeviceLoading(); - await repository.removeDevice(event.device); - Cache().initBadges(); - yield CustomerExerciseDeviceReady(); - } - } on Exception catch (ex) { - yield CustomerExerciseDeviceError(message: ex.toString()); - } - } - bool hasCustomerDevice(int exerciseDeviceId) { return repository.hasDevice(exerciseDeviceId); } diff --git a/lib/bloc/development_by_muscle/development_by_muscle_bloc.dart b/lib/bloc/development_by_muscle/development_by_muscle_bloc.dart index 8c966d8..642c429 100644 --- a/lib/bloc/development_by_muscle/development_by_muscle_bloc.dart +++ b/lib/bloc/development_by_muscle/development_by_muscle_bloc.dart @@ -1,12 +1,9 @@ -import 'package:intl/intl.dart'; -import 'dart:async'; import 'package:aitrainer_app/model/cache.dart'; -import 'package:aitrainer_app/model/exercise.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_repository.dart'; import 'package:aitrainer_app/service/logging.dart'; -import 'package:aitrainer_app/util/app_language.dart'; + import 'package:aitrainer_app/util/common.dart'; import 'package:aitrainer_app/util/enums.dart'; import 'package:aitrainer_app/util/diagram_data.dart'; @@ -18,391 +15,17 @@ import 'package:flutter/material.dart'; part 'development_by_muscle_event.dart'; part 'development_by_muscle_state.dart'; -enum DiagramType { sumMass, oneRepMax, percent } -enum DiagramDateType { daily, weekly, monthly, yearly } - -class GroupDate extends GroupData with Common { - final List inputList; - final List outputList; - - String? _origDatePart; - late int _origExerciseTypeId; - late Exercise _origExercise; - - late double _sumQuantity; - late double _maxQuantity; - late int _countExercises; - - late DiagramType diagramType; - late DiagramDateType dateRate; - - GroupDate({required this.inputList, required this.outputList}); - - double getQuantityByDate(Exercise exercise) { - double sum = 0; - if (this.diagramType == DiagramType.sumMass) { - if (exercise.unitQuantity != null) { - sum = exercise.quantity! * exercise.unitQuantity!; - } else { - sum = exercise.quantity!; - } - } else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) { - if (exercise.unitQuantity != null) { - sum = calculate1RM(exercise.quantity!, exercise.unitQuantity!); - } else { - sum = exercise.quantity!; - } - } - return sum; - } - - @override - void addTempData(Exercise exercise) { - double newQuantity = getQuantityByDate(exercise); - _sumQuantity = _sumQuantity + newQuantity; - if (_maxQuantity < newQuantity) { - _maxQuantity = newQuantity; - } - _countExercises = _countExercises + 1; - _origDatePart = getDatePart(exercise.dateAdd!, dateRate); - _origExerciseTypeId = exercise.exerciseTypeId!; - _origExercise = exercise; - } - - @override - bool checkNewType(Exercise exercise) { - String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate); - return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId; - } - - String getDatePart(DateTime date, DiagramDateType dateRate) { - String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date); - if (dateRate == DiagramDateType.weekly) { - datePart = weekNumber(date).toString(); - } else if (dateRate == DiagramDateType.monthly) { - datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date); - } else if (dateRate == DiagramDateType.yearly) { - datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date); - } else if (dateRate == DiagramDateType.daily) { - datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date); - } - return datePart; - } - - @override - void iteration() { - this.resetTemp(); - Exercise? tempExercise; - inputList.forEach((element) { - tempExercise = element; - if (this.checkNewType(element)) { - if (_origDatePart == null) { - this.addTempData(element); - } else { - this.temp2Output(_origExercise); - this.resetTemp(); - this.addTempData(element); - } - } else { - this.addTempData(element); - } - }); - if (tempExercise != null) { - this.temp2Output(tempExercise!); - } - } - - @override - void temp2Output(Exercise exercise) { - if (exercise.unitQuantity == null) { - return; - } - Exercise newExercise = exercise.copy(); - newExercise.datePart = _origDatePart; - if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) { - newExercise.calculated = _maxQuantity; - } else { - newExercise.calculated = _sumQuantity / _countExercises; - } - DiagramData data = DiagramData(newExercise.datePart!, newExercise.calculated); - outputList.add(data); - } - - @override - void resetTemp() { - _countExercises = 0; - _sumQuantity = 0; - _maxQuantity = 0; - } -} - -/* -class DiagramType { - static String sumMass = "sumMass"; - static String oneRepMax = "oneRepMax"; - static String percent = "percent"; -} - -/* - =========== GROUPDATE CLASS - */ - -class GroupDate extends GroupData with Common { - final List inputList; - final List outputList; - - String? _origDatePart; - late int _origExerciseTypeId; - late Exercise _origExercise; - - late double _sumQuantity; - late double _maxQuantity; - late int _countExercises; - - late String diagramType; - late String dateRate; - - GroupDate({required this.inputList, required this.outputList}); - - double getQuantityByDate(Exercise exercise) { - double sum = 0; - if (this.diagramType == DiagramType.sumMass) { - if (exercise.unitQuantity != null) { - sum = exercise.quantity! * exercise.unitQuantity!; - } else { - sum = exercise.quantity!; - } - } else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) { - if (exercise.unitQuantity != null) { - sum = calculate1RM(exercise.quantity!, exercise.unitQuantity!); - } else { - sum = exercise.quantity!; - } - } - return sum; - } - - @override - void addTempData(Exercise exercise) { - double newQuantity = getQuantityByDate(exercise); - _sumQuantity = _sumQuantity + newQuantity; - if (_maxQuantity < newQuantity) { - _maxQuantity = newQuantity; - } - _countExercises = _countExercises + 1; - _origDatePart = getDatePart(exercise.dateAdd!, dateRate); - _origExerciseTypeId = exercise.exerciseTypeId!; - _origExercise = exercise; - } - - @override - bool checkNewType(Exercise exercise) { - String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate); - return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId; - } - - @override - void iteration() { - this.resetTemp(); - Exercise? tempExercise; - inputList.forEach((element) { - tempExercise = element; - if (this.checkNewType(element)) { - if (_origDatePart == null) { - this.addTempData(element); - } else { - this.temp2Output(_origExercise); - this.resetTemp(); - this.addTempData(element); - } - } else { - this.addTempData(element); - } - }); - if (tempExercise != null) { - this.temp2Output(tempExercise!); - } - } - - @override - void temp2Output(Exercise exercise) { - if (exercise.unitQuantity == null) { - return; - } - Exercise newExercise = exercise.copy(); - newExercise.datePart = _origDatePart; - if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) { - newExercise.calculated = _maxQuantity; - } else { - newExercise.calculated = _sumQuantity / _countExercises; - } - outputList.add(newExercise); - } - - @override - void resetTemp() { - _countExercises = 0; - _sumQuantity = 0; - _maxQuantity = 0; - } -} - -/* - =========== CHART DATA CLASS - */ -class GroupChart extends GroupData with Common { - final List inputList; - LinkedHashMap outputList = LinkedHashMap(); - - int? _origExerciseTypeId; - late double _minData = 999999999999; - late double _maxData = 0; - late List _chartData; - late double _basePercent; - - String diagramType = DiagramType.sumMass; - - GroupChart({required this.inputList, required this.outputList}); - - double getBasePercent(Exercise exercise) { - if (exercise.unitQuantity != null) { - this._basePercent = calculate1RM(exercise.quantity!, exercise.unitQuantity!); - } else { - this._basePercent = exercise.quantity!; - } - return this._basePercent; - } - - double getDiagramValue(Exercise exercise) { - double value = 0; - - if (diagramType == DiagramType.percent) { - if (exercise.unitQuantity != null) { - double oneRepMax = calculate1RM(exercise.quantity!, exercise.unitQuantity!); - value = (oneRepMax / this._basePercent) * 100; - } else { - value = (exercise.quantity! / this._basePercent) * 100; - } - } else if (diagramType == DiagramType.oneRepMax || diagramType == DiagramType.sumMass) { - value = exercise.calculated!; - } - return value; - } - - @override - void addTempData(Exercise exercise) { - double diagramValue = this.getDiagramValue(exercise); - - if (_maxData < diagramValue) { - _maxData = diagramValue; - } - if (_minData > diagramValue) { - _minData = diagramValue; - } - - BarChartGroupData data = BarChartGroupData( - x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [BarChartRodData(toY: diagramValue, width: 12, color: Colors.lightBlue)]); - _chartData.add(data); - _origExerciseTypeId = exercise.exerciseTypeId!; - } - - @override - bool checkNewType(Exercise exercise) { - return _origExerciseTypeId == null || _origExerciseTypeId != exercise.exerciseTypeId; - } - - @override - void iteration() { - this.resetTemp(); - Exercise? tempExercise; - inputList.forEach((element) { - tempExercise = element; - - if (this.checkNewType(element)) { - if (_origExerciseTypeId == null) { - _basePercent = getBasePercent(element); - this.addTempData(element); - } else { - this.temp2Output(element); - this.resetTemp(); - _basePercent = getBasePercent(element); - this.addTempData(element); - } - } else { - this.addTempData(element); - } - }); - if (tempExercise != null) { - this.temp2Output(tempExercise!); - } - } - - @override - void temp2Output(Exercise exercise) { - double dInterval = ((_maxData + _minData) / 8).roundToDouble(); - int gridInterval = (dInterval / 3).floor(); - - ChartDataExtended extended; - if (outputList[_origExerciseTypeId] == null) { - extended = ChartDataExtended(data: _chartData, interval: dInterval, gridInterval: gridInterval); - outputList[_origExerciseTypeId!] = extended; - } else { - extended = outputList[_origExerciseTypeId]!; - _chartData.forEach((element) { - extended.data.add(element); - }); - } - } - - @override - void resetTemp() { - _minData = 999999999999; - _maxData = 0; - _chartData = []; - } -} - -class ChartDataExtended { - final List data; - final double interval; - final int gridInterval; - - const ChartDataExtended({required this.data, required this.interval, required this.gridInterval}); - - Map toJson() { - List listBarChartData = []; - data.forEach((element) { - element.barRods.forEach((rods) { - var barChartData = { - 'x': element.x, - 'y': rods.toY, - }; - listBarChartData.add(barChartData); - }); - }); - var chartData = { - "data": listBarChartData.toString(), - "interval": interval.toString(), - "gridInterval": gridInterval, - }; - return chartData; - } -} */ - class DevelopmentByMuscleBloc extends Bloc with Common, Logging { final WorkoutTreeRepository workoutTreeRepository; final ExerciseRepository exerciseRepository = ExerciseRepository(); final List diagramData = []; - int actualExerciseType = 0; - DiagramType diagramType = DiagramType.sumMass; - DiagramDateType diagramDateType = DiagramDateType.monthly; @override DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial()) { on(_onLoad); } - Future getData() async { + void getTree() { workoutTreeRepository.sortedTree.clear(); workoutTreeRepository.sortByMuscleType(); @@ -414,11 +37,11 @@ class DevelopmentByMuscleBloc extends Bloc emit) async { + void _onLoad(DevelopmentByMuscleLoad event, Emitter emit) { emit(DevelopmentByMuscleLoadingState()); Track().track(TrackingEvent.my_muscle_development); Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen); - await getData(); + getTree(); emit(DevelopmentByMuscleReadyState()); } } diff --git a/lib/bloc/development_by_muscle/development_by_muscle_event.dart b/lib/bloc/development_by_muscle/development_by_muscle_event.dart index 2b55999..2c7df75 100644 --- a/lib/bloc/development_by_muscle/development_by_muscle_event.dart +++ b/lib/bloc/development_by_muscle/development_by_muscle_event.dart @@ -11,19 +11,3 @@ abstract class DevelopmentByMuscleEvent extends Equatable { class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent { const DevelopmentByMuscleLoad(); } - -class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent { - final DiagramDateType dateRate; - const DevelopmentByMuscleDateRateChange({required this.dateRate}); - - @override - List get props => [dateRate]; -} - -class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent { - final DiagramType diagramType; - const DevelopmentByMuscleDiagramTypeChange({required this.diagramType}); - - @override - List get props => [diagramType]; -} diff --git a/lib/bloc/exercise_control/exercise_control_bloc.dart b/lib/bloc/exercise_control/exercise_control_bloc.dart index a7cb02a..9fb1d69 100644 --- a/lib/bloc/exercise_control/exercise_control_bloc.dart +++ b/lib/bloc/exercise_control/exercise_control_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'package:aitrainer_app/bloc/timer/timer_bloc.dart'; import 'package:aitrainer_app/model/exercise.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; @@ -39,8 +38,14 @@ class ExerciseControlBloc extends Bloc controlList = []; @override - ExerciseControlBloc({required this.exerciseRepository, required this.readonly, required this.timerBloc}) - : super(ExerciseControlInitial()) { + ExerciseControlBloc({required this.exerciseRepository, required this.readonly, required this.timerBloc}) : super(ExerciseControlInitial()) { + _load(); + on(_onQuantityChange); + on(_onQuantityUnitChange); + on(_onSubmit); + } + + void _load() { print("Exercise ${exerciseRepository.exercise!.toJson()}"); exerciseTypeLocal = ExerciseTypeLocal.oneRepMax; @@ -69,47 +74,46 @@ class ExerciseControlBloc extends Bloc mapEventToState(ExerciseControlEvent event) async* { - try { - if (event is ExerciseControlQuantityChange) { - if (event.step == step) { - exerciseRepository.setQuantity(event.quantity); - quantity = event.quantity; - controlList[step - 1].quantity = quantity; - } - } else if (event is ExerciseControlUnitQuantityChange) { - yield ExerciseControlLoading(); - print("event step ${event.step} quantity ${event.quantity}"); - if (event.step == step) { - this.unitQuantity = event.quantity; - exerciseRepository.setUnitQuantity(event.quantity); - unitQuantity = event.quantity; - quantity = calculateQuantityByUnitQuantity().toDouble(); - exerciseRepository.setQuantity(quantity); - controlList[step - 1].unitQuantity = event.quantity; - controlList[step - 1].quantity = quantity; - } - yield ExerciseControlReady(); - } else if (event is ExerciseControlSubmit) { - yield ExerciseControlLoading(); - if (event.step == step) { - step++; - scrollOffset = step * 400.0; - - if (exerciseRepository.exercise!.quantity == null) { - exerciseRepository.setQuantity(quantity); - } - exerciseRepository.end = DateTime.now(); - await exerciseRepository.addExercise(); - - step <= 3 ? timerBloc.add(TimerStart(duration: 300)) : timerBloc.add(TimerEnd(duration: 300)); - } - yield ExerciseControlReady(); - } - } on Exception catch (e) { - yield ExerciseControlError(message: e.toString()); + void _onQuantityChange(ExerciseControlQuantityChange event, Emitter emit) { + emit(ExerciseControlLoading()); + if (event.step == step) { + exerciseRepository.setQuantity(event.quantity); + quantity = event.quantity; + controlList[step - 1].quantity = quantity; } + emit(ExerciseControlReady()); + } + + void _onQuantityUnitChange(ExerciseControlUnitQuantityChange event, Emitter emit) { + emit(ExerciseControlLoading()); + print("event step ${event.step} quantity ${event.quantity}"); + if (event.step == step) { + this.unitQuantity = event.quantity; + exerciseRepository.setUnitQuantity(event.quantity); + unitQuantity = event.quantity; + quantity = calculateQuantityByUnitQuantity().toDouble(); + exerciseRepository.setQuantity(quantity); + controlList[step - 1].unitQuantity = event.quantity; + controlList[step - 1].quantity = quantity; + } + emit(ExerciseControlReady()); + } + + void _onSubmit(ExerciseControlSubmit event, Emitter emit) async { + emit(ExerciseControlLoading()); + if (event.step == step) { + step++; + scrollOffset = step * 400.0; + + if (exerciseRepository.exercise!.quantity == null) { + exerciseRepository.setQuantity(quantity); + } + exerciseRepository.end = DateTime.now(); + await exerciseRepository.addExercise(); + + step <= 3 ? timerBloc.add(TimerStart(duration: 300)) : timerBloc.add(TimerEnd(duration: 300)); + } + emit(ExerciseControlReady()); } double calculate1RM({bool percent75 = true}) { diff --git a/lib/bloc/exercise_new/exercise_new_bloc.dart b/lib/bloc/exercise_new/exercise_new_bloc.dart index 1c1489b..f13af79 100644 --- a/lib/bloc/exercise_new/exercise_new_bloc.dart +++ b/lib/bloc/exercise_new/exercise_new_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'package:aitrainer_app/repository/mautic_repository.dart'; import 'package:intl/intl.dart'; import 'package:aitrainer_app/main.dart'; @@ -56,11 +55,28 @@ class ExerciseNewBloc extends Bloc with Logg ); late int timerValue; + late ExerciseType exerciseType; + @override - ExerciseNewBloc( - {required this.exerciseRepository, required this.menuBloc, required this.customerRepository, required ExerciseType exerciseType}) + ExerciseNewBloc({required this.exerciseRepository, required this.menuBloc, required this.customerRepository, required this.exerciseType}) : super(ExerciseNewInitial()) { - exerciseRepository.exerciseType = exerciseType; + this._load(); + on(_onQuantityChange); + on(_onQuantityUnitChange); + on(_onWeightChange); + on(_onFitnessLevelChange); + on(_onBirthyearChange); + on(_onHeightChange); + on(_onSaveWeight); + on(_onSizeChange); + on(_onSubmit); + on(_onSubmitNoRegistration); + on(_onBMIAnimate); + on(_onAddError); + } + + void _load() { + exerciseRepository.exerciseType = this.exerciseType; exerciseRepository.setUnit(exerciseType.unit); exerciseRepository.setUnitQuantity(unitQuantity); exerciseRepository.setQuantity(quantity); @@ -78,110 +94,120 @@ class ExerciseNewBloc extends Bloc with Logg } } + void _onQuantityChange(ExerciseNewQuantityChange event, Emitter emit) { + emit(ExerciseNewLoading()); + log("Event quantity " + event.quantity.toStringAsFixed(0)); + this.setQuantity(event.quantity); + emit(ExerciseNewReady()); + } + + void _onQuantityUnitChange(ExerciseNewQuantityUnitChange event, Emitter emit) { + emit(ExerciseNewLoading()); + log("Event quantityUnit " + event.quantity.toStringAsFixed(0)); + exerciseRepository.setUnitQuantity(event.quantity); + unitQuantity = event.quantity; + emit(ExerciseNewReady()); + } + + void _onWeightChange(ExerciseNewWeightChange event, Emitter emit) { + emit(ExerciseNewLoading()); + customerRepository.setWeight(event.value); + changedWeight = true; + weight = event.value; + getBMI(); + getGoalBMI(); + getBMR(); + emit(ExerciseNewReady()); + } + + void _onFitnessLevelChange(ExerciseNewFitnessLevelChange event, Emitter emit) { + emit(ExerciseNewLoading()); + customerRepository.setFitnessLevel(event.value); + fitnessLevel = event.value; + changedWeight = true; + getBMR(); + emit(ExerciseNewReady()); + } + + void _onBirthyearChange(ExerciseNewBirthyearChange event, Emitter emit) { + emit(ExerciseNewLoading()); + changedWeight = true; + customerRepository.setBirthYear(event.value.toInt()); + birthYear = event.value; + emit(ExerciseNewReady()); + } + + void _onHeightChange(ExerciseNewHeightChange event, Emitter emit) { + emit(ExerciseNewLoading()); + customerRepository.setHeight(event.value.toInt()); + changedWeight = true; + height = event.value; + getBMI(); + getGoalBMI(); + getBMR(); + emit(ExerciseNewReady()); + } + + void _onSaveWeight(ExerciseNewSaveWeight event, Emitter emit) { + emit(ExerciseNewLoading()); + customerRepository.saveCustomer(); + changedWeight = false; + this.changedSizes = false; + Cache().initBadges(); + Track().track(TrackingEvent.sizes); + emit(ExerciseNewReady()); + } + + void _onSizeChange(ExerciseNewSizeChange event, Emitter emit) { + emit(ExerciseNewLoading()); + this.changedSizes = true; + this.customerRepository.updateSizes(event.propertyName, event.value); + customerRepository.setCustomerProperty(event.propertyName, event.value); + emit(ExerciseNewReady()); + } + + void _onSubmit(ExerciseNewSubmit event, Emitter emit) async { + emit(ExerciseNewLoading()); + if (quantity == -1 || unitQuantity == -1) { + emit(ExerciseNewReady()); + throw Exception("Please type in a real number"); + } + + exerciseRepository.end = DateTime.now(); + await exerciseRepository.addExercise(); + if (!isInDebugMode) { + MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); + await mauticRepository.sendMauticExercise(); + } + menuBloc.add(MenuTreeDown(parent: 0)); + Cache().initBadges(); + Track().track(TrackingEvent.exercise_new, eventValue: exerciseRepository.exerciseType!.name); + emit(ExerciseNewReady()); + } + + void _onSubmitNoRegistration(ExerciseNewSubmitNoRegistration event, Emitter emit) async { + emit(ExerciseNewLoading()); + exerciseRepository.addExerciseNoRegistration(); + menuBloc.add(MenuTreeDown(parent: 0)); + Track().track(TrackingEvent.exercise_new_no_registration, eventValue: exerciseRepository.exerciseType!.name); + emit(ExerciseNewReady()); + } + + void _onBMIAnimate(ExerciseNewBMIAnimate event, Emitter emit) async { + emit(ExerciseNewLoading()); + emit(ExerciseNewReady()); + } + + void _onAddError(ExerciseNewAddError event, Emitter emit) async { + emit(ExerciseNewLoading()); + emit(ExerciseNewReady()); + } + void setQuantity(double quantity) { this.quantity = quantity; exerciseRepository.setQuantity(quantity); } - @override - Stream mapEventToState(ExerciseNewEvent event) async* { - try { - if (event is ExerciseNewLoad) { - yield ExerciseNewLoading(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewQuantityChange) { - yield ExerciseNewLoading(); - log("Event quantity " + event.quantity.toStringAsFixed(0)); - this.setQuantity(event.quantity); - yield ExerciseNewReady(); - } else if (event is ExerciseNewQuantityUnitChange) { - yield ExerciseNewLoading(); - log("Event quantityUnit " + event.quantity.toStringAsFixed(0)); - exerciseRepository.setUnitQuantity(event.quantity); - unitQuantity = event.quantity; - yield ExerciseNewReady(); - } else if (event is ExerciseNewWeightChange) { - yield ExerciseNewLoading(); - customerRepository.setWeight(event.value); - changedWeight = true; - weight = event.value; - getBMI(); - getGoalBMI(); - getBMR(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewFitnessLevelChange) { - yield ExerciseNewLoading(); - customerRepository.setFitnessLevel(event.value); - fitnessLevel = event.value; - changedWeight = true; - getBMR(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewBirthyearChange) { - yield ExerciseNewLoading(); - changedWeight = true; - customerRepository.setBirthYear(event.value.toInt()); - birthYear = event.value; - getBMR(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewHeightChange) { - yield ExerciseNewLoading(); - customerRepository.setHeight(event.value.toInt()); - changedWeight = true; - height = event.value; - getBMI(); - getGoalBMI(); - getBMR(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewSaveWeight) { - yield ExerciseNewLoading(); - customerRepository.saveCustomer(); - changedWeight = false; - this.changedSizes = false; - Cache().initBadges(); - Track().track(TrackingEvent.sizes); - yield ExerciseNewReady(); - } else if (event is ExerciseNewSizeChange) { - yield ExerciseNewLoading(); - this.changedSizes = true; - this.customerRepository.updateSizes(event.propertyName, event.value); - customerRepository.setCustomerProperty(event.propertyName, event.value); - yield ExerciseNewReady(); - } else if (event is ExerciseNewSubmit) { - yield ExerciseNewLoading(); - if (quantity == -1 || unitQuantity == -1) { - yield ExerciseNewReady(); - throw Exception("Please type in a real number"); - } - - exerciseRepository.end = DateTime.now(); - await exerciseRepository.addExercise(); - if (!isInDebugMode) { - MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); - await mauticRepository.sendMauticExercise(); - } -// exerciseRepository.initExercise(); - menuBloc.add(MenuTreeDown(parent: 0)); - Cache().initBadges(); - Track().track(TrackingEvent.exercise_new, eventValue: exerciseRepository.exerciseType!.name); - yield ExerciseNewSaved(); - } else if (event is ExerciseNewSubmitNoRegistration) { - yield ExerciseNewLoading(); - exerciseRepository.addExerciseNoRegistration(); - menuBloc.add(MenuTreeDown(parent: 0)); - Track().track(TrackingEvent.exercise_new_no_registration, eventValue: exerciseRepository.exerciseType!.name); - yield ExerciseNewSaved(); - } else if (event is ExerciseNewBMIAnimate) { - yield ExerciseNewLoading(); - yield ExerciseNewReady(); - } else if (event is ExerciseNewAddError) { - yield ExerciseNewLoading(); - yield ExerciseNewError(message: event.message); - } - } on Exception catch (e) { - yield ExerciseNewError(message: e.toString()); - } - } - double getBMI() { if (weight == null || height == null || height == 0 || weight == 0) { this.bmi = 0; diff --git a/lib/bloc/exercise_plan/exercise_plan_bloc.dart b/lib/bloc/exercise_plan/exercise_plan_bloc.dart index 2a75e99..6b282d8 100644 --- a/lib/bloc/exercise_plan/exercise_plan_bloc.dart +++ b/lib/bloc/exercise_plan/exercise_plan_bloc.dart @@ -20,7 +20,72 @@ class ExercisePlanBloc extends Bloc { ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository(); late int customerId; - ExercisePlanBloc({required this.menuTreeRepository}) : super(ExercisePlanInitial()); + ExercisePlanBloc({required this.menuTreeRepository}) : super(ExercisePlanInitial()) { + on(_onLoad); + on(_onUpdateUI); + on(_onAddExercise); + on(_onRemoveExercise); + } + + void _onLoad(ExercisePlanLoad event, Emitter emit) async { + if (Cache().userLoggedIn == null || Cache().userLoggedIn!.customerId == null) { + throw Exception("Please log in"); + } + emit(ExercisePlanLoading()); + customerId = Cache().userLoggedIn!.customerId!; + await this.getData(); + Track().track(TrackingEvent.my_custom_exercise_plan); + emit(ExercisePlanReady()); + } + + void _onUpdateUI(ExercisePlanUpdateUI event, Emitter emit) { + emit(ExercisePlanLoading()); + WorkoutMenuTree workoutTree = event.workoutTree; + exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!); + workoutTree.selected = true; + emit(ExercisePlanReady()); + } + + void _onAddExercise(ExercisePlanAddExercise event, Emitter emit) async { + emit(ExercisePlanLoading()); + ExercisePlanDetail planDetail = event.exercisePlanDetail; + exercisePlanRepository.actualPlanDetail = planDetail; + + if (exercisePlanRepository.getExercisePlanDetailSize() != 0) { + await exercisePlanRepository.saveExercisePlan(); + } + + this.menuTreeRepository.sortedTree.forEach((key, value) { + List listTreeItem = value; + listTreeItem.forEach((element) { + if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) { + element.selected = true; + } + }); + }); + emit(ExercisePlanReady()); + } + + void _onRemoveExercise(ExercisePlanRemoveExercise event, Emitter emit) async { + emit(ExercisePlanLoading()); + ExercisePlanDetail planDetail = event.exercisePlanDetail; + exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId); + + this.menuTreeRepository.sortedTree.forEach((key, value) { + List listTreeItem = value; + listTreeItem.forEach((element) { + if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) { + element.selected = false; + } + }); + }); + + if (exercisePlanRepository.getExercisePlanDetailSize() != 0) { + await exercisePlanRepository.saveExercisePlan(); + Track().track(TrackingEvent.my_custom_exercise_plan_save); + } + emit(ExercisePlanReady()); + } Future getData() async { exercisePlanRepository.setCustomerId(customerId); @@ -45,71 +110,4 @@ class ExercisePlanBloc extends Bloc { } void setExercisePlanRepository(ExercisePlanRepository repo) => exercisePlanRepository = repo; - - @override - Stream mapEventToState(ExercisePlanEvent event) async* { - try { - if (event is ExercisePlanLoad) { - if (Cache().userLoggedIn == null || Cache().userLoggedIn!.customerId == null) { - throw Exception("Please log in"); - } - yield ExercisePlanLoading(); - customerId = Cache().userLoggedIn!.customerId!; - await this.getData(); - Track().track(TrackingEvent.my_custom_exercise_plan); - yield ExercisePlanReady(); - } - - if (event is ExercisePlanUpdateUI) { - yield ExercisePlanLoading(); - - WorkoutMenuTree workoutTree = event.workoutTree; - exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!); - workoutTree.selected = true; - - yield ExercisePlanReady(); - } else if (event is ExercisePlanAddExercise) { - yield ExercisePlanLoading(); - ExercisePlanDetail planDetail = event.exercisePlanDetail; - exercisePlanRepository.actualPlanDetail = planDetail; - - if (exercisePlanRepository.getExercisePlanDetailSize() != 0) { - await exercisePlanRepository.saveExercisePlan(); - } - - this.menuTreeRepository.sortedTree.forEach((key, value) { - List listTreeItem = value; - listTreeItem.forEach((element) { - if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) { - element.selected = true; - } - }); - }); - - yield ExercisePlanReady(); - } else if (event is ExercisePlanRemoveExercise) { - yield ExercisePlanLoading(); - ExercisePlanDetail planDetail = event.exercisePlanDetail; - exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId); - - this.menuTreeRepository.sortedTree.forEach((key, value) { - List listTreeItem = value; - listTreeItem.forEach((element) { - if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) { - element.selected = false; - } - }); - }); - - if (exercisePlanRepository.getExercisePlanDetailSize() != 0) { - exercisePlanRepository.saveExercisePlan(); - Track().track(TrackingEvent.my_custom_exercise_plan_save); - } - - yield ExercisePlanReady(); - } - } on Exception catch (e) { - yield ExercisePlanError(message: e.toString()); - } - } } diff --git a/lib/bloc/exercise_plan_custom_add/exercise_plan_custom_add_bloc.dart b/lib/bloc/exercise_plan_custom_add/exercise_plan_custom_add_bloc.dart index 87683cd..7949059 100644 --- a/lib/bloc/exercise_plan_custom_add/exercise_plan_custom_add_bloc.dart +++ b/lib/bloc/exercise_plan_custom_add/exercise_plan_custom_add_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart'; import 'package:aitrainer_app/repository/exercise_plan_repository.dart'; @@ -7,7 +6,6 @@ import 'package:equatable/equatable.dart'; import 'package:meta/meta.dart'; part 'exercise_plan_custom_add_event.dart'; - part 'exercise_plan_custom_add_state.dart'; class ExercisePlanDetailChange { @@ -29,16 +27,18 @@ class ExercisePlanCustomAddBloc extends Bloc(_onLoad); + on(_onChangeSerie); + on(_onChangeQuantity); + on(_onChangeQuantityUnit); + on(_onSubmit); + on(_onRemove); } void init() { exercisePlanRepository.setActualPlanDetailByExerciseType(workoutMenuTree.exerciseType!); - quantity = exercisePlanRepository.getActualPlanDetail()!.repeats != null - ? exercisePlanRepository.getActualPlanDetail()!.repeats!.toDouble() - : 12; - serie = - exercisePlanRepository.getActualPlanDetail()!.serie != null ? exercisePlanRepository.getActualPlanDetail()!.serie!.toDouble() : 3; + quantity = exercisePlanRepository.getActualPlanDetail()!.repeats != null ? exercisePlanRepository.getActualPlanDetail()!.repeats!.toDouble() : 12; + serie = exercisePlanRepository.getActualPlanDetail()!.serie != null ? exercisePlanRepository.getActualPlanDetail()!.serie!.toDouble() : 3; quantityUnit = exercisePlanRepository.getActualPlanDetail()!.weightEquation != null ? double.parse(exercisePlanRepository.getActualPlanDetail()!.weightEquation!) : 30; @@ -48,47 +48,49 @@ class ExercisePlanCustomAddBloc extends Bloc mapEventToState(ExercisePlanCustomAddEvent event) async* { - try { - if (event is ExercisePlanCustomAddLoad) { - yield ExercisePlanCustomAddLoading(); - init(); - yield ExercisePlanCustomAddReady(); - } else if (event is ExercisePlanCustomAddChangeSerie) { - yield ExercisePlanCustomAddLoading(); - serie = event.quantity; - exercisePlanRepository.getActualPlanDetail()!.serie = event.quantity.toInt(); - yield ExercisePlanCustomAddReady(); - } else if (event is ExercisePlanCustomAddChangeQuantity) { - yield ExercisePlanCustomAddLoading(); - quantity = event.quantity; - exercisePlanRepository.getActualPlanDetail()!.repeats = event.quantity.toInt(); - yield ExercisePlanCustomAddReady(); - } else if (event is ExercisePlanCustomAddChangeQuantityUnit) { - yield ExercisePlanCustomAddLoading(); - quantityUnit = event.quantity; - exercisePlanRepository.getActualPlanDetail()!.weightEquation = event.quantity.toStringAsFixed(0); - yield ExercisePlanCustomAddReady(); - } else if (event is ExercisePlanCustomAddSubmit) { - yield ExercisePlanCustomAddLoading(); - if (exercisePlanRepository.exercisePlanDetails[exercisePlanRepository.getActualPlanDetail()] == null) { - exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.add; - } else { - exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.update; - } - exercisePlanRepository.addDetailToPlan(); - planBloc.add(ExercisePlanAddExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()!)); - yield ExercisePlanCustomAddReady(); - } else if (event is ExercisePlanCustomAddRemove) { - yield ExercisePlanCustomAddLoading(); - exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.delete; - planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()!)); + void _onLoad(ExercisePlanCustomAddLoad event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + init(); + emit(ExercisePlanCustomAddReady()); + } - yield ExercisePlanCustomAddReady(); - } - } on Exception catch (e) { - yield ExercisePlanCustomAddError(message: e.toString()); + void _onChangeSerie(ExercisePlanCustomAddChangeSerie event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + serie = event.quantity; + exercisePlanRepository.getActualPlanDetail()!.serie = event.quantity.toInt(); + emit(ExercisePlanCustomAddReady()); + } + + void _onChangeQuantity(ExercisePlanCustomAddChangeQuantity event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + quantity = event.quantity; + exercisePlanRepository.getActualPlanDetail()!.repeats = event.quantity.toInt(); + emit(ExercisePlanCustomAddReady()); + } + + void _onChangeQuantityUnit(ExercisePlanCustomAddChangeQuantityUnit event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + quantityUnit = event.quantity; + exercisePlanRepository.getActualPlanDetail()!.weightEquation = event.quantity.toStringAsFixed(0); + emit(ExercisePlanCustomAddReady()); + } + + void _onSubmit(ExercisePlanCustomAddSubmit event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + if (exercisePlanRepository.exercisePlanDetails[exercisePlanRepository.getActualPlanDetail()] == null) { + exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.add; + } else { + exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.update; } + exercisePlanRepository.addDetailToPlan(); + planBloc.add(ExercisePlanAddExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()!)); + emit(ExercisePlanCustomAddReady()); + } + + void _onRemove(ExercisePlanCustomAddRemove event, Emitter emit) { + emit(ExercisePlanCustomAddLoading()); + exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.delete; + planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()!)); + emit(ExercisePlanCustomAddReady()); } } diff --git a/lib/bloc/faq/faq_bloc.dart b/lib/bloc/faq/faq_bloc.dart index 8cc7c3f..498a6d2 100644 --- a/lib/bloc/faq/faq_bloc.dart +++ b/lib/bloc/faq/faq_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/faq.dart'; import 'package:bloc/bloc.dart'; @@ -12,22 +10,17 @@ class FaqBloc extends Bloc { List? faqs; FaqBloc() : super(FaqInitial()) { faqs = Cache().getFaqs(); + on(_onLoad); + on(_onClick); } - @override - Stream mapEventToState( - FaqEvent event, - ) async* { - try { - if (event is FaqLoad) { - yield FaqLoading(); - yield FaqReady(); - } else if (event is FaqClickDetail) { - yield FaqLoading(); - yield FaqReady(); - } - } on Exception catch (e) { - yield FaqError(message: e.toString()); - } + void _onLoad(FaqLoad event, Emitter emit) { + emit(FaqLoading()); + emit(FaqReady()); + } + + void _onClick(FaqClickDetail event, Emitter emit) { + emit(FaqLoading()); + emit(FaqReady()); } } diff --git a/lib/bloc/login/login_bloc.dart b/lib/bloc/login/login_bloc.dart index fb99baf..1738b0e 100644 --- a/lib/bloc/login/login_bloc.dart +++ b/lib/bloc/login/login_bloc.dart @@ -34,13 +34,26 @@ class LoginBloc extends Bloc with Trans { Color testColor = Colors.green[800]!; bool emailCheckbox = true; - LoginBloc( - {required this.accountBloc, - required this.userRepository, - required this.context, - required this.isRegistration, - this.customerRepository}) + LoginBloc({required this.accountBloc, required this.userRepository, required this.context, required this.isRegistration, this.customerRepository}) : super(LoginInitial()) { + this._init(); + on(_onEmailChange); + on(_onPasswordChange); + on(_onSubmit); + on(_onLoginFB); + on(_onLoginGoogle); + on(_onLoginApple); + on(_onRegistrationSubmit); + on(_onRegistrationFB); + on(_onRegistrationGoogle); + on(_onRegistrationApple); + on(_onDataProtectionClicked); + on(_onEmailSubscriptionClicked); + on(_onPasswordChangeObscure); + on(_onLoginSkip); + } + + void _init() { String colorString = splitTestRepository.getSplitTestValue("registration_skip"); if (colorString == "red") { testColor = Colors.red[800]!; @@ -54,112 +67,126 @@ class LoginBloc extends Bloc with Trans { } } - @override - Stream mapEventToState( - LoginEvent event, - ) async* { - try { - if (event is LoginEmailChange) { - yield LoginLoading(); - final String email = event.email; - userRepository.setEmail(email); - yield LoginReady(); - } else if (event is LoginPasswordChange) { - yield LoginLoading(); - final String password = event.password; - userRepository.setPassword(password); - yield LoginReady(); - } else if (event is LoginSubmit) { - yield LoginLoading(); - await userRepository.getUser(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - Track().track(TrackingEvent.login, eventValue: "email"); - Cache().setLoginType(LoginType.email); - yield LoginSuccess(); - } else if (event is LoginFB) { - yield LoginLoading(); - Cache().setLoginType(LoginType.fb); - await userRepository.getUserByFB(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - 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!)); - 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!)); - Track().track(TrackingEvent.login, eventValue: "Apple"); - yield LoginSuccess(); - } else if (event is RegistrationSubmit) { - yield LoginLoading(); + void _onEmailChange(LoginEmailChange event, Emitter emit) { + emit(LoginLoading()); + final String email = event.email; + userRepository.setEmail(email); + emit(LoginReady()); + } - final String? validationError = validate(); - if (validationError != null) { - yield LoginError(message: validationError); - } else { - await userRepository.addUser(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; - await afterRegistration("email"); - Cache().setLoginType(LoginType.email); - yield LoginSuccess(); - } - } else if (event is RegistrationFB) { - yield LoginLoading(); + void _onPasswordChange(LoginPasswordChange event, Emitter emit) { + emit(LoginLoading()); + final String password = event.password; + userRepository.setPassword(password); + emit(LoginReady()); + } - Cache().setLoginType(LoginType.fb); - await userRepository.addUserFB(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; - await afterRegistration("FB"); - yield LoginSuccess(); - } else if (event is RegistrationGoogle) { - yield LoginLoading(); + void _onSubmit(LoginSubmit event, Emitter emit) async { + emit(LoginLoading()); + await userRepository.getUser(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + Track().track(TrackingEvent.login, eventValue: "email"); + Cache().setLoginType(LoginType.email); - Cache().setLoginType(LoginType.google); - await userRepository.addUserGoogle(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; - await afterRegistration("Google"); - yield LoginSuccess(); - } else if (event is RegistrationApple) { - yield LoginLoading(); + emit(LoginReady()); + } - Cache().setLoginType(LoginType.apple); - await userRepository.addUserApple(); - accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); - customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; - await afterRegistration("Apple"); + void _onLoginFB(LoginFB event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.fb); + await userRepository.getUserByFB(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + Track().track(TrackingEvent.login, eventValue: "FB"); + emit(LoginReady()); + } - yield LoginSuccess(); - } else if (event is DataProtectionClicked) { - yield LoginLoading(); - this.dataPolicyAllowed = !dataPolicyAllowed; - yield LoginReady(); - } else if (event is EmailSubscriptionClicked) { - yield LoginLoading(); - this.emailSubscription = !emailSubscription; - yield LoginReady(); - } else if (event is LoginPasswordChangeObscure) { - yield LoginLoading(); - this.obscure = !this.obscure; - yield LoginReady(); - } else if (event is LoginSkip) { - yield LoginLoading(); - Track().track(TrackingEvent.login_skip); - Cache().startPage = "home"; - yield LoginSkipped(); - } - } on Exception catch (e) { - yield LoginError(message: e.toString()); + void _onLoginGoogle(LoginGoogle event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.google); + await userRepository.getUserByGoogle(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + Track().track(TrackingEvent.login, eventValue: "Google"); + + emit(LoginSuccess()); + } + + void _onLoginApple(LoginApple event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.apple); + await userRepository.getUserByApple(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + Track().track(TrackingEvent.login, eventValue: "Apple"); + emit(LoginSuccess()); + } + + void _onRegistrationSubmit(RegistrationSubmit event, Emitter emit) async { + emit(LoginLoading()); + final String? validationError = this.validate(); + if (validationError != null) { + emit(LoginError(message: validationError)); + } else { + await userRepository.addUser(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; + await afterRegistration("email"); + Cache().setLoginType(LoginType.email); } + emit(LoginSuccess()); + } + + void _onRegistrationFB(RegistrationFB event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.fb); + await userRepository.addUserFB(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; + await afterRegistration("FB"); + emit(LoginSuccess()); + } + + void _onRegistrationGoogle(RegistrationGoogle event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.google); + await userRepository.addUserGoogle(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; + await afterRegistration("Google"); + emit(LoginSuccess()); + } + + void _onRegistrationApple(RegistrationApple event, Emitter emit) async { + emit(LoginLoading()); + Cache().setLoginType(LoginType.apple); + await userRepository.addUserApple(); + accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!)); + customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0; + await afterRegistration("Apple"); + emit(LoginSuccess()); + } + + void _onDataProtectionClicked(DataProtectionClicked event, Emitter emit) async { + emit(LoginLoading()); + this.dataPolicyAllowed = !dataPolicyAllowed; + emit(LoginReady()); + } + + void _onEmailSubscriptionClicked(EmailSubscriptionClicked event, Emitter emit) async { + emit(LoginLoading()); + this.emailSubscription = !emailSubscription; + emit(LoginReady()); + } + + void _onPasswordChangeObscure(LoginPasswordChangeObscure event, Emitter emit) async { + emit(LoginLoading()); + this.obscure = !this.obscure; + emit(LoginReady()); + } + + void _onLoginSkip(LoginSkip event, Emitter emit) async { + emit(LoginLoading()); + Track().track(TrackingEvent.login_skip); + Cache().startPage = "home"; + emit(LoginSkipped()); } Future afterRegistration(String event) async { diff --git a/lib/bloc/menu/menu_bloc.dart b/lib/bloc/menu/menu_bloc.dart index bff726f..ba4f2d9 100644 --- a/lib/bloc/menu/menu_bloc.dart +++ b/lib/bloc/menu/menu_bloc.dart @@ -1,19 +1,12 @@ import 'dart:async'; import 'dart:collection'; -import 'package:aitrainer_app/repository/mautic_repository.dart'; -import 'package:intl/intl.dart'; - -import 'package:aitrainer_app/main.dart'; import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/exercise_ability.dart'; import 'package:aitrainer_app/model/workout_menu_tree.dart'; -import 'package:aitrainer_app/repository/customer_repository.dart'; import 'package:aitrainer_app/repository/exercise_device_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/repository/workout_tree_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:aitrainer_app/util/trans.dart'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; @@ -40,13 +33,87 @@ class MenuBloc extends Bloc with Trans, Logging { MenuBloc({required this.menuTreeRepository}) : super(MenuInitial()) { parent = 0; + on(_onCreate); + on(_onRecreateTree); + on(_onTreeDown); + on(_onTreeUp); + on(_onTreeJump); + on(_onFilterExercise); + } + + void _onCreate(MenuCreate event, Emitter emit) { + emit(MenuLoading()); + if (Cache().getDevices() != null) { + exerciseDeviceRepository.setDevices(Cache().getDevices()!); + } + emit(MenuReady()); + } + + void _onRecreateTree(MenuRecreateTree event, Emitter emit) { + emit(MenuLoading()); + // ie. at language changes + menuTreeRepository.createTree(); + emit(MenuReady()); + } + + Future _onTreeDown(MenuTreeDown event, Emitter emit) async { + emit(MenuLoading()); + parent = event.parent; + workoutItem = event.item; + + if (workoutItem != null) { + setAbility(workoutItem!.internalName); + } + final LinkedHashMap branch = menuTreeRepository.getBranch(event.parent); + + await getImages(branch); + emit(MenuReady()); + } + + Future _onTreeUp(MenuTreeUp event, Emitter emit) async { + emit(MenuLoading()); + // get parent menus or exercises + parent = event.parent; + workoutItem = menuTreeRepository.getParentItem(parent); + + LinkedHashMap branch; + if (workoutItem != null) { + setAbility(workoutItem!.internalName); + branch = menuTreeRepository.getBranch(workoutItem!.parent); + await getImages(branch); + } + emit(MenuReady()); + } + + Future _onTreeJump(MenuTreeJump event, Emitter emit) async { + emit(MenuLoading()); + parent = event.parent; + workoutItem = menuTreeRepository.getParentItem(parent); + + if (workoutItem != null) { + setAbility(workoutItem!.internalName); + } + final LinkedHashMap branch = menuTreeRepository.getBranch(workoutItem!.parent); + await getImages(branch); + emit(MenuReady()); + } + + Future _onFilterExercise(MenuFilterExerciseType event, Emitter emit) async { + emit(MenuLoading()); + final int deviceId = event.deviceId; + if (selectedDevice(deviceId)) { + listFilterDevice.add(deviceId); + } else { + listFilterDevice.remove(deviceId); + } + emit(MenuReady()); } void setContext(BuildContext context) { this.context = context; } - @override + /* @override Stream mapEventToState( MenuEvent event, ) async* { @@ -141,7 +208,7 @@ class MenuBloc extends Bloc with Trans, Logging { } on Exception catch (ex) { yield MenuError(message: ex.toString()); } - } + } */ void setAbility(String name) { switch (name) { diff --git a/lib/bloc/menu/menu_event.dart b/lib/bloc/menu/menu_event.dart index 9516ba0..26d9e9c 100644 --- a/lib/bloc/menu/menu_event.dart +++ b/lib/bloc/menu/menu_event.dart @@ -41,14 +41,6 @@ class MenuTreeJump extends MenuEvent { List get props => [parent]; } -class MenuClickExercise extends MenuEvent { - final int exerciseTypeId; - const MenuClickExercise({required this.exerciseTypeId}); - - @override - List get props => [exerciseTypeId]; -} - class MenuRecreateTree extends MenuEvent { const MenuRecreateTree(); } @@ -60,11 +52,3 @@ class MenuFilterExerciseType extends MenuEvent { @override List get props => [deviceId]; } - -class MenuStartTrial extends MenuEvent { - final DateTime start; - const MenuStartTrial({required this.start}); - - @override - List get props => [start]; -} diff --git a/lib/bloc/password_reset/password_reset_bloc.dart b/lib/bloc/password_reset/password_reset_bloc.dart index 3af2af6..f8dd76a 100644 --- a/lib/bloc/password_reset/password_reset_bloc.dart +++ b/lib/bloc/password_reset/password_reset_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:aitrainer_app/repository/user_repository.dart'; import 'package:aitrainer_app/util/common.dart'; import 'package:bloc/bloc.dart'; @@ -10,26 +8,22 @@ part 'password_reset_state.dart'; class PasswordResetBloc extends Bloc { final UserRepository userRepository; - PasswordResetBloc({required this.userRepository}) : super(PasswordResetInitial()); + PasswordResetBloc({required this.userRepository}) : super(PasswordResetInitial()) { + on(_onEmailChange); + on(_onSubmit); + } - @override - Stream mapEventToState( - PasswordResetEvent event, - ) async* { - try { - if (event is PasswordResetEmailChange) { - yield PasswordResetLoading(); - final String email = event.email; - userRepository.setEmail(email); - yield PasswordResetReady(); - } else if (event is PasswordResetSubmit) { - yield PasswordResetLoading(); - await userRepository.resetPassword(); - yield PasswordResetFinished(); - } - } on Exception catch (e) { - yield PasswordResetError(message: e.toString()); - } + void _onEmailChange(PasswordResetEmailChange event, Emitter emit) { + emit(PasswordResetLoading()); + final String email = event.email; + userRepository.setEmail(email); + emit(PasswordResetReady()); + } + + void _onSubmit(PasswordResetSubmit event, Emitter emit) async { + emit(PasswordResetLoading()); + await userRepository.resetPassword(); + emit(PasswordResetReady()); } String? emailValidation(String email) { diff --git a/lib/bloc/result/result_bloc.dart b/lib/bloc/result/result_bloc.dart index 4d46856..f97979c 100644 --- a/lib/bloc/result/result_bloc.dart +++ b/lib/bloc/result/result_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:aitrainer_app/model/result.dart'; import 'package:aitrainer_app/repository/evaluation_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; @@ -37,6 +35,11 @@ class ResultBloc extends Bloc with Logging, Trans { ]; */ ResultBloc({required this.resultRepository, required this.exerciseRepository, required this.context}) : super(ResultInitial()) { + this._load(); + on(_onLoad); + } + + void _load() { this.startTime = exerciseRepository.start; this.endTime = exerciseRepository.end; if (this.startTime == null) { @@ -45,22 +48,10 @@ class ResultBloc extends Bloc with Logging, Trans { } } - @override - Stream mapEventToState( - ResultEvent event, - ) async* { - try { - if (event is ResultLoad) { - yield ResultLoading(); - - //await _fetchHealthData(); - _matchExerciseData(); - //await resultRepository.saveExerciseResults(); - yield ResultReady(); - } - } on Exception catch (ex) { - yield ResultError(error: ex.toString()); - } + void _onLoad(ResultLoad event, Emitter emit) { + emit(ResultLoading()); + _matchExerciseData(); + emit(ResultReady()); } void _matchExerciseData() { diff --git a/lib/bloc/sales/sales_bloc.dart b/lib/bloc/sales/sales_bloc.dart index dc4b41a..2044e67 100644 --- a/lib/bloc/sales/sales_bloc.dart +++ b/lib/bloc/sales/sales_bloc.dart @@ -27,12 +27,51 @@ class SalesBloc extends Bloc with Logging { int productSet = -1; final DescriptionRepository descriptionRepository = DescriptionRepository(); - SalesBloc() : super(SalesInitial()); + SalesBloc() : super(SalesInitial()) { + on(_onLoad); + on(_onPurchase); + } String? salesText; String? premiumFunctions = ""; String? trial = ""; + void _onLoad(SalesLoad event, Emitter emit) async { + emit(SalesLoading()); + await init(); + emit(SalesReady()); + } + + void _onPurchase(SalesPurchase event, Emitter emit) async { + if (Cache().hasPurchased) { + throw Exception("You have already a successfull subscription"); + } + emit(SalesLoading()); + final int productId = event.productId; + log("Requesting purchase for: " + productId.toString()); + Track().track(TrackingEvent.purchase_request); + final Product? selectedProduct = this.getSelectedProduct(productId); + log("SelectedProduct for purchase $selectedProduct"); + if (selectedProduct != null) { + await RevenueCatPurchases().makePurchase(selectedProduct); + if (Cache().hasPurchased) { + Purchase purchase = Purchase(customerId: Cache().userLoggedIn!.customerId!, productId: productId); + purchase.dateAdd = DateTime.now(); + purchase.purchaseSum = 0; + purchase.currency = "EUR"; + await PurchaseApi().savePurchase(purchase); + Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString()); + CustomerRepository customerRepository = CustomerRepository(); + customerRepository.customer = Cache().userLoggedIn; + MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); + await mauticRepository.sendMauticPurchase(); + } + emit(SalesSuccessful()); + } else { + emit(SalesError(message: "No selected product")); + } + } + Future init() async { if (Cache().userLoggedIn == null) { throw Exception("Please log in"); @@ -60,51 +99,6 @@ class SalesBloc extends Bloc with Logging { Track().track(TrackingEvent.sales_page); } - @override - Stream mapEventToState( - SalesEvent event, - ) async* { - try { - if (event is SalesLoad) { - log(" -- start SalesLoad"); - yield SalesLoading(); - await init(); - yield SalesReady(); - log(" -- finish SalesLoad"); - } else if (event is SalesPurchase) { - if (Cache().hasPurchased) { - throw Exception("You have already a successfull subscription"); - } - yield SalesLoading(); - final int productId = event.productId; - log("Requesting purchase for: " + productId.toString()); - Track().track(TrackingEvent.purchase_request); - final Product? selectedProduct = this.getSelectedProduct(productId); - log("SelectedProduct for purchase $selectedProduct"); - if (selectedProduct != null) { - await RevenueCatPurchases().makePurchase(selectedProduct); - if (Cache().hasPurchased) { - Purchase purchase = Purchase(customerId: Cache().userLoggedIn!.customerId!, productId: productId); - purchase.dateAdd = DateTime.now(); - purchase.purchaseSum = 0; - purchase.currency = "EUR"; - await PurchaseApi().savePurchase(purchase); - Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString()); - CustomerRepository customerRepository = CustomerRepository(); - customerRepository.customer = Cache().userLoggedIn; - MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); - await mauticRepository.sendMauticPurchase(); - } - yield SalesSuccessful(); - } else { - yield SalesError(message: "No selected product"); - } - } - } on Exception catch (ex) { - yield SalesError(message: ex.toString()); - } - } - void getProductsTexts() { Product product; if (product2Display.isNotEmpty) { diff --git a/lib/bloc/session/session_bloc.dart b/lib/bloc/session/session_bloc.dart index 47a4ce1..12bc495 100644 --- a/lib/bloc/session/session_bloc.dart +++ b/lib/bloc/session/session_bloc.dart @@ -14,35 +14,30 @@ part 'session_state.dart'; class SessionBloc extends Bloc with Logging { final Session session; StreamSubscription? _sub; + SettingsBloc? settingsBloc; - SessionBloc({required this.session}) : super(SessionInitial()); + SessionBloc({required this.session}) : super(SessionInitial()) { + on(_onStart); + } - @override - Stream mapEventToState( - SessionEvent event, - ) async* { - try { - if (event is SessionStart) { - log(" -------- Session starting..."); - yield SessionLoading(); - // ignore: close_sinks - SettingsBloc settingsBloc = event.settingsBloc; - await session.fetchSessionAndNavigate(); - FirebaseApi().setupRemoteConfig(); - String lang = AppLanguage().appLocal.languageCode; - log("Change lang to $lang"); - settingsBloc.add(SettingsChangeLanguage(language: lang)); - yield SessionReady(); - } - } on Exception catch (ex) { - yield SessionFailure(message: ex.toString()); - } + void _onStart(SessionStart event, Emitter emit) async { + log(" -------- Session starting..."); + emit(SessionLoading()); + + this.settingsBloc = event.settingsBloc; + await session.fetchSessionAndNavigate(); + FirebaseApi().setupRemoteConfig(); + String lang = AppLanguage().appLocal.languageCode; + log("Change lang to $lang"); + settingsBloc!.add(SettingsChangeLanguage(language: lang)); + emit(SessionReady()); } @override Future close() async { await this.close(); _sub?.cancel(); + settingsBloc?.close(); super.close(); } } diff --git a/lib/bloc/test_set_control/test_set_control_bloc.dart b/lib/bloc/test_set_control/test_set_control_bloc.dart index c888bdf..6b261f6 100644 --- a/lib/bloc/test_set_control/test_set_control_bloc.dart +++ b/lib/bloc/test_set_control/test_set_control_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:aitrainer_app/bloc/test_set_execute/test_set_execute_bloc.dart'; import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/exercise.dart'; @@ -25,9 +23,11 @@ class TestSetControlBloc extends Bloc late double oneRepMax; late int step; - TestSetControlBloc({required this.exercisePlanDetail, required this.executeBloc, required this.exerciseType}) - : super(TestSetControlInitial()) { + TestSetControlBloc({required this.exercisePlanDetail, required this.executeBloc, required this.exerciseType}) : super(TestSetControlInitial()) { initBloc(); + on(_onQuantityChange); + on(_onUnitQuantityChange); + on(_onSubmit); } void initBloc() { @@ -42,29 +42,29 @@ class TestSetControlBloc extends Bloc exerciseRepository.exerciseType = exerciseType; } - @override - Stream mapEventToState( - TestSetControlEvent event, - ) async* { - try { - if (event is TestSetControlQuantityChange) { - quantity = event.quantity; - } else if (event is TestSetControlUnitQuantityChange) { - unitQuantity = event.quantity; - } else if (event is TestSetControlSubmit) { - final Exercise exercise = Exercise(); - exercise.quantity = quantity; - exercise.unit = exerciseType.unit; - exercise.unitQuantity = unitQuantity; - exercise.dateAdd = DateTime.now(); - exerciseRepository.exercise = exercise; + void _onQuantityChange(TestSetControlQuantityChange event, Emitter emit) { + emit(TestSetControlLoading()); + quantity = event.quantity; + emit(TestSetControlReady()); + } - await exerciseRepository.addExercise(); - executeBloc.add( - TestSetExecuteExerciseFinished(exerciseTypeId: exerciseType.exerciseTypeId, quantity: quantity, unitQuantity: unitQuantity)); - } - } on Exception catch (e) { - yield TestSetControlError(message: e.toString()); - } + void _onUnitQuantityChange(TestSetControlUnitQuantityChange event, Emitter emit) { + emit(TestSetControlLoading()); + unitQuantity = event.quantity; + emit(TestSetControlReady()); + } + + void _onSubmit(TestSetControlSubmit event, Emitter emit) async { + emit(TestSetControlLoading()); + final Exercise exercise = Exercise(); + exercise.quantity = quantity; + exercise.unit = exerciseType.unit; + exercise.unitQuantity = unitQuantity; + exercise.dateAdd = DateTime.now(); + exerciseRepository.exercise = exercise; + + await exerciseRepository.addExercise(); + executeBloc.add(TestSetExecuteExerciseFinished(exerciseTypeId: exerciseType.exerciseTypeId, quantity: quantity, unitQuantity: unitQuantity)); + emit(TestSetControlReady()); } } diff --git a/lib/bloc/test_set_edit/test_set_edit_bloc.dart b/lib/bloc/test_set_edit/test_set_edit_bloc.dart index f74ee6c..7ae11a8 100644 --- a/lib/bloc/test_set_edit/test_set_edit_bloc.dart +++ b/lib/bloc/test_set_edit/test_set_edit_bloc.dart @@ -1,6 +1,4 @@ -import 'dart:async'; import 'dart:collection'; - import 'package:aitrainer_app/bloc/menu/menu_bloc.dart'; import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/exercise_ability.dart'; @@ -32,9 +30,16 @@ class TestSetEditBloc extends Bloc { final HashMap?> _displayPlanDetails = HashMap(); int? sliderIndex; - TestSetEditBloc( - {required this.templateName, required this.templateNameTranslation, required this.workoutTreeRepository, required this.menuBloc}) + TestSetEditBloc({required this.templateName, required this.templateNameTranslation, required this.workoutTreeRepository, required this.menuBloc}) : super(TestSetEditInitial()) { + this._init(); + on(_onChangeExerciseType); + on(_onDeleteExerciseType); + on(_onAddExerciseType); + on(_onSubmit); + } + + void _init() { if (Cache().exercisePlanTemplates.isNotEmpty) { Cache().exercisePlanTemplates.forEach((element) { final ExercisePlanTemplate template = element as ExercisePlanTemplate; @@ -65,60 +70,56 @@ class TestSetEditBloc extends Bloc { } } - @override - Stream mapEventToState(TestSetEditEvent event) async* { - try { - if (event is TestSetEditChangeExerciseType) { - yield TestSetEditLoading(); - ExerciseType? exerciseType; - if (_exercisePlanDetails[event.indexKey] == null) { - exerciseType = displayPlanDetails[event.indexKey][0]; - } else { - exerciseType = displayPlanDetails[event.indexKey][event.index]; - } - _exercisePlanDetails[event.indexKey] = exerciseType; - this.sliderIndex = event.index; - yield TestSetEditReady(); - } else if (event is TestSetEditDeleteExerciseType) { - yield TestSetEditLoading(); - _exercisePlanDetails[event.indexKey] = null; - - yield TestSetEditReady(); - } else if (event is TestSetEditAddExerciseType) { - yield TestSetEditLoading(); - ExerciseType exerciseType = displayPlanDetails[event.indexKey][0]; - _exercisePlanDetails[event.indexKey] = exerciseType; - yield TestSetEditReady(); - } else if (event is TestSetEditSubmit) { - yield TestSetEditLoading(); - ExercisePlan exercisePlan = ExercisePlan(templateNameTranslation, Cache().userLoggedIn!.customerId!); - exercisePlan.private = true; - exercisePlan.type = ExerciseAbility.mini_test_set.enumToString(); - exercisePlan.dateAdd = DateTime.now(); - ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan); - - List details = []; - for (var entry in _exercisePlanDetails.entries) { - if (entry.value != null) { - ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(entry.value!.exerciseTypeId); - exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId!; - exercisePlanDetail.serie = 1; - - ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail); - exercisePlanDetail.exercisePlanDetailId = savedDetail.exercisePlanDetailId; - exercisePlanDetail.exercises = []; - details.add(exercisePlanDetail); - } - } - Cache().saveActiveExercisePlan(exercisePlan, details); - Track().track(TrackingEvent.test_set_edit, eventValue: templateName); - yield TestSetEditSaved(); - } else if (event is TestSetEditAddError) { - yield TestSetEditError(message: event.message); - } - } on Exception catch (e) { - yield TestSetEditError(message: e.toString()); + void _onChangeExerciseType(TestSetEditChangeExerciseType event, Emitter emit) { + emit(TestSetEditLoading()); + ExerciseType? exerciseType; + if (_exercisePlanDetails[event.indexKey] == null) { + exerciseType = displayPlanDetails[event.indexKey][0]; + } else { + exerciseType = displayPlanDetails[event.indexKey][event.index]; } + _exercisePlanDetails[event.indexKey] = exerciseType; + this.sliderIndex = event.index; + emit(TestSetEditReady()); + } + + void _onDeleteExerciseType(TestSetEditDeleteExerciseType event, Emitter emit) { + emit(TestSetEditLoading()); + _exercisePlanDetails[event.indexKey] = null; + emit(TestSetEditReady()); + } + + void _onAddExerciseType(TestSetEditAddExerciseType event, Emitter emit) { + emit(TestSetEditLoading()); + ExerciseType exerciseType = displayPlanDetails[event.indexKey][0]; + _exercisePlanDetails[event.indexKey] = exerciseType; + emit(TestSetEditReady()); + } + + void _onSubmit(TestSetEditSubmit event, Emitter emit) async { + emit(TestSetEditLoading()); + ExercisePlan exercisePlan = ExercisePlan(templateNameTranslation, Cache().userLoggedIn!.customerId!); + exercisePlan.private = true; + exercisePlan.type = ExerciseAbility.mini_test_set.enumToString(); + exercisePlan.dateAdd = DateTime.now(); + ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan); + + List details = []; + for (var entry in _exercisePlanDetails.entries) { + if (entry.value != null) { + ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(entry.value!.exerciseTypeId); + exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId!; + exercisePlanDetail.serie = 1; + + ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail); + exercisePlanDetail.exercisePlanDetailId = savedDetail.exercisePlanDetailId; + exercisePlanDetail.exercises = []; + details.add(exercisePlanDetail); + } + } + Cache().saveActiveExercisePlan(exercisePlan, details); + Track().track(TrackingEvent.test_set_edit, eventValue: templateName); + emit(TestSetEditSaved()); } List get exerciseTypes => this._exerciseTypes; diff --git a/lib/bloc/test_set_execute/test_set_execute_bloc.dart b/lib/bloc/test_set_execute/test_set_execute_bloc.dart index ca6c6cd..6a251cb 100644 --- a/lib/bloc/test_set_execute/test_set_execute_bloc.dart +++ b/lib/bloc/test_set_execute/test_set_execute_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:collection'; import 'package:aitrainer_app/bloc/menu/menu_bloc.dart'; @@ -30,7 +29,153 @@ class TestSetExecuteBloc extends Bloc List? exercisePlanDetails; - TestSetExecuteBloc() : super(TestSetExecuteInitial()); + TestSetExecuteBloc() : super(TestSetExecuteInitial()) { + on(_onLoad); + on(_onDeleteActive); + on(_onDeleteAllActive); + on(_onExerciseFinished); + on(_onNewExercise); + on(_onDeleteExercise); + on(_onFinish); + } + + void _onLoad(TestSetExecuteLoad event, Emitter emit) { + emit(TestSetExecuteLoading()); + initExercisePlan(); + if (exerciseTypeId != null) { + int step = 0; + if (exercisePlanDetails != null) { + exercisePlanDetails!.forEach((element) { + if (element.exerciseTypeId == this.exerciseTypeId) { + scrollOffset = (step * 85).toDouble() + 10; + } + step++; + }); + } + } + emit(TestSetExecuteReady()); + } + + void _onDeleteActive(TestSetExecuteDeleteActive event, Emitter emit) async { + emit(TestSetExecuteLoading()); + print("Delete: ${exercisePlan!.type} paralellTest: $paralellTest"); + if (exercisePlan != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan!.type!)) { + exercisePlan = null; + if (exercisePlanDetails != null) { + exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1); + } + await Cache().deleteActiveExercisePlan(); + } + emit(TestSetExecuteReady()); + } + + void _onDeleteAllActive(TestSetExecuteDeleteAllActive event, Emitter emit) async { + emit(TestSetExecuteLoading()); + if (exercisePlan != null) { + print("DeleteAll Test Set: ${exercisePlan!.type}"); + exercisePlan = null; + if (exercisePlanDetails != null) { + exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1); + } + await Cache().deleteActiveExercisePlan(); + } + emit(TestSetExecuteReady()); + } + + void _onExerciseFinished(TestSetExecuteExerciseFinished event, Emitter emit) { + emit(TestSetExecuteLoading()); + exercisePlanDetails!.forEach((element) { + if (element.exerciseTypeId == event.exerciseTypeId) { + element.repeats = event.quantity.toInt(); + element.weightEquation = event.unitQuantity.toString(); + if (element.exercises == null) { + element.exercises = []; + } + final Exercise exercise = Exercise(); + exercise.customerId = Cache().userLoggedIn!.customerId!; + exercise.exerciseTypeId = event.exerciseTypeId; + exercise.quantity = event.quantity; + exercise.unit = element.exerciseType!.unit; + exercise.unitQuantity = event.unitQuantity; + exercise.dateAdd = DateTime.now(); + element.exercises!.add(exercise); + setPlanDetailState(element); + } + }); + Cache().saveActiveExercisePlan(exercisePlan!, exercisePlanDetails!); + if (this.isDone100Percent()) { + add(TestSetExecuteFinish()); + } else { + emit(TestSetExecuteReady()); + } + emit(TestSetExecuteReady()); + } + + void _onNewExercise(TestSetExecuteNewExercise event, Emitter emit) async { + emit(TestSetExecuteLoading()); + if (exercisePlan == null) { + exercisePlan = ExercisePlan(Cache().userLoggedIn!.name! + " Custom Test", Cache().userLoggedIn!.customerId!); + exercisePlan!.private = true; + exercisePlan!.dateAdd = DateTime.now(); + exercisePlan!.type = ExerciseAbility.paralell_test.enumToString(); + ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan!); + exercisePlan = savedExercisePlan; + exercisePlanDetails = []; + } + + if (!this.existsInPlanDetails(event.exerciseTypeId)) { + ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(event.exerciseTypeId); + if (exercisePlan!.exercisePlanId != null) { + exercisePlanDetail.exercisePlanId = exercisePlan!.exercisePlanId!; + } + final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId)!; + + exercisePlanDetail.serie = exerciseType.unitQuantityUnit == null ? 1 : 4; + exercisePlanDetail.exerciseType = exerciseType; + exercisePlanDetail.exerciseTypeId = event.exerciseTypeId; + ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail); + exercisePlanDetail.exercisePlanDetailId = savedDetail.exercisePlanDetailId; + exercisePlanDetail.state = ExercisePlanDetailState.start; + exercisePlanDetail.exercises = []; + if (exercisePlanDetails == null) { + exercisePlanDetails = []; + } + exercisePlanDetails!.add(exercisePlanDetail); + await Cache().saveActiveExercisePlan(exercisePlan!, exercisePlanDetails!); + paralellTest = true; + } + emit(TestSetExecuteReady()); + } + + void _onDeleteExercise(TestSetExecuteDeleteExercise event, Emitter emit) { + emit(TestSetExecuteLoading()); + ExercisePlanDetail? deleteDetail; + if (exercisePlanDetails != null) { + exercisePlanDetails!.forEach((element) { + if (element.exerciseTypeId == event.exerciseTypeId) { + deleteDetail = element; + } + }); + if (deleteDetail != null) { + exercisePlanDetails!.remove(deleteDetail); + if (exercisePlanDetails!.isEmpty) { + exercisePlan = null; + exercisePlanDetails = null; + Cache().deleteActiveExercisePlan(); + } + } + } + emit(TestSetExecuteReady()); + } + + void _onFinish(TestSetExecuteFinish event, Emitter emit) { + emit(TestSetExecuteLoading()); + Cache().deleteActiveExercisePlan(); + isDone100 = isDone100Percent(); + // Animation + // Home + emit(TestSetExecuteReady()); + } void setExerciseTypeId(int id) => exerciseTypeId = id; @@ -59,135 +204,6 @@ class TestSetExecuteBloc extends Bloc } } - @override - Stream mapEventToState( - TestSetExecuteEvent event, - ) async* { - try { - if (event is TestSetExecuteLoad) { - yield TestSetExecuteLoading(); - initExercisePlan(); - if (exerciseTypeId != null) { - int step = 0; - if (exercisePlanDetails != null) { - exercisePlanDetails!.forEach((element) { - if (element.exerciseTypeId == this.exerciseTypeId) { - scrollOffset = (step * 85).toDouble() + 10; - } - step++; - }); - } - } - yield TestSetExecuteReady(); - } else if (event is TestSetExecuteDeleteActive) { - print("Delete: ${exercisePlan!.type} paralellTest: $paralellTest"); - if (exercisePlan != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan!.type!)) { - exercisePlan = null; - if (exercisePlanDetails != null) { - exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1); - } - await Cache().deleteActiveExercisePlan(); - } - } else if (event is TestSetExecuteDeleteAllActive) { - if (exercisePlan != null) { - print("DeleteAll Test Set: ${exercisePlan!.type}"); - exercisePlan = null; - if (exercisePlanDetails != null) { - exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1); - } - await Cache().deleteActiveExercisePlan(); - } - } else if (event is TestSetExecuteExerciseFinished) { - yield TestSetExecuteLoading(); - exercisePlanDetails!.forEach((element) { - if (element.exerciseTypeId == event.exerciseTypeId) { - element.repeats = event.quantity.toInt(); - element.weightEquation = event.unitQuantity.toString(); - if (element.exercises == null) { - element.exercises = []; - } - final Exercise exercise = Exercise(); - exercise.customerId = Cache().userLoggedIn!.customerId!; - exercise.exerciseTypeId = event.exerciseTypeId; - exercise.quantity = event.quantity; - exercise.unit = element.exerciseType!.unit; - exercise.unitQuantity = event.unitQuantity; - exercise.dateAdd = DateTime.now(); - element.exercises!.add(exercise); - setPlanDetailState(element); - } - }); - Cache().saveActiveExercisePlan(exercisePlan!, exercisePlanDetails!); - if (this.isDone100Percent()) { - add(TestSetExecuteFinish()); - } else { - yield TestSetExecuteReady(); - } - } else if (event is TestSetExecuteNewExercise) { - yield TestSetExecuteLoading(); - if (exercisePlan == null) { - exercisePlan = ExercisePlan(Cache().userLoggedIn!.name! + " Custom Test", Cache().userLoggedIn!.customerId!); - exercisePlan!.private = true; - exercisePlan!.dateAdd = DateTime.now(); - exercisePlan!.type = ExerciseAbility.paralell_test.enumToString(); - ExercisePlan savedExercisePlan = await ExercisePlanApi().saveExercisePlan(exercisePlan!); - exercisePlan = savedExercisePlan; - exercisePlanDetails = []; - } - - if (!this.existsInPlanDetails(event.exerciseTypeId)) { - ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(event.exerciseTypeId); - if (exercisePlan!.exercisePlanId != null) { - exercisePlanDetail.exercisePlanId = exercisePlan!.exercisePlanId!; - } - final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId)!; - - exercisePlanDetail.serie = exerciseType.unitQuantityUnit == null ? 1 : 4; - exercisePlanDetail.exerciseType = exerciseType; - exercisePlanDetail.exerciseTypeId = event.exerciseTypeId; - ExercisePlanDetail savedDetail = await ExercisePlanApi().saveExercisePlanDetail(exercisePlanDetail); - exercisePlanDetail.exercisePlanDetailId = savedDetail.exercisePlanDetailId; - exercisePlanDetail.state = ExercisePlanDetailState.start; - exercisePlanDetail.exercises = []; - if (exercisePlanDetails == null) { - exercisePlanDetails = []; - } - exercisePlanDetails!.add(exercisePlanDetail); - await Cache().saveActiveExercisePlan(exercisePlan!, exercisePlanDetails!); - paralellTest = true; - } - yield TestSetExecuteReady(); - } else if (event is TestSetExecuteDeleteExercise) { - yield TestSetExecuteLoading(); - ExercisePlanDetail? deleteDetail; - if (exercisePlanDetails != null) { - exercisePlanDetails!.forEach((element) { - if (element.exerciseTypeId == event.exerciseTypeId) { - deleteDetail = element; - } - }); - if (deleteDetail != null) { - exercisePlanDetails!.remove(deleteDetail); - if (exercisePlanDetails!.isEmpty) { - exercisePlan = null; - exercisePlanDetails = null; - Cache().deleteActiveExercisePlan(); - } - } - } - yield TestSetExecuteReady(); - } else if (event is TestSetExecuteFinish) { - Cache().deleteActiveExercisePlan(); - isDone100 = isDone100Percent(); - // Animation - // Home - yield TestSetExecuteFinished(); - } - } on Exception catch (e) { - yield TestSetExecuteError(message: e.toString()); - } - } - bool hasBegun() { if (exercisePlanDetails == null || exercisePlanDetails!.isEmpty || diff --git a/lib/bloc/test_set_new/test_set_new_bloc.dart b/lib/bloc/test_set_new/test_set_new_bloc.dart index 545a264..2821c87 100644 --- a/lib/bloc/test_set_new/test_set_new_bloc.dart +++ b/lib/bloc/test_set_new/test_set_new_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'package:aitrainer_app/main.dart'; import 'package:aitrainer_app/bloc/test_set_execute/test_set_execute_bloc.dart'; import 'package:aitrainer_app/model/cache.dart'; @@ -23,9 +22,15 @@ class TestSetNewBloc extends Bloc { late double quantity; late double unitQuantity; - TestSetNewBloc( - {required this.exerciseRepository, required this.exerciseType, required this.exercisePlanDetailId, required this.executeBloc}) + TestSetNewBloc({required this.exerciseRepository, required this.exerciseType, required this.exercisePlanDetailId, required this.executeBloc}) : super(TestSetNewInitial()) { + this._load(); + on(_onChangeQuantity); + on(_onChangeQuantityUnit); + on(_onSubmit); + } + + void _load() { exerciseRepository.exerciseType = exerciseType; quantity = 12; unitQuantity = 30; @@ -37,34 +42,33 @@ class TestSetNewBloc extends Bloc { exerciseRepository.setCustomer(Cache().userLoggedIn!); } - @override - Stream mapEventToState( - TestSetNewEvent event, - ) async* { - try { - if (event is TestSetNewChangeQuantity) { - quantity = event.quantity; - exerciseRepository.setQuantity(quantity); - } else if (event is TestSetNewChangeQuantityUnit) { - unitQuantity = event.quantity; - exerciseRepository.setUnitQuantity(unitQuantity); - } else if (event is TestSetNewSubmit) { - yield TestSetNewLoading(); - exerciseRepository.end = DateTime.now(); - await exerciseRepository.addExercise(); - executeBloc.add( - TestSetExecuteExerciseFinished(exerciseTypeId: exerciseType.exerciseTypeId, quantity: quantity, unitQuantity: unitQuantity)); - if (!isInDebugMode) { - CustomerRepository customerRepository = CustomerRepository(); - customerRepository.customer = Cache().userLoggedIn; - MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); - await mauticRepository.sendMauticExercise(); - } + void _onChangeQuantity(TestSetNewChangeQuantity event, Emitter emit) { + emit(TestSetNewLoading()); + quantity = event.quantity; + exerciseRepository.setQuantity(quantity); + emit(TestSetNewReady()); + } - Track().track(TrackingEvent.test_set_new, eventValue: exerciseType.name); - } - } on Exception catch (e) { - yield TestSetNewError(message: e.toString()); + void _onChangeQuantityUnit(TestSetNewChangeQuantityUnit event, Emitter emit) { + emit(TestSetNewLoading()); + unitQuantity = event.quantity; + exerciseRepository.setUnitQuantity(unitQuantity); + emit(TestSetNewReady()); + } + + void _onSubmit(TestSetNewSubmit event, Emitter emit) async { + emit(TestSetNewLoading()); + exerciseRepository.end = DateTime.now(); + await exerciseRepository.addExercise(); + executeBloc.add(TestSetExecuteExerciseFinished(exerciseTypeId: exerciseType.exerciseTypeId, quantity: quantity, unitQuantity: unitQuantity)); + if (!isInDebugMode) { + CustomerRepository customerRepository = CustomerRepository(); + customerRepository.customer = Cache().userLoggedIn; + MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository); + await mauticRepository.sendMauticExercise(); } + + Track().track(TrackingEvent.test_set_new, eventValue: exerciseType.name); + emit(TestSetNewReady()); } } diff --git a/lib/bloc/timer/timer_bloc.dart b/lib/bloc/timer/timer_bloc.dart index cf1d29b..1105127 100644 --- a/lib/bloc/timer/timer_bloc.dart +++ b/lib/bloc/timer/timer_bloc.dart @@ -29,7 +29,42 @@ class TimerBloc extends Bloc { // ignore: cancel_subscriptions StreamSubscription? _tickerSubscription; - TimerBloc() : super(TimerReady(300)); + TimerBloc() : super(TimerReady(300)) { + on(_onStart); + on(_onPause); + on(_onResume); + on(_onReset); + on(_onTick); + on(_onEnd); + } + + Stream _onStart(TimerStart event, Emitter emit) async* { + yield* _mapStartToState(event); + } + + Stream _onPause(TimerPause event, Emitter emit) async* { + yield* _mapPauseToState(event); + } + + Stream _onResume(TimerResume event, Emitter emit) async* { + yield* _mapResumeToState(event); + } + + Stream _onReset(TimerReset event, Emitter emit) async* { + yield* _mapResetToState(event); + } + + Stream _onTick(TimerTick event, Emitter emit) async* { + yield* _mapTickToState(event); + } + + void _onEnd(TimerEnd event, Emitter emit) { + print("$event"); + if (_tickerSubscription != null) { + _tickerSubscription!.cancel(); + } + emit(TimerFinished(state.duration)); + } @override void onTransition(Transition transition) { @@ -37,29 +72,6 @@ class TimerBloc extends Bloc { //print(transition); } - @override - Stream mapEventToState( - TimerEvent event, - ) async* { - if (event is TimerStart) { - yield* _mapStartToState(event); - } else if (event is TimerPause) { - yield* _mapPauseToState(event); - } else if (event is TimerResume) { - yield* _mapResumeToState(event); - } else if (event is TimerReset) { - yield* _mapResetToState(event); - } else if (event is TimerTick) { - yield* _mapTickToState(event); - } else if (event is TimerEnd) { - print("$event"); - if (_tickerSubscription != null) { - _tickerSubscription!.cancel(); - } - yield TimerFinished(state.duration); - } - } - @override Future close() { if (_tickerSubscription != null) { diff --git a/lib/bloc/training_evaluation/training_evaluation_bloc.dart b/lib/bloc/training_evaluation/training_evaluation_bloc.dart index 210ad35..94afa7f 100644 --- a/lib/bloc/training_evaluation/training_evaluation_bloc.dart +++ b/lib/bloc/training_evaluation/training_evaluation_bloc.dart @@ -16,7 +16,8 @@ class TrainingEvaluationBloc extends Bloc(_onLoad); + _load(); + //on(_onLoad); } String duration = "-"; @@ -42,6 +43,20 @@ class TrainingEvaluationBloc extends Bloc 5) { + emit(TrainingEvaluationReady()); + } else { + emit(TrainingEvaluationVictoryReady()); + } + } + void createEvaluationData() { if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) { return; diff --git a/lib/bloc/tutorial/tutorial_bloc.dart b/lib/bloc/tutorial/tutorial_bloc.dart index c73d261..6cbb353 100644 --- a/lib/bloc/tutorial/tutorial_bloc.dart +++ b/lib/bloc/tutorial/tutorial_bloc.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'package:aitrainer_app/bloc/menu/menu_bloc.dart'; import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/tutorial.dart'; @@ -36,7 +35,67 @@ class TutorialBloc extends Bloc with Logging { MenuBloc? menuBloc; - TutorialBloc({required this.tutorialName}) : super(TutorialInitial()); + TutorialBloc({required this.tutorialName}) : super(TutorialInitial()) { + on(_onLoad); + on(_onNext); + on(_onWrongAction); + on(_onStart); + on(_onFinished); + } + + void _onLoad(TutorialLoad event, Emitter emit) { + emit(TutorialLoading()); + init(); + if (menuBloc != null) { + menuBloc!.add(MenuCreate()); + } + emit(TutorialReady()); + } + + void _onNext(TutorialNext event, Emitter emit) { + print("Tutorial Next: ${event.text}"); + if (tutorial != null) { + emit(TutorialLoading()); + + step = this.getNextStep(step); + if (step == -1) { + print("Tutorial $tutorialName finished!"); + return; + } + print("Step: $step"); + setNextStepData(step); + + if (menuBloc != null) { + menuBloc!.add(MenuCreate()); + } + Track().track(TrackingEvent.tutorial_step, eventValue: step.toString()); + } + } + + void _onWrongAction(TutorialWrongAction event, Emitter emit) { + emit(TutorialLoading()); + actualText = tutorial!.steps![step].errorTextTranslation!; + emit(TutorialReady()); + } + + void _onStart(TutorialStart event, Emitter emit) { + emit(TutorialLoading()); + canActivate = true; + step = 0; + emit(TutorialReady()); + } + + void _onFinished(TutorialFinished event, Emitter emit) async { + emit(TutorialLoading()); + isActive = false; + canActivate = false; + ActivityDone? activityDone = ActivityDone.tutorialBasic.searchByString(tutorialName); + if (activityDone != null) { + await Cache().setActivityDonePrefs(activityDone); + } + Track().track(TrackingEvent.tutorial_finished); + emit(TutorialReady()); + } init() { if (Cache().tutorials != null) { @@ -146,52 +205,4 @@ class TutorialBloc extends Bloc with Logging { } return nextStep; } - - @override - Stream mapEventToState(TutorialEvent event) async* { - if (event is TutorialLoad) { - init(); - if (menuBloc != null) { - menuBloc!.add(MenuCreate()); - } - } else if (event is TutorialNext) { - print("Tutorial Next: ${event.text}"); - if (tutorial != null) { - yield TutorialLoading(); - - step = this.getNextStep(step); - if (step == -1) { - print("Tutorial $tutorialName finished!"); - return; - } - print("Step: $step"); - setNextStepData(step); - - if (menuBloc != null) { - menuBloc!.add(MenuCreate()); - } - Track().track(TrackingEvent.tutorial_step, eventValue: step.toString()); - yield TutorialReady(); - } - } else if (event is TutorialWrongAction) { - yield TutorialLoading(); - actualText = tutorial!.steps![step].errorTextTranslation!; - yield TutorialReady(); - } else if (event is TutorialStart) { - yield TutorialLoading(); - canActivate = true; - step = 0; - yield TutorialReady(); - } else if (event is TutorialFinished) { - yield TutorialLoading(); - isActive = false; - canActivate = false; - ActivityDone? activityDone = ActivityDone.tutorialBasic.searchByString(tutorialName); - if (activityDone != null) { - await Cache().setActivityDonePrefs(activityDone); - } - Track().track(TrackingEvent.tutorial_finished); - yield TutorialReady(); - } - } } diff --git a/lib/library/liquid_progress_indicator/liquid_circular_progress_indicator.dart b/lib/library/liquid_progress_indicator/liquid_circular_progress_indicator.dart index 2440009..4f0ff56 100644 --- a/lib/library/liquid_progress_indicator/liquid_circular_progress_indicator.dart +++ b/lib/library/liquid_progress_indicator/liquid_circular_progress_indicator.dart @@ -38,7 +38,7 @@ class LiquidCircularProgressIndicator extends ProgressIndicator { Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor; - Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor; + Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).colorScheme.secondary; @override State createState() => _LiquidCircularProgressIndicatorState(); diff --git a/lib/library/liquid_progress_indicator/liquid_custom_progress_indicator.dart b/lib/library/liquid_progress_indicator/liquid_custom_progress_indicator.dart index 35af1bf..0d4009b 100644 --- a/lib/library/liquid_progress_indicator/liquid_custom_progress_indicator.dart +++ b/lib/library/liquid_progress_indicator/liquid_custom_progress_indicator.dart @@ -28,7 +28,7 @@ class LiquidCustomProgressIndicator extends ProgressIndicator { Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor; - Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor; + Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).colorScheme.secondary; @override State createState() => _LiquidCustomProgressIndicatorState(); diff --git a/lib/library/liquid_progress_indicator/liquid_linear_progress_indicator.dart b/lib/library/liquid_progress_indicator/liquid_linear_progress_indicator.dart index 72e7442..3c68bdc 100644 --- a/lib/library/liquid_progress_indicator/liquid_linear_progress_indicator.dart +++ b/lib/library/liquid_progress_indicator/liquid_linear_progress_indicator.dart @@ -40,7 +40,7 @@ class LiquidLinearProgressIndicator extends ProgressIndicator { Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor; - Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor; + Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).colorScheme.secondary; @override State createState() => _LiquidLinearProgressIndicatorState(); @@ -126,8 +126,7 @@ class _LinearBorderPainter extends CustomPainter { } @override - bool shouldRepaint(_LinearBorderPainter oldDelegate) => - color != oldDelegate.color || width != oldDelegate.width || radius != oldDelegate.radius; + bool shouldRepaint(_LinearBorderPainter oldDelegate) => color != oldDelegate.color || width != oldDelegate.width || radius != oldDelegate.radius; } class _LinearClipper extends CustomClipper { diff --git a/lib/main.dart b/lib/main.dart index f93a8db..30eb527 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -104,8 +104,7 @@ Future _reportError(dynamic error, dynamic stackTrace) async { ); final String platform = Platform.isAndroid ? "Android" : "iOS"; final String version = Cache().packageInfo != null ? Cache().packageInfo!.version + "+" + Cache().packageInfo!.buildNumber : ""; - final sentryId = - await Sentry.captureException(error, stackTrace: stackTrace, hint: "Platform: $platform, Version: $version, User: $customerId"); + final sentryId = await Sentry.captureException(error, stackTrace: stackTrace, hint: "Platform: $platform, Version: $version, User: $customerId"); print('Capture exception result : SentryId : $sentryId'); } @@ -163,7 +162,6 @@ Future main() async { } await initThirdParty(); final FirebaseAnalytics analytics = FirebaseAnalytics.instance; - ; print(" -- FireBase init.."); @@ -196,8 +194,7 @@ Future main() async { BlocProvider( create: (BuildContext context) => TestSetExecuteBloc(), ), - BlocProvider( - create: (BuildContext context) => TutorialBloc(tutorialName: ActivityDone.tutorialExecuteFirstTest.toStr())), + BlocProvider(create: (BuildContext context) => TutorialBloc(tutorialName: ActivityDone.tutorialExecuteFirstTest.toStr())), BlocProvider(create: (context) { final MenuBloc menuBloc = BlocProvider.of(context); return TrainingPlanBloc(menuBloc: menuBloc, trainingPlanRepository: TrainingPlanRepository()); diff --git a/lib/model/cache.dart b/lib/model/cache.dart index 62d5cd5..dc27681 100644 --- a/lib/model/cache.dart +++ b/lib/model/cache.dart @@ -780,25 +780,4 @@ class Cache with Logging { } this._customerPropertyAll!.add(property); } - - bool canTrial() { - bool can = true; - if (Cache().userLoggedIn == null) { - can = false; - return can; - } - for (var element in _purchases) { - if (element.customerId == Cache().userLoggedIn!.customerId) { - can = false; - } - } - - if (userLoggedIn!.trialDate != null) { - can = false; - } - - print("Can Trial $can"); - - return can; - } } diff --git a/lib/util/trans.dart b/lib/util/trans.dart index 618c473..ef4e07d 100644 --- a/lib/util/trans.dart +++ b/lib/util/trans.dart @@ -8,9 +8,6 @@ mixin Trans { } String t(String text) { - if (context == null) { - throw Exception("Translation: initialize the context"); - } return AppLocalizations.of(context)!.translate(text); } } diff --git a/lib/view/exercise_new_page.dart b/lib/view/exercise_new_page.dart index 5f465db..1cd4aa1 100644 --- a/lib/view/exercise_new_page.dart +++ b/lib/view/exercise_new_page.dart @@ -41,11 +41,7 @@ class _ExerciseNewPageState extends State with Trans, Logging { return BlocProvider( create: (context) => ExerciseNewBloc( - exerciseRepository: ExerciseRepository(), - menuBloc: menuBloc, - customerRepository: CustomerRepository(), - exerciseType: exerciseType) - ..add(ExerciseNewLoad()), + exerciseRepository: ExerciseRepository(), menuBloc: menuBloc, customerRepository: CustomerRepository(), exerciseType: exerciseType), child: BlocConsumer( listener: (context, state) { if (state is ExerciseNewError) { diff --git a/lib/view/mydevelopment_body_page.dart b/lib/view/mydevelopment_body_page.dart index f866a83..68cd091 100644 --- a/lib/view/mydevelopment_body_page.dart +++ b/lib/view/mydevelopment_body_page.dart @@ -1,5 +1,7 @@ import 'dart:async'; import 'dart:collection'; +import 'package:aitrainer_app/bloc/development_diagram/development_diagram_bloc.dart'; +import 'package:aitrainer_app/bloc/menu/menu_bloc.dart'; import 'package:aitrainer_app/library/radar_chart.dart'; import 'package:aitrainer_app/widgets/app_bar.dart'; import 'package:aitrainer_app/widgets/bottom_nav.dart'; @@ -11,6 +13,7 @@ import 'package:aitrainer_app/util/trans.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:aitrainer_app/bloc/body_development/body_development_bloc.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; class MyDevelopmentBodyPage extends StatefulWidget { @@ -55,7 +58,7 @@ class _MyDevelopmentBodyPage extends State with Trans, Co @override Widget build(BuildContext context) { - bloc = BlocProvider.of(context); + final MenuBloc menuBloc = BlocProvider.of(context); LinkedHashMap arguments = ModalRoute.of(context)!.settings.arguments as LinkedHashMap; final int customerId = arguments['customerId']; setContext(context); @@ -73,41 +76,181 @@ class _MyDevelopmentBodyPage extends State with Trans, Co alignment: Alignment.center, ), ), - child: BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - if (state is BodyDevelopmentInitial) { - return Container(); - } else { - return ModalProgressHUD( - child: developmentWidget(customerId), - inAsyncCall: state is BodyDevelopmentLoading, - opacity: 0.5, - color: Colors.black54, - progressIndicator: CircularProgressIndicator(), - ); - } - }, - )), + child: BlocProvider( + create: (context) => BodyDevelopmentBloc(workoutTreeRepository: menuBloc.menuTreeRepository), + child: BlocConsumer( + listener: (context, state) { + if (state is BodyDevelopmentError) { + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white)))); + } + }, + builder: (context, state) { + final bloc = BlocProvider.of(context); + return ModalProgressHUD( + child: developmentWidget(customerId, bloc), + inAsyncCall: state is BodyDevelopmentLoading, + opacity: 0.5, + color: Colors.black54, + progressIndicator: CircularProgressIndicator(), + ); + }, + ))), bottomNavigationBar: BottomNavigator(bottomNavIndex: 1), ); } - Widget developmentWidget(int customerId) { + Widget getFilterData(BodyDevelopmentBloc bloc) { + return Container( + color: Colors.transparent, + // padding: EdgeInsets.all(5), + child: Wrap( + direction: Axis.horizontal, + spacing: 10, + runSpacing: 5, + children: [ + ChoiceChip( + avatar: Icon( + Icons.bubble_chart, + ), + label: Text(t('Sum Of Mass')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.lightBlueAccent, + selected: bloc.group == DiagramGroup.sumMass, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.sumMass))}, + ), + ChoiceChip( + avatar: Icon(Icons.accessibility_new), + label: Text(t('One Rep Max')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.lightBlueAccent, + selected: bloc.group == DiagramGroup.oneRepMax, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.oneRepMax))}, + ), + ChoiceChip( + avatar: Icon(Icons.perm_device_information), + label: Text(t('Percent')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.lightBlueAccent, + selected: bloc.group == DiagramGroup.percent, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeGroup(group: DiagramGroup.percent))}, + ), + ], + ), + ); + } + + Widget getGroupDate(BodyDevelopmentBloc bloc) { + return Container( + color: Colors.transparent, + //padding: EdgeInsets.all(5), + child: Wrap( + direction: Axis.horizontal, + spacing: 10, + runSpacing: 5, + children: [ + ChoiceChip( + labelPadding: EdgeInsets.only(right: 5), + avatar: Icon(Icons.timer), + label: Text(t('L3M')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + disabledColor: Colors.black26, + selectedColor: Colors.greenAccent, + selected: bloc.filter == DiagramDateFilterGroup.l3m, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.l3m))}, + ), + ChoiceChip( + labelPadding: EdgeInsets.only(right: 5), + avatar: Icon(Icons.timer), + label: Text(t('FM-LM')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.greenAccent, + disabledColor: Colors.white12, + selected: bloc.filter == DiagramDateFilterGroup.fm_lm, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.fm_lm))}, + ), + ChoiceChip( + labelPadding: EdgeInsets.only(right: 5), + avatar: Icon(Icons.timer), + label: Text(t('L3T')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.greenAccent, + disabledColor: Colors.black26, + selected: bloc.filter == DiagramDateFilterGroup.l3t, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.l3t))}, + ), + ChoiceChip( + labelPadding: EdgeInsets.only(right: 5), + avatar: Icon(Icons.timer), + label: Text(t('Yearly')), + labelStyle: TextStyle(fontSize: 9, color: Colors.black), + selectedColor: Colors.greenAccent, + disabledColor: Colors.white70, + selected: bloc.filter == DiagramDateFilterGroup.yearly, + onSelected: (value) => {bloc.add(BodyDevelopmentChangeDate(filter: DiagramDateFilterGroup.yearly))}, + ), + ], + ), + ); + } + + Widget getLegend(BodyDevelopmentBloc bloc) { + if (bloc.filter == DiagramDateFilterGroup.yearly) { + return Offstage(); + } + return Wrap( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + width: 100, + height: 6, + color: Colors.green, + ), + Text("First Month", style: GoogleFonts.inter(fontSize: 14)), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + width: 100, + height: 6, + color: Colors.blue, + ), + Text("First Month", style: GoogleFonts.inter(fontSize: 14)), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + width: 100, + height: 6, + color: Colors.red, + ), + Text("First Month", style: GoogleFonts.inter(fontSize: 14)), + ], + ) + ], + ); + } + + Widget developmentWidget(int customerId, BodyDevelopmentBloc bloc) { return Column(children: [ explanationWidget(), + getFilterData(bloc), + getGroupDate(bloc), + getLegend(bloc), Expanded( - child: exerciseWidget(customerId), + child: exerciseWidget(customerId, bloc), ), ]); } - Widget exerciseWidget(int customerId) { - return RadarChart.light( - ticks: bloc.radarTicks, - features: bloc.radarFeatures, - data: bloc.radarData, - ); + Widget exerciseWidget(int customerId, BodyDevelopmentBloc bloc) { + return RadarChart.light(ticks: bloc.radarTicks, features: bloc.radarFeatures, data: bloc.radarData); } Widget explanationWidget() { diff --git a/lib/view/mydevelopment_page.dart b/lib/view/mydevelopment_page.dart index fa93b71..9747502 100644 --- a/lib/view/mydevelopment_page.dart +++ b/lib/view/mydevelopment_page.dart @@ -87,9 +87,7 @@ class _MyDevelopmentPage extends State with Trans { builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), - descriptions: Cache().canTrial() - ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") - : t("This is a premium function, you can reach it only with a valid subscription"), + descriptions: t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', @@ -151,9 +149,7 @@ class _MyDevelopmentPage extends State with Trans { builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), - descriptions: Cache().canTrial() - ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") - : t("This is a premium function, you can reach it only with a valid subscription"), + descriptions: t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', diff --git a/lib/view/mydevelopment_sizes_page.dart b/lib/view/mydevelopment_sizes_page.dart index c695371..3c693d6 100644 --- a/lib/view/mydevelopment_sizes_page.dart +++ b/lib/view/mydevelopment_sizes_page.dart @@ -160,7 +160,7 @@ class _SizeState extends State with Trans { HashMap args = HashMap(); args['customerRepository'] = bloc.customerRepository; args['property'] = element; - args['title'] = t("Size development: ") + " " + propertyName; + args['title'] = t("Size development") + ": " + t(propertyName); Navigator.of(context).pushNamed('developmentDiagramPage', arguments: args); } @@ -177,8 +177,8 @@ class _SizeState extends State with Trans { ), padding: EdgeInsets.only(left: 10, right: 5, top: 12, bottom: 8), child: Column(children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, + Wrap( + //mainAxisAlignment: MainAxisAlignment.start, children: [ Icon( Icons.info, @@ -187,7 +187,7 @@ class _SizeState extends State with Trans { Text(" "), Text( t("Red icon means you have not saved this size."), - overflow: TextOverflow.clip, + //overflow: TextOverflow.clip, style: GoogleFonts.inter( fontSize: 14, color: Colors.white, @@ -197,7 +197,7 @@ class _SizeState extends State with Trans { ), Text( t("Tap on the green icon to see your development in a diagram"), - overflow: TextOverflow.clip, + //overflow: TextOverflow.clip, style: GoogleFonts.inter( fontSize: 14, color: Colors.white, diff --git a/lib/view/settings.dart b/lib/view/settings.dart index 76f4298..4ba9475 100644 --- a/lib/view/settings.dart +++ b/lib/view/settings.dart @@ -185,7 +185,7 @@ class SettingsPage extends StatelessWidget with Trans { leading: Icon(CustomIcon.user_cog), title: TextButton( child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("Terms Of Use", style: TextStyle(color: Colors.black)), + Text(t("Terms Of Use"), style: TextStyle(color: Colors.black)), Icon( Icons.arrow_forward_ios, color: Colors.indigo, @@ -212,7 +212,7 @@ class SettingsPage extends StatelessWidget with Trans { leading: Icon(Icons.enhanced_encryption), title: TextButton( child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("Data Privacy", style: TextStyle(color: Colors.black)), + Text(t("Data Privacy"), style: TextStyle(color: Colors.black)), Icon( Icons.arrow_forward_ios, color: Colors.indigo, @@ -239,7 +239,7 @@ class SettingsPage extends StatelessWidget with Trans { leading: Icon(CustomIcon.question), title: TextButton( child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("Frequently Asked Questions", style: TextStyle(color: Colors.indigo)), + Text(t("Frequently Asked Questions"), style: TextStyle(color: Colors.indigo)), Icon( Icons.arrow_forward_ios, color: Colors.indigo, @@ -282,7 +282,7 @@ class SettingsPage extends StatelessWidget with Trans { leading: Icon(CustomIcon.mail_1), title: TextButton( child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("Feedback email", style: TextStyle(color: Colors.indigo)), + Text(t("Feedback email"), style: TextStyle(color: Colors.indigo)), Icon( Icons.arrow_forward_ios, color: Colors.indigo, diff --git a/lib/view/training_evaluation_page.dart b/lib/view/training_evaluation_page.dart index b5d6f97..c137785 100644 --- a/lib/view/training_evaluation_page.dart +++ b/lib/view/training_evaluation_page.dart @@ -51,12 +51,11 @@ class TrainingEvaluationPage extends StatelessWidget with Trans { ), ), child: BlocProvider( - create: (context) => - TrainingEvaluationBloc(trainingPlanBloc: trainingPlanBloc, day: dayName)..add(TrainingEvaluationLoad()), + create: (context) => TrainingEvaluationBloc(trainingPlanBloc: trainingPlanBloc, day: dayName), child: BlocConsumer(listener: (context, state) { if (state is TrainingEvaluationError) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white)))); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white)))); } else if (state is TrainingEvaluationVictoryReady) { showDialog( context: context, @@ -373,8 +372,7 @@ class ExerciseTile extends StatelessWidget with Trans { hasWeight ? skipped ? extra - ? TextSpan( - text: "-", style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold)) + ? TextSpan(text: "-", style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold)) : TextSpan( text: t("skipped") + "!", style: GoogleFonts.inter(fontSize: 12, color: Colors.grey[400], fontWeight: FontWeight.bold)) @@ -433,8 +431,7 @@ class ExerciseTile extends StatelessWidget with Trans { skipped || extra ? TextSpan() : TextSpan( - text: t("Trend") + ": ", - style: GoogleFonts.inter(fontSize: 12, color: Colors.yellow[400], fontWeight: FontWeight.bold)), + text: t("Trend") + ": ", style: GoogleFonts.inter(fontSize: 12, color: Colors.yellow[400], fontWeight: FontWeight.bold)), skipped || extra ? TextSpan() : TextSpan( diff --git a/lib/view/training_plan_activate_page.dart b/lib/view/training_plan_activate_page.dart index 8172538..25d2bac 100644 --- a/lib/view/training_plan_activate_page.dart +++ b/lib/view/training_plan_activate_page.dart @@ -204,9 +204,7 @@ class TrainingPlanActivatePage extends StatelessWidget with Trans { builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), - descriptions: Cache().canTrial() - ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") - : t("This is a premium function, you can reach it only with a valid subscription"), + descriptions: t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', @@ -478,8 +476,7 @@ class TrainingPlanActivatePage extends StatelessWidget with Trans { return DialogCommon( title: t("Dropset"), descriptions: t("A drop set is an advanced resistance training technique "), - description2: - t(" in which you focus on completing a set until failure - or the inability to do another repetition."), + description2: t(" in which you focus on completing a set until failure - or the inability to do another repetition."), text: "OK", onTap: () => { Navigator.of(context).pop(), diff --git a/lib/view/training_plan_execute.dart b/lib/view/training_plan_execute.dart index 94b662f..87b4f34 100644 --- a/lib/view/training_plan_execute.dart +++ b/lib/view/training_plan_execute.dart @@ -333,8 +333,8 @@ class _ExerciseListState extends State with Trans { String description2 = ""; if (next.exerciseTypeId != detail.exerciseTypeId) { title = AppLocalizations.of(context)!.translate("Stop!"); - description = AppLocalizations.of(context)!.translate("Please continue with the next exercise in the queue:") + - next.exerciseType!.nameTranslation; + description = + AppLocalizations.of(context)!.translate("Please continue with the next exercise in the queue:") + next.exerciseType!.nameTranslation; } else { final HashMap args = HashMap(); args['exerciseType'] = next.exerciseType; @@ -388,8 +388,7 @@ class _ExerciseListState extends State with Trans { bloc.getMyPlan()!.days[widget.dayName]!.forEach((element) { if (prev == null || (prev != null && prev!.exerciseTypeId != element.exerciseTypeId)) { tiles.add(GestureDetector( - onTap: () => - bloc.getNext() != null ? executeExercise(bloc, bloc.getNext()!, context) : Navigator.of(context).pushNamed('home'), + onTap: () => bloc.getNext() != null ? executeExercise(bloc, bloc.getNext()!, context) : Navigator.of(context).pushNamed('home'), child: ExerciseTile( bloc: bloc, detail: element, @@ -544,8 +543,7 @@ class ExerciseTile extends StatelessWidget with Trans { List getExerciseTiles(CustomerTrainingPlanDetails detail) { final List list = []; - if (bloc.alternatives[detail.customerTrainingPlanDetailsId] != null && - bloc.alternatives[detail.customerTrainingPlanDetailsId].length > 0) { + if (bloc.alternatives[detail.customerTrainingPlanDetailsId] != null && bloc.alternatives[detail.customerTrainingPlanDetailsId].length > 0) { int index = 0; for (CustomerTrainingPlanDetails alternative in bloc.alternatives[detail.customerTrainingPlanDetailsId]) { final Widget widget = getTile(alternative, index); @@ -565,8 +563,7 @@ class ExerciseTile extends StatelessWidget with Trans { final int step = bloc.getStep(detail); final int highlightStep = bloc.getHighlightStep(detail); final bool hasLeftAlternative = detail.alternatives.length > 0 && index > 0; - final bool hasRightAlternative = - detail.alternatives.length > 0 && index + 1 < bloc.alternatives[detail.customerTrainingPlanDetailsId].length; + final bool hasRightAlternative = detail.alternatives.length > 0 && index + 1 < bloc.alternatives[detail.customerTrainingPlanDetailsId].length; return Container( child: Stack(alignment: Alignment.centerRight, children: [ @@ -601,8 +598,7 @@ class ExerciseTile extends StatelessWidget with Trans { context: context, builder: (BuildContext context) { return DialogHTML( - title: detail.exerciseType!.nameTranslation, - htmlData: '

' + detail.exerciseType!.descriptionTranslation + '

'); + title: detail.exerciseType!.nameTranslation, htmlData: '

' + detail.exerciseType!.descriptionTranslation + '

'); }), icon: Icon( Icons.info_outline, @@ -676,13 +672,13 @@ class ExerciseTile extends StatelessWidget with Trans { height: 1.1, shadows: [ Shadow( - offset: Offset(16.0, 16.0), - blurRadius: 16.0, + offset: Offset(8.0, 8.0), + blurRadius: 8.0, color: Colors.black54, ), Shadow( - offset: Offset(16.0, 16.0), - blurRadius: 16.0, + offset: Offset(8.0, 8.0), + blurRadius: 8.0, color: Colors.black54, ), ], diff --git a/lib/widgets/app_bar.dart b/lib/widgets/app_bar.dart index dc89d29..271fc60 100644 --- a/lib/widgets/app_bar.dart +++ b/lib/widgets/app_bar.dart @@ -191,7 +191,7 @@ class _AppBarNav extends State with SingleTickerProviderStateMixin, C percent > 0.6 ? Icons.mood : Icons.mood_bad, color: colorAnim.value, ), - linearStrokeCap: LinearStrokeCap.roundAll, + barRadius: Radius.circular(8), backgroundColor: colorAnim.value, progressColor: Color(0xff73e600), animation: true, diff --git a/lib/widgets/menu_page_widget.dart b/lib/widgets/menu_page_widget.dart index 0b9481f..0dde78a 100644 --- a/lib/widgets/menu_page_widget.dart +++ b/lib/widgets/menu_page_widget.dart @@ -75,32 +75,6 @@ class _MenuPageWidgetState extends State with Trans, Logging { if (Cache().userLoggedIn != null) { await initDynamicLinks(); } - if (Cache().canTrial()) { - showDialog( - context: context, - builder: (BuildContext context) { - return DialogTrialWidget( - title: t("10 days Premium for free"), - description: t("Would you like to try all premium functions for 10 days, without any subscription or bank card data?"), - widget: Column(children: [ - Text( - t("If you click to 'OK', all premium functions will be available right now."), - style: GoogleFonts.inter(color: Colors.white), - ), - Divider(), - /* Text( - t("If you click to 'No', you can use all basic functions, and you will loose the oppurtunity to try the premium functions for free."), - style: GoogleFonts.inter(color: Colors.white), - ), */ - ]), - onCancel: () => { - Navigator.of(context).pop(), - menuBloc.add(MenuStartTrial(start: DateTime.parse("1900-01-01 00:00:00"))), - }, - onTap: () => {Navigator.of(context).pop(), menuBloc.add(MenuStartTrial(start: DateTime.now()))}, - ); - }); - } }); } @@ -128,7 +102,6 @@ class _MenuPageWidgetState extends State with Trans, Logging { @override Widget build(BuildContext context) { menuBloc = BlocProvider.of(context); - //tutorialBloc = BlocProvider.of(context); setContext(context); double cWidth = MediaQuery.of(context).size.width; double cHeight = MediaQuery.of(context).size.height; @@ -139,9 +112,7 @@ class _MenuPageWidgetState extends State with Trans, Logging { return Stack(children: [ CustomScrollView( - controller: scrollController, - scrollDirection: Axis.vertical, - slivers: buildMenuColumn(widget.parent!, context, menuBloc, cWidth, cHeight)), + controller: scrollController, scrollDirection: Axis.vertical, slivers: buildMenuColumn(widget.parent!, context, menuBloc, cWidth, cHeight)), ]); } @@ -163,15 +134,13 @@ class _MenuPageWidgetState extends State with Trans, Logging { padding: EdgeInsets.only(top: 15.0), child: Center( child: Stack(alignment: Alignment.bottomLeft, children: [ - Text(AppLocalizations.of(context)!.translate("All Exercises has been filtered out"), - style: GoogleFonts.inter(color: Colors.white)), + Text(AppLocalizations.of(context)!.translate("All Exercises has been filtered out"), style: GoogleFonts.inter(color: Colors.white)), ])))); } else { menuBloc.getFilteredBranch(menuBloc.parent).forEach((treeName, value) { WorkoutMenuTree workoutTree = value; _columnChildren.add(Container( padding: EdgeInsets.only(top: 15.0, left: cWidth * 0.04, right: cWidth * 0.04), - //height: (cHeight / 3) - cWidth * 0.16, child: Badge( padding: EdgeInsets.all(8), position: BadgePosition.bottomEnd(end: 0), @@ -384,8 +353,6 @@ class _MenuPageWidgetState extends State with Trans, Logging { Navigator.of(context).pushNamed("myTrainingPlanActivate", arguments: args); menuBloc.add(MenuTreeDown(item: workoutTree, parent: workoutTree.id)); } else if (workoutTree.internalName == "training_execute") { - /* Cache().myTrainingPlan = null; - Cache().deleteMyTrainingPlan(); */ if (Cache().myTrainingPlan != null) { final TrainingPlanBloc bloc = BlocProvider.of(context); bloc.setMyPlan(Cache().myTrainingPlan); @@ -417,8 +384,6 @@ class _MenuPageWidgetState extends State with Trans, Logging { menuBloc.add(MenuTreeDown(item: workoutTree, parent: workoutTree.id)); } } else { - menuBloc.add(MenuClickExercise(exerciseTypeId: workoutTree.id)); - if (workoutTree.exerciseType!.name == "Custom" && Cache().userLoggedIn!.admin == 1) { Navigator.of(context).pushNamed('exerciseCustomPage', arguments: workoutTree.exerciseType); } else { @@ -430,10 +395,8 @@ class _MenuPageWidgetState extends State with Trans, Logging { dynamic getShape(WorkoutMenuTree workoutTree) { bool base = workoutTree.base; dynamic returnCode = (base == true) - ? RoundedRectangleBorder( - side: BorderSide(width: 6, color: Colors.orangeAccent), borderRadius: BorderRadius.all(Radius.circular(24.0))) - : RoundedRectangleBorder( - side: BorderSide(width: 1, color: Colors.transparent), borderRadius: BorderRadius.all(Radius.circular(8.0))); + ? RoundedRectangleBorder(side: BorderSide(width: 6, color: Colors.orangeAccent), borderRadius: BorderRadius.all(Radius.circular(24.0))) + : RoundedRectangleBorder(side: BorderSide(width: 1, color: Colors.transparent), borderRadius: BorderRadius.all(Radius.circular(8.0))); return returnCode; } diff --git a/pubspec.lock b/pubspec.lock index 5b4cd19..97202c1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -56,14 +56,14 @@ packages: name: bloc url: "https://pub.dartlang.org" source: hosted - version: "7.2.1" + version: "8.0.3" bloc_test: dependency: "direct dev" description: name: bloc_test url: "https://pub.dartlang.org" source: hosted - version: "8.5.0" + version: "9.0.3" boolean_selector: dependency: transitive description: @@ -523,7 +523,7 @@ packages: name: flutter_bloc url: "https://pub.dartlang.org" source: hosted - version: "7.3.3" + version: "8.0.1" flutter_facebook_auth: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index c13630e..21004a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,7 +28,7 @@ dependencies: google_fonts: ^2.1.0 devicelocale: ^0.5.0 sentry_flutter: ^6.4.0 - flutter_bloc: ^7.3.3 + flutter_bloc: ^8.0.1 equatable: ^2.0.3 radar_chart: ^2.1.0 @@ -100,7 +100,7 @@ dev_dependencies: test: '>=1.0.0 <2.0.0' flutter_test: sdk: flutter - bloc_test: ^8.5.0 + bloc_test: ^9.0.3 build_runner: