WT1.1.11 Null-Safe migration
This commit is contained in:
@@ -16,9 +16,9 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
final CustomerRepository customerRepository;
|
||||
bool loggedIn = false;
|
||||
int traineeId = 0;
|
||||
AccountBloc({this.customerRepository}) : super(AccountInitial()) {
|
||||
AccountBloc({required this.customerRepository}) : super(AccountInitial()) {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
loggedIn = true;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
yield AccountLoggedIn();
|
||||
} else if (event is AccountLogout) {
|
||||
await Cache().logout();
|
||||
customerRepository.customer = null;
|
||||
//customerRepository.customer = null;
|
||||
customerRepository.emptyTrainees();
|
||||
loggedIn = false;
|
||||
yield AccountLoggedOut();
|
||||
@@ -85,7 +85,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
} else if (event is AccountSelectTrainee) {
|
||||
yield AccountLoading();
|
||||
customerRepository.setTrainee(event.traineeId);
|
||||
Cache().setTrainee(customerRepository.getTraineeById(event.traineeId));
|
||||
Cache().setTrainee(customerRepository.getTraineeById(event.traineeId)!);
|
||||
ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
await exerciseRepository.getExercisesByCustomer(event.traineeId);
|
||||
this.traineeId = event.traineeId;
|
||||
|
||||
@@ -9,37 +9,21 @@ abstract class AccountEvent extends Equatable {
|
||||
}
|
||||
|
||||
class AccountChangeCustomer extends AccountEvent {
|
||||
final Customer customer;
|
||||
|
||||
const AccountChangeCustomer({this.customer});
|
||||
|
||||
@override
|
||||
List<Object> get props => [customer];
|
||||
const AccountChangeCustomer();
|
||||
}
|
||||
|
||||
class AccountLogout extends AccountEvent {
|
||||
final Customer customer;
|
||||
|
||||
const AccountLogout({this.customer});
|
||||
|
||||
@override
|
||||
List<Object> get props => [customer];
|
||||
|
||||
const AccountLogout();
|
||||
}
|
||||
|
||||
class AccountLogin extends AccountEvent {
|
||||
final Customer customer;
|
||||
|
||||
const AccountLogin({this.customer});
|
||||
|
||||
@override
|
||||
List<Object> get props => [customer];
|
||||
const AccountLogin();
|
||||
}
|
||||
|
||||
class AccountLogInFinished extends AccountEvent {
|
||||
final Customer customer;
|
||||
|
||||
const AccountLogInFinished({this.customer});
|
||||
const AccountLogInFinished({required this.customer});
|
||||
|
||||
@override
|
||||
List<Object> get props => [customer];
|
||||
@@ -51,8 +35,8 @@ class AccountGetTrainees extends AccountEvent {
|
||||
|
||||
class AccountSelectTrainee extends AccountEvent {
|
||||
final int traineeId;
|
||||
const AccountSelectTrainee({this.traineeId});
|
||||
const AccountSelectTrainee({required this.traineeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [traineeId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class AccountLoggedIn extends AccountState {
|
||||
|
||||
class AccountError extends AccountState {
|
||||
final String message;
|
||||
const AccountError({this.message});
|
||||
const AccountError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -13,14 +13,14 @@ class BodyDevelopmentBloc extends Bloc<BodyDevelopmentEvent, BodyDevelopmentStat
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
|
||||
List<int> radarTicks = List();
|
||||
List<String> radarFeatures = List();
|
||||
List<List<int>> radarData = List();
|
||||
List<int> radarTicks = [];
|
||||
List<String> radarFeatures = [];
|
||||
List<List<int>> radarData = [];
|
||||
|
||||
@override
|
||||
BodyDevelopmentBloc({this.workoutTreeRepository}): super(BodyDevelopmentInitial());
|
||||
BodyDevelopmentBloc({required this.workoutTreeRepository}) : super(BodyDevelopmentInitial());
|
||||
|
||||
Future<void> getData() async{
|
||||
Future<void> getData() async {
|
||||
radarTicks = [20, 40, 60, 80, 100];
|
||||
radarFeatures = ["Mell", "Bicepsz", "Tricepsz", "Hát", "Váll"];
|
||||
radarData = [
|
||||
|
||||
@@ -22,9 +22,8 @@ class BodyDevelopmentReady extends BodyDevelopmentState {
|
||||
|
||||
class BodyDevelopmentError extends BodyDevelopmentState {
|
||||
final String message;
|
||||
const BodyDevelopmentError({this.message});
|
||||
const BodyDevelopmentError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ part 'bodytype_state.dart';
|
||||
class BodytypeBloc extends Bloc<BodytypeEvent, BodytypeState> {
|
||||
static const int numberQuestions = 22;
|
||||
final CustomerRepository repository;
|
||||
final List<String> questions = List();
|
||||
final List<int> answers = List();
|
||||
final weights = List.generate(numberQuestions, (i) => List(3), growable: false);
|
||||
final List<String> questions = [];
|
||||
final List<int> answers = [];
|
||||
final weights = List.generate(numberQuestions, (i) => []..length = 3, growable: false);
|
||||
|
||||
BodytypeBloc({this.repository}) : super(BodytypeInitial()) {
|
||||
BodytypeBloc({required this.repository}) : super(BodytypeInitial()) {
|
||||
questions.add("1. Basicly I am skinny and bonny");
|
||||
questions.add("2. question");
|
||||
questions.add("3. question");
|
||||
@@ -71,15 +71,14 @@ class BodytypeBloc extends Bloc<BodytypeEvent, BodytypeState> {
|
||||
weights[21] = [7, 3, 0];
|
||||
|
||||
final double value = repository.getCustomerPropertyValue(PropertyEnum.Ectomorph.toStr());
|
||||
if (value != null) {
|
||||
_ecto = value.toInt();
|
||||
_mezo = repository.getCustomerPropertyValue(PropertyEnum.Mesomorph.toStr()).toInt();
|
||||
_endo = repository.getCustomerPropertyValue(PropertyEnum.Endomorph.toStr()).toInt();
|
||||
print("** Init ecto: " + _ecto.toString() + " mezo: " + _mezo.toString() + " endo: " + _endo.toString());
|
||||
if (_ecto > 0 && _mezo > 0 && _endo > 0) {
|
||||
calculateBodyType(init: true);
|
||||
origBodyTypeValue = bodyTypeValue;
|
||||
}
|
||||
|
||||
_ecto = value.toInt();
|
||||
_mezo = repository.getCustomerPropertyValue(PropertyEnum.Mesomorph.toStr()).toInt();
|
||||
_endo = repository.getCustomerPropertyValue(PropertyEnum.Endomorph.toStr()).toInt();
|
||||
print("** Init ecto: " + _ecto.toString() + " mezo: " + _mezo.toString() + " endo: " + _endo.toString());
|
||||
if (_ecto > 0 && _mezo > 0 && _endo > 0) {
|
||||
calculateBodyType(init: true);
|
||||
origBodyTypeValue = bodyTypeValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,13 +134,13 @@ class BodytypeBloc extends Bloc<BodytypeEvent, BodytypeState> {
|
||||
|
||||
Future<void> savePropertyDB(String name, double value) async {
|
||||
final now = DateTime.now();
|
||||
Property property = repository.propertyRepository.getPropertyByName(name);
|
||||
Property? property = repository.propertyRepository.getPropertyByName(name);
|
||||
if (property != null) {
|
||||
int propertyId = property.propertyId;
|
||||
CustomerProperty customerProperty = repository.getCustomerProperty(name);
|
||||
CustomerProperty? customerProperty = repository.getCustomerProperty(name);
|
||||
if (customerProperty == null || customerProperty.customerPropertyId == null) {
|
||||
customerProperty =
|
||||
CustomerProperty(customerId: Cache().userLoggedIn.customerId, propertyId: propertyId, propertyValue: value, dateAdd: now);
|
||||
CustomerProperty(customerId: Cache().userLoggedIn!.customerId!, propertyId: propertyId, propertyValue: value, dateAdd: now);
|
||||
|
||||
CustomerProperty newProperty = await CustomerApi().addProperty(customerProperty);
|
||||
repository.setCustomerProperty(name, value, id: newProperty.customerPropertyId);
|
||||
|
||||
@@ -17,7 +17,7 @@ class BodytypeSave extends BodytypeEvent {
|
||||
|
||||
class BodytypeClick extends BodytypeEvent {
|
||||
final int value;
|
||||
const BodytypeClick({this.value});
|
||||
const BodytypeClick({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
|
||||
@@ -25,7 +25,7 @@ class BodytypeFinished extends BodytypeState {
|
||||
|
||||
class BodytypeError extends BodytypeState {
|
||||
final String error;
|
||||
const BodytypeError({this.error});
|
||||
const BodytypeError({required this.error});
|
||||
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
import 'dart:math';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
class CustomExerciseFormBloc extends FormBloc<String, String> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
bool loading = false;
|
||||
final quantityField = TextFieldBloc(
|
||||
validators: [
|
||||
FieldBlocValidators.required,
|
||||
],
|
||||
);
|
||||
|
||||
final unitQuantityField = TextFieldBloc(
|
||||
validators: [
|
||||
FieldBlocValidators.required,
|
||||
],
|
||||
);
|
||||
|
||||
//1RM calculated Fields
|
||||
final rmWendlerField = TextFieldBloc(
|
||||
initialValue: "0",
|
||||
);
|
||||
final rmMayhewField = TextFieldBloc(initialValue: "0");
|
||||
final rmOconnerField = TextFieldBloc(initialValue: "0");
|
||||
final rmWathenField = TextFieldBloc(initialValue: "0");
|
||||
final rmAverageField = TextFieldBloc(initialValue: "0");
|
||||
final rm90Field = TextFieldBloc(initialValue: "0");
|
||||
final rm80Field = TextFieldBloc(initialValue: "0");
|
||||
final rm75Field = TextFieldBloc(initialValue: "0");
|
||||
final rm75WendlerField = TextFieldBloc(initialValue: "0");
|
||||
final rm75OconnorField = TextFieldBloc(initialValue: "0");
|
||||
final rm70Field = TextFieldBloc(initialValue: "0");
|
||||
final rm60Field = TextFieldBloc(initialValue: "0");
|
||||
final rm50Field = TextFieldBloc(initialValue: "0");
|
||||
|
||||
CustomExerciseFormBloc({this.exerciseRepository}) {
|
||||
addFieldBlocs(fieldBlocs: [
|
||||
quantityField,
|
||||
unitQuantityField,
|
||||
rmWendlerField,
|
||||
rmMayhewField,
|
||||
rmOconnerField,
|
||||
rmWathenField,
|
||||
rmAverageField,
|
||||
rm90Field,
|
||||
rm80Field,
|
||||
rm70Field,
|
||||
rm75Field,
|
||||
rm75WendlerField,
|
||||
rm75OconnorField,
|
||||
rm60Field,
|
||||
rm50Field
|
||||
]);
|
||||
|
||||
quantityField.onValueChanges(onData: (previous, current) async* {
|
||||
exerciseRepository.setQuantity(current.valueToDouble);
|
||||
calculate1RM();
|
||||
});
|
||||
|
||||
unitQuantityField.onValueChanges(onData: (previous, current) async* {
|
||||
exerciseRepository.setUnitQuantity(current.valueToDouble);
|
||||
calculate1RM();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
try {
|
||||
loading = true;
|
||||
emitLoading(progress: 30);
|
||||
// Emit either Loaded or Error
|
||||
|
||||
emitSuccess(canSubmitAgain: false);
|
||||
loading = false;
|
||||
} on Exception catch (ex) {
|
||||
emitFailure(failureResponse: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void calculate1RM() {
|
||||
double weight = exerciseRepository.exercise.unitQuantity;
|
||||
double repeat = exerciseRepository.exercise.quantity;
|
||||
if (weight == 0 || repeat == 0) {
|
||||
return;
|
||||
}
|
||||
exerciseRepository.rmWendler = weight * repeat * 0.0333 + weight;
|
||||
rmWendlerField.updateValue(exerciseRepository.rmWendler.toStringAsFixed(1));
|
||||
exerciseRepository.rmOconner = weight * (1 + repeat / 40);
|
||||
rmOconnerField.updateValue(exerciseRepository.rmOconner.toStringAsFixed(1));
|
||||
exerciseRepository.rmMayhew = 100 * weight / (52.2 + 41.9 * pow(e, -0.055 * repeat));
|
||||
rmMayhewField.updateValue(exerciseRepository.rmMayhew.toStringAsFixed(1));
|
||||
exerciseRepository.rmWathen = 100 * weight / (48.8 + 53.8 * pow(e, -0.075 * repeat));
|
||||
rmWathenField.updateValue(exerciseRepository.rmWathen.toStringAsFixed(1));
|
||||
double average = (exerciseRepository.rmWendler + exerciseRepository.rmOconner) / 2;
|
||||
rmAverageField.updateValue(average.toStringAsFixed(1));
|
||||
rm90Field.updateValue((average * 0.9).toStringAsFixed(1));
|
||||
rm80Field.updateValue((average * 0.8).toStringAsFixed(1));
|
||||
rm75Field.updateValue((average * 0.75).toStringAsFixed(1));
|
||||
rm75OconnorField.updateValue((exerciseRepository.rmOconner * 0.75).toStringAsFixed(1));
|
||||
rm75WendlerField.updateValue((exerciseRepository.rmWendler * 0.75).toStringAsFixed(1));
|
||||
rm70Field.updateValue((average * 0.7).toStringAsFixed(1));
|
||||
rm60Field.updateValue((average * 0.6).toStringAsFixed(1));
|
||||
rm50Field.updateValue((average * 0.5).toStringAsFixed(1));
|
||||
}
|
||||
|
||||
//@override
|
||||
Future<void> close() {
|
||||
quantityField.close();
|
||||
unitQuantityField.close();
|
||||
|
||||
rmWendlerField.close();
|
||||
rmMayhewField.close();
|
||||
rmOconnerField.close();
|
||||
rmWathenField.close();
|
||||
rmAverageField.close();
|
||||
rm90Field.close();
|
||||
rm80Field.close();
|
||||
rm75WendlerField.close();
|
||||
rm75OconnorField.close();
|
||||
rm75Field.close();
|
||||
rm70Field.close();
|
||||
rm60Field.close();
|
||||
rm50Field.close();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,13 @@ part 'customer_change_state.dart';
|
||||
|
||||
class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState> with Trans {
|
||||
final CustomerRepository customerRepository;
|
||||
final BuildContext context;
|
||||
bool visiblePassword = false;
|
||||
int year = 1990;
|
||||
int? year = 1990;
|
||||
double weight = 60;
|
||||
double height = 170;
|
||||
CustomerChangeBloc({this.customerRepository, this.context}) : super(CustomerChangeInitial()) {
|
||||
CustomerChangeBloc({required this.customerRepository}) : super(CustomerChangeInitial()) {
|
||||
year = this.customerRepository.customer.birthYear;
|
||||
if (year == 0) {
|
||||
if (year == null || year == 0) {
|
||||
year = 1990;
|
||||
}
|
||||
weight = this.customerRepository.getWeight() == 0 ? 60 : this.customerRepository.getWeight();
|
||||
@@ -102,23 +101,23 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
(nameValidation(customerRepository.customer.name) == null); */
|
||||
}
|
||||
|
||||
String emailValidation(String email) {
|
||||
String message = Common.emailValidation(email);
|
||||
String? emailValidation(String email) {
|
||||
String? message = Common.emailValidation(email);
|
||||
if (message != null) {
|
||||
message = t(message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
String passwordValidation(String value) {
|
||||
String message = Common.passwordValidation(value);
|
||||
String? passwordValidation(String value) {
|
||||
String? message = Common.passwordValidation(value);
|
||||
if (message != null) {
|
||||
message = t(message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
String nameValidation(String value) {
|
||||
String? nameValidation(String? value) {
|
||||
if (value == null || value.length == 0) {
|
||||
return t("Name too short");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class CustomerChangeEvent extends Equatable {
|
||||
|
||||
class CustomerGoalChange extends CustomerChangeEvent {
|
||||
final String goal;
|
||||
const CustomerGoalChange({this.goal});
|
||||
const CustomerGoalChange({required this.goal});
|
||||
|
||||
@override
|
||||
List<Object> get props => [goal];
|
||||
@@ -17,7 +17,7 @@ class CustomerGoalChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerFitnessChange extends CustomerChangeEvent {
|
||||
final String fitness;
|
||||
const CustomerFitnessChange({this.fitness});
|
||||
const CustomerFitnessChange({required this.fitness});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fitness];
|
||||
@@ -25,7 +25,7 @@ class CustomerFitnessChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerBodyTypeChange extends CustomerChangeEvent {
|
||||
final String bodyType;
|
||||
const CustomerBodyTypeChange({this.bodyType});
|
||||
const CustomerBodyTypeChange({required this.bodyType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [bodyType];
|
||||
@@ -33,7 +33,7 @@ class CustomerBodyTypeChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerBirthYearChange extends CustomerChangeEvent {
|
||||
final int year;
|
||||
const CustomerBirthYearChange({this.year});
|
||||
const CustomerBirthYearChange({required this.year});
|
||||
|
||||
@override
|
||||
List<Object> get props => [year];
|
||||
@@ -41,7 +41,7 @@ class CustomerBirthYearChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerWeightChange extends CustomerChangeEvent {
|
||||
final int weight;
|
||||
const CustomerWeightChange({this.weight});
|
||||
const CustomerWeightChange({required this.weight});
|
||||
|
||||
@override
|
||||
List<Object> get props => [weight];
|
||||
@@ -49,7 +49,7 @@ class CustomerWeightChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerHeightChange extends CustomerChangeEvent {
|
||||
final int height;
|
||||
const CustomerHeightChange({this.height});
|
||||
const CustomerHeightChange({required this.height});
|
||||
|
||||
@override
|
||||
List<Object> get props => [height];
|
||||
@@ -57,7 +57,7 @@ class CustomerHeightChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerGenderChange extends CustomerChangeEvent {
|
||||
final int gender;
|
||||
const CustomerGenderChange({this.gender});
|
||||
const CustomerGenderChange({required this.gender});
|
||||
|
||||
@override
|
||||
List<Object> get props => [gender];
|
||||
@@ -65,7 +65,7 @@ class CustomerGenderChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerEmailChange extends CustomerChangeEvent {
|
||||
final String email;
|
||||
const CustomerEmailChange({this.email});
|
||||
const CustomerEmailChange({required this.email});
|
||||
|
||||
@override
|
||||
List<Object> get props => [email];
|
||||
@@ -73,7 +73,7 @@ class CustomerEmailChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerFirstNameChange extends CustomerChangeEvent {
|
||||
final String firstName;
|
||||
const CustomerFirstNameChange({this.firstName});
|
||||
const CustomerFirstNameChange({required this.firstName});
|
||||
|
||||
@override
|
||||
List<Object> get props => [firstName];
|
||||
@@ -81,7 +81,7 @@ class CustomerFirstNameChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerNameChange extends CustomerChangeEvent {
|
||||
final String name;
|
||||
const CustomerNameChange({this.name});
|
||||
const CustomerNameChange({required this.name});
|
||||
|
||||
@override
|
||||
List<Object> get props => [name];
|
||||
@@ -89,7 +89,7 @@ class CustomerNameChange extends CustomerChangeEvent {
|
||||
|
||||
class CustomerPasswordChange extends CustomerChangeEvent {
|
||||
final String password;
|
||||
const CustomerPasswordChange({this.password});
|
||||
const CustomerPasswordChange({required this.password});
|
||||
|
||||
@override
|
||||
List<Object> get props => [password];
|
||||
|
||||
@@ -29,7 +29,7 @@ class CustomerSaveSuccess extends CustomerChangeState {
|
||||
|
||||
class CustomerSaveError extends CustomerChangeState {
|
||||
final String message;
|
||||
const CustomerSaveError({this.message});
|
||||
const CustomerSaveError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -13,11 +13,11 @@ part 'customer_exercise_device_state.dart';
|
||||
|
||||
class CustomerExerciseDeviceBloc extends Bloc<CustomerExerciseDeviceEvent, CustomerExerciseDeviceState> {
|
||||
final CustomerExerciseDeviceRepository repository;
|
||||
final List<ExerciseDevice> devices;
|
||||
final List<ExerciseDevice>? devices;
|
||||
|
||||
CustomerExerciseDeviceBloc({this.repository, this.devices}) : super(CustomerExerciseDeviceInitial()) {
|
||||
CustomerExerciseDeviceBloc({required this.repository, required this.devices}) : super(CustomerExerciseDeviceInitial()) {
|
||||
if (repository.getDevices().isEmpty) {
|
||||
repository.setDevices(Cache().getCustomerDevices());
|
||||
repository.setDevices(Cache().getCustomerDevices()!);
|
||||
}
|
||||
Track().track(TrackingEvent.exercise_device);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CustomerExerciseDeviceLoad extends CustomerExerciseDeviceEvent {
|
||||
|
||||
class CustomerExerciseDeviceAdd extends CustomerExerciseDeviceEvent {
|
||||
final ExerciseDevice device;
|
||||
const CustomerExerciseDeviceAdd({this.device});
|
||||
const CustomerExerciseDeviceAdd({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [device];
|
||||
@@ -21,7 +21,7 @@ class CustomerExerciseDeviceAdd extends CustomerExerciseDeviceEvent {
|
||||
|
||||
class CustomerExerciseDeviceRemove extends CustomerExerciseDeviceEvent {
|
||||
final ExerciseDevice device;
|
||||
const CustomerExerciseDeviceRemove({this.device});
|
||||
const CustomerExerciseDeviceRemove({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [device];
|
||||
|
||||
@@ -21,7 +21,7 @@ class CustomerExerciseDeviceReady extends CustomerExerciseDeviceState {
|
||||
|
||||
class CustomerExerciseDeviceError extends CustomerExerciseDeviceState {
|
||||
final String message;
|
||||
const CustomerExerciseDeviceError({this.message});
|
||||
const CustomerExerciseDeviceError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -13,11 +13,10 @@ import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/group_data.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
|
||||
@@ -36,35 +35,35 @@ class DiagramType {
|
||||
*/
|
||||
|
||||
class GroupDate extends GroupData with Calculate, Common {
|
||||
final List<dynamic> inputList;
|
||||
final List<dynamic> outputList;
|
||||
final List<Exercise> inputList;
|
||||
final List<Exercise> outputList;
|
||||
|
||||
String _origDatePart;
|
||||
int _origExerciseTypeId;
|
||||
Exercise _origExercise;
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
double _sumQuantity;
|
||||
double _maxQuantity;
|
||||
int _countExercises;
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
|
||||
String diagramType;
|
||||
String dateRate;
|
||||
late String diagramType;
|
||||
late String dateRate;
|
||||
|
||||
GroupDate({this.inputList, this.outputList});
|
||||
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;
|
||||
sum = exercise.quantity! * exercise.unitQuantity!;
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
sum = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
@@ -73,26 +72,26 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
_sumQuantity += newQuantity;
|
||||
_sumQuantity = _sumQuantity + newQuantity;
|
||||
if (_maxQuantity < newQuantity) {
|
||||
_maxQuantity = newQuantity;
|
||||
}
|
||||
_countExercises++;
|
||||
_origDatePart = getDatePart(exercise.dateAdd, dateRate);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId;
|
||||
_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 != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise tempExercise;
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if (this.checkNewType(element)) {
|
||||
@@ -108,7 +107,7 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise);
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,21 +141,21 @@ class GroupChart extends GroupData with Calculate {
|
||||
final List<dynamic> inputList;
|
||||
LinkedHashMap<int, ChartDataExtended> outputList = LinkedHashMap();
|
||||
|
||||
int _origExerciseTypeId;
|
||||
double _minData = 999999999999;
|
||||
double _maxData = 0;
|
||||
List<BarChartGroupData> _chartData;
|
||||
double _basePercent;
|
||||
int? _origExerciseTypeId;
|
||||
late double _minData = 999999999999;
|
||||
late double _maxData = 0;
|
||||
late List<BarChartGroupData> _chartData;
|
||||
late double _basePercent;
|
||||
|
||||
String diagramType = DiagramType.sumMass;
|
||||
|
||||
GroupChart({this.inputList, this.outputList});
|
||||
GroupChart({required this.inputList, required this.outputList});
|
||||
|
||||
double getBasePercent(Exercise exercise) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
this._basePercent = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
this._basePercent = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
} else {
|
||||
this._basePercent = exercise.quantity;
|
||||
this._basePercent = exercise.quantity!;
|
||||
}
|
||||
return this._basePercent;
|
||||
}
|
||||
@@ -166,13 +165,13 @@ class GroupChart extends GroupData with Calculate {
|
||||
|
||||
if (diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
double oneRepMax = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
double oneRepMax = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
value = (oneRepMax / this._basePercent) * 100;
|
||||
} else {
|
||||
value = (exercise.quantity / this._basePercent) * 100;
|
||||
value = (exercise.quantity! / this._basePercent) * 100;
|
||||
}
|
||||
} else if (diagramType == DiagramType.oneRepMax || diagramType == DiagramType.sumMass) {
|
||||
value = exercise.calculated;
|
||||
value = exercise.calculated!;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -188,22 +187,22 @@ class GroupChart extends GroupData with Calculate {
|
||||
_minData = diagramValue;
|
||||
}
|
||||
|
||||
BarChartGroupData data = BarChartGroupData(x: exercise.dateAdd.millisecondsSinceEpoch, barRods: [
|
||||
BarChartGroupData data = BarChartGroupData(x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, colors: [Colors.lightBlue, Colors.lightBlueAccent])
|
||||
]);
|
||||
_chartData.add(data);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId;
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
return _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
return _origExerciseTypeId == null || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise tempExercise;
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
|
||||
@@ -222,7 +221,7 @@ class GroupChart extends GroupData with Calculate {
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise);
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,9 +233,9 @@ class GroupChart extends GroupData with Calculate {
|
||||
ChartDataExtended extended;
|
||||
if (outputList[_origExerciseTypeId] == null) {
|
||||
extended = ChartDataExtended(data: _chartData, interval: dInterval, gridInterval: gridInterval);
|
||||
outputList[_origExerciseTypeId] = extended;
|
||||
outputList[_origExerciseTypeId!] = extended;
|
||||
} else {
|
||||
extended = outputList[_origExerciseTypeId];
|
||||
extended = outputList[_origExerciseTypeId]!;
|
||||
_chartData.forEach((element) {
|
||||
extended.data.add(element);
|
||||
});
|
||||
@@ -247,7 +246,7 @@ class GroupChart extends GroupData with Calculate {
|
||||
void resetTemp() {
|
||||
_minData = 999999999999;
|
||||
_maxData = 0;
|
||||
_chartData = List();
|
||||
_chartData = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,10 +255,10 @@ class ChartDataExtended {
|
||||
final double interval;
|
||||
final int gridInterval;
|
||||
|
||||
const ChartDataExtended({this.data, this.interval, this.gridInterval});
|
||||
const ChartDataExtended({required this.data, required this.interval, required this.gridInterval});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
List listBarChartData = List();
|
||||
List listBarChartData = [];
|
||||
data.forEach((element) {
|
||||
element.barRods.forEach((rods) {
|
||||
var barChartData = {
|
||||
@@ -280,18 +279,19 @@ class ChartDataExtended {
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate, Logging {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
LinkedHashMap<int, ChartDataExtended> listChartData = LinkedHashMap();
|
||||
List<BarChartGroupData> chartData;
|
||||
late List<BarChartGroupData> chartData;
|
||||
String diagramType = DiagramType.sumMass;
|
||||
String dateRate = DateRate.daily;
|
||||
double basePercent = 0;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
workoutTreeRepository.sortedTree = null;
|
||||
workoutTreeRepository.sortedTree.clear();
|
||||
workoutTreeRepository.sortByMuscleType();
|
||||
|
||||
workoutTreeRepository.sortedTree.forEach((key, value) {
|
||||
@@ -305,7 +305,7 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
}
|
||||
|
||||
void getChartData() {
|
||||
List<Exercise> exercises = exerciseRepository.getExerciseList();
|
||||
List<Exercise>? exercises = exerciseRepository.getExerciseList();
|
||||
|
||||
//print("-- Start calculate --- ");
|
||||
exercises = this.groupByDate(exercises);
|
||||
@@ -322,24 +322,25 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
listChartData = groupChart.outputList;
|
||||
|
||||
listChartData.forEach((key, value) {
|
||||
trace("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
//trace("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<Exercise> groupByDate(List<Exercise> exercises) {
|
||||
List<Exercise> groupedExercises = List();
|
||||
List<Exercise> groupByDate(List<Exercise>? exercises) {
|
||||
List<Exercise> groupedExercises = [];
|
||||
if (exercises != null) {
|
||||
exercises = sort(exercises, false);
|
||||
exercises.forEach((exercise) {
|
||||
//trace("Date exercise " + exercise.toJsonDatePart().toString());
|
||||
});
|
||||
|
||||
exercises = sort(exercises, false);
|
||||
exercises.forEach((exercise) {
|
||||
trace("Date exercise " + exercise.toJsonDatePart().toString());
|
||||
});
|
||||
|
||||
GroupDate groupDate = GroupDate(inputList: exercises, outputList: groupedExercises);
|
||||
groupDate.dateRate = this.dateRate;
|
||||
groupDate.diagramType = this.diagramType;
|
||||
groupDate.iteration();
|
||||
groupedExercises = groupDate.outputList;
|
||||
GroupDate groupDate = GroupDate(inputList: exercises, outputList: groupedExercises);
|
||||
groupDate.dateRate = this.dateRate;
|
||||
groupDate.diagramType = this.diagramType;
|
||||
groupDate.iteration();
|
||||
groupedExercises = groupDate.outputList;
|
||||
}
|
||||
|
||||
/* groupedExercises.forEach((element) {
|
||||
print("Grouped " + element.toJsonDatePart().toString());
|
||||
|
||||
@@ -14,7 +14,7 @@ class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent {
|
||||
|
||||
class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
final String dateRate;
|
||||
const DevelopmentByMuscleDateRateChange({this.dateRate});
|
||||
const DevelopmentByMuscleDateRateChange({required this.dateRate});
|
||||
|
||||
@override
|
||||
List<Object> get props => [dateRate];
|
||||
@@ -22,7 +22,7 @@ class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
|
||||
class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent {
|
||||
final String diagramType;
|
||||
const DevelopmentByMuscleDiagramTypeChange({this.diagramType});
|
||||
const DevelopmentByMuscleDiagramTypeChange({required this.diagramType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [diagramType];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
part of 'development_by_muscle_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class DevelopmentByMuscleState extends Equatable{
|
||||
abstract class DevelopmentByMuscleState extends Equatable {
|
||||
const DevelopmentByMuscleState();
|
||||
|
||||
@override
|
||||
@@ -20,10 +20,9 @@ class DevelopmentByMuscleReadyState extends DevelopmentByMuscleState {
|
||||
const DevelopmentByMuscleReadyState();
|
||||
}
|
||||
|
||||
|
||||
class DevelopmentByMuscleErrorState extends DevelopmentByMuscleState {
|
||||
final String message;
|
||||
const DevelopmentByMuscleErrorState({this.message});
|
||||
const DevelopmentByMuscleErrorState({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -10,11 +10,11 @@ part 'development_sizes_state.dart';
|
||||
|
||||
class DevelopmentSizesBloc extends Bloc<DevelopmentSizesEvent, DevelopmentSizesState> {
|
||||
final CustomerRepository customerRepository;
|
||||
DevelopmentSizesBloc({this.customerRepository}) : super(DevelopmentSizesInitial()) {
|
||||
isMan = Cache().userLoggedIn.sex == "m";
|
||||
DevelopmentSizesBloc({required this.customerRepository}) : super(DevelopmentSizesInitial()) {
|
||||
isMan = Cache().userLoggedIn!.sex == "m";
|
||||
}
|
||||
|
||||
bool isMan;
|
||||
late bool isMan;
|
||||
|
||||
@override
|
||||
Stream<DevelopmentSizesState> mapEventToState(
|
||||
|
||||
@@ -21,7 +21,7 @@ class DevelopmentSizesReady extends DevelopmentSizesState {
|
||||
|
||||
class DevelopmentSizesError extends DevelopmentSizesState {
|
||||
final String message;
|
||||
const DevelopmentSizesError({this.message});
|
||||
const DevelopmentSizesError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.message];
|
||||
|
||||
@@ -15,23 +15,24 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
final bool readonly;
|
||||
int step = 1;
|
||||
|
||||
double initialRM;
|
||||
double unitQuantity;
|
||||
double quantity;
|
||||
double origQuantity;
|
||||
double oneRepQuantity;
|
||||
double oneRepUnitQuantity;
|
||||
late double initialRM;
|
||||
late double unitQuantity;
|
||||
late double quantity;
|
||||
late double origQuantity;
|
||||
late double oneRepQuantity;
|
||||
late double oneRepUnitQuantity;
|
||||
|
||||
double firstQuantity; // quantity of the first test
|
||||
double firstUnitQuantity; // unit quantity of the first test
|
||||
double? firstQuantity; // quantity of the first test
|
||||
double? firstUnitQuantity; // unit quantity of the first test
|
||||
|
||||
double scrollOffset = 0;
|
||||
|
||||
@override
|
||||
ExerciseControlBloc({this.exerciseRepository, this.readonly, @required this.timerBloc}) : super(ExerciseControlInitial()) {
|
||||
print("Exercise ${exerciseRepository.exercise.toJson()}");
|
||||
oneRepQuantity = exerciseRepository.exercise.quantity;
|
||||
oneRepUnitQuantity = exerciseRepository.exercise.unitQuantity;
|
||||
ExerciseControlBloc({required this.exerciseRepository, required this.readonly, required this.timerBloc})
|
||||
: super(ExerciseControlInitial()) {
|
||||
print("Exercise ${exerciseRepository.exercise!.toJson()}");
|
||||
oneRepQuantity = exerciseRepository.exercise!.quantity!;
|
||||
oneRepUnitQuantity = exerciseRepository.exercise!.unitQuantity!;
|
||||
initialRM = this.calculate1RM(percent75: false);
|
||||
unitQuantity = this.calculate1RM(percent75: true).roundToDouble();
|
||||
quantity = 12;
|
||||
@@ -76,14 +77,14 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
scrollOffset = step * 400.0;
|
||||
|
||||
quantity = origQuantity;
|
||||
if (exerciseRepository.exercise.quantity == null) {
|
||||
if (exerciseRepository.exercise!.quantity == null) {
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
}
|
||||
exerciseRepository.end = DateTime.now();
|
||||
await exerciseRepository.addExercise();
|
||||
//exerciseRepository.initExercise();
|
||||
|
||||
step <= 3 ? timerBloc.add(TimerStart(duration: 300)) : timerBloc.add(TimerEnd());
|
||||
step <= 3 ? timerBloc.add(TimerStart(duration: 300)) : timerBloc.add(TimerEnd(duration: 300));
|
||||
}
|
||||
yield ExerciseControlReady();
|
||||
}
|
||||
@@ -92,12 +93,12 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
}
|
||||
}
|
||||
|
||||
double calculate1RM({bool percent75}) {
|
||||
double calculate1RM({bool percent75 = true}) {
|
||||
if (exerciseRepository.exercise == null) {
|
||||
exerciseRepository.getLastExercise();
|
||||
}
|
||||
double weight = exerciseRepository.exercise.unitQuantity;
|
||||
double repeat = exerciseRepository.exercise.quantity;
|
||||
double weight = exerciseRepository.exercise!.unitQuantity!;
|
||||
double repeat = exerciseRepository.exercise!.quantity!;
|
||||
if (weight == 0 || repeat == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -117,8 +118,8 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
final double rmOconner = weight * (1 + repeat / 40);
|
||||
print("Weight: $weight oneRepQuantity: $repeat, $rmWendler, Oconner: $rmOconner");
|
||||
|
||||
weight = exerciseRepository.exercise.unitQuantity;
|
||||
repeat = exerciseRepository.exercise.quantity;
|
||||
weight = exerciseRepository.exercise!.unitQuantity!;
|
||||
repeat = exerciseRepository.exercise!.quantity!;
|
||||
|
||||
final double repeatWendler = (rmWendler - weight) / 0.0333 / weight;
|
||||
final double repeatOconner = (rmOconner / weight - 1) * 40;
|
||||
|
||||
@@ -15,16 +15,16 @@ class ExerciseControlLoad extends ExerciseControlEvent {
|
||||
class ExerciseControlQuantityChange extends ExerciseControlEvent {
|
||||
final double quantity;
|
||||
final int step;
|
||||
const ExerciseControlQuantityChange({this.quantity, this.step});
|
||||
const ExerciseControlQuantityChange({required this.quantity, required this.step});
|
||||
}
|
||||
|
||||
class ExerciseControlUnitQuantityChange extends ExerciseControlEvent {
|
||||
final double quantity;
|
||||
final int step;
|
||||
const ExerciseControlUnitQuantityChange({this.quantity, this.step});
|
||||
const ExerciseControlUnitQuantityChange({required this.quantity, required this.step});
|
||||
}
|
||||
|
||||
class ExerciseControlSubmit extends ExerciseControlEvent {
|
||||
final int step;
|
||||
const ExerciseControlSubmit({this.step});
|
||||
const ExerciseControlSubmit({required this.step});
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ class ExerciseControlReady extends ExerciseControlState {
|
||||
|
||||
class ExerciseControlError extends ExerciseControlState {
|
||||
final String message;
|
||||
const ExerciseControlError({this.message});
|
||||
|
||||
const ExerciseControlError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,17 @@ part 'exercise_execute_plan_state.dart';
|
||||
class ExerciseExecutePlanBloc extends Bloc<ExerciseExecutePlanEvent, ExerciseExecutePlanState> {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
int? customerId;
|
||||
int selectedNumber = 0;
|
||||
|
||||
@override
|
||||
ExerciseExecutePlanBloc({this.menuTreeRepository}) : super(ExerciseByPlanStateInitial());
|
||||
ExerciseExecutePlanBloc({required this.menuTreeRepository}) : super(ExerciseByPlanStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
exercisePlanRepository.setCustomerId(customerId!);
|
||||
await exercisePlanRepository.getLastExercisePlan();
|
||||
await exercisePlanRepository.getExercisePlanDetails();
|
||||
menuTreeRepository.sortedTree = null;
|
||||
menuTreeRepository.sortedTree.clear();
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
|
||||
@@ -10,7 +10,7 @@ abstract class ExerciseExecutePlanEvent extends Equatable {
|
||||
|
||||
class AddExerciseByPlanEvent extends ExerciseExecutePlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const AddExerciseByPlanEvent({this.exerciseType});
|
||||
const AddExerciseByPlanEvent({required this.exerciseType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
|
||||
@@ -24,8 +24,8 @@ class ExerciseByPlanReady extends ExerciseExecutePlanState {
|
||||
// error splash screen
|
||||
class ExerciseByPlanError extends ExerciseExecutePlanState {
|
||||
final String message;
|
||||
const ExerciseByPlanError({this.message});
|
||||
const ExerciseByPlanError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,30 +22,35 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
final ExerciseExecutePlanBloc planBloc;
|
||||
final int customerId;
|
||||
|
||||
Customer customer;
|
||||
late Customer customer;
|
||||
int step = 1;
|
||||
int countSteps = 1;
|
||||
|
||||
double quantity;
|
||||
double unitQuantity;
|
||||
late double quantity;
|
||||
late double unitQuantity;
|
||||
|
||||
double scrollOffset = 0;
|
||||
|
||||
@override
|
||||
ExerciseExecutePlanAddBloc({this.exerciseRepository, this.exercisePlanRepository, this.customerId, this.workoutTree, this.planBloc})
|
||||
ExerciseExecutePlanAddBloc(
|
||||
{required this.exerciseRepository,
|
||||
required this.exercisePlanRepository,
|
||||
required this.customerId,
|
||||
required this.workoutTree,
|
||||
required this.planBloc})
|
||||
: super(ExerciseExecutePlanAddInitial()) {
|
||||
exerciseRepository.exerciseType = workoutTree.exerciseType;
|
||||
if (Cache().userLoggedIn.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn;
|
||||
} else if (Cache().getTrainee().customerId == customerId) {
|
||||
customer = Cache().getTrainee();
|
||||
if (Cache().userLoggedIn!.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn!;
|
||||
} else if (Cache().getTrainee()!.customerId == customerId) {
|
||||
customer = Cache().getTrainee()!;
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail().serie;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail()!.serie!;
|
||||
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats.toDouble();
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail()!.weightEquation!);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail()!.repeats!.toDouble();
|
||||
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
@@ -70,8 +75,8 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddSubmit) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
exerciseRepository.exercise.exercisePlanDetailId = exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
|
||||
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
|
||||
exerciseRepository.exercise!.exercisePlanDetailId = exercisePlanRepository.getActualPlanDetail()!.exercisePlanDetailId;
|
||||
exerciseRepository.exercise!.unit = workoutTree.exerciseType!.unit;
|
||||
workoutTree.executed = true;
|
||||
await exerciseRepository.addExercise();
|
||||
exerciseRepository.initExercise();
|
||||
|
||||
@@ -14,7 +14,7 @@ class ExerciseExecutePlanAddLoad extends ExerciseExecutePlanAddEvent {
|
||||
|
||||
class ExerciseExecutePlanAddChangeQuantity extends ExerciseExecutePlanAddEvent {
|
||||
final double quantity;
|
||||
const ExerciseExecutePlanAddChangeQuantity({this.quantity});
|
||||
const ExerciseExecutePlanAddChangeQuantity({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -22,7 +22,7 @@ class ExerciseExecutePlanAddChangeQuantity extends ExerciseExecutePlanAddEvent {
|
||||
|
||||
class ExerciseExecutePlanAddChangeUnitQuantity extends ExerciseExecutePlanAddEvent {
|
||||
final double quantity;
|
||||
const ExerciseExecutePlanAddChangeUnitQuantity({this.quantity});
|
||||
const ExerciseExecutePlanAddChangeUnitQuantity({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
|
||||
@@ -24,8 +24,8 @@ class ExerciseExecutePlanAddReady extends ExerciseExecutePlanAddState {
|
||||
// error splash screen
|
||||
class ExerciseExecutePlanAddError extends ExerciseExecutePlanAddState {
|
||||
final String message;
|
||||
const ExerciseExecutePlanAddError({this.message});
|
||||
const ExerciseExecutePlanAddError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ part 'exercise_log_state.dart';
|
||||
class ExerciseLogBloc extends Bloc<ExerciseLogEvent, ExerciseLogState> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
@override
|
||||
ExerciseLogBloc({this.exerciseRepository}) : super(ExerciseLogInitial());
|
||||
ExerciseLogBloc({required this.exerciseRepository}) : super(ExerciseLogInitial());
|
||||
|
||||
@override
|
||||
Stream<ExerciseLogState> mapEventToState(ExerciseLogEvent event) async* {
|
||||
@@ -27,7 +27,7 @@ class ExerciseLogBloc extends Bloc<ExerciseLogEvent, ExerciseLogState> {
|
||||
yield ExerciseLogReady();
|
||||
} else if (event is ExerciseLogDelete) {
|
||||
yield ExerciseLogLoading();
|
||||
exerciseRepository.exerciseList.remove(event.exercise);
|
||||
exerciseRepository.exerciseList!.remove(event.exercise);
|
||||
await exerciseRepository.deleteExercise(event.exercise);
|
||||
Track().track(TrackingEvent.exercise_log_delete);
|
||||
yield ExerciseLogReady();
|
||||
|
||||
@@ -14,7 +14,7 @@ class ExerciseLogLoad extends ExerciseLogEvent {
|
||||
|
||||
class ExerciseLogDelete extends ExerciseLogEvent {
|
||||
final Exercise exercise;
|
||||
const ExerciseLogDelete({this.exercise});
|
||||
const ExerciseLogDelete({required this.exercise});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercise];
|
||||
|
||||
@@ -22,9 +22,8 @@ class ExerciseLogReady extends ExerciseLogState {
|
||||
|
||||
class ExerciseLogError extends ExerciseLogState {
|
||||
final String message;
|
||||
const ExerciseLogError({this.message});
|
||||
|
||||
const ExerciseLogError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
@@ -12,7 +14,6 @@ import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:stop_watch_timer/stop_watch_timer.dart';
|
||||
|
||||
@@ -23,7 +24,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final CustomerRepository customerRepository;
|
||||
final MenuBloc menuBloc;
|
||||
AnimationController bmiAnimationController;
|
||||
late AnimationController bmiAnimationController;
|
||||
double quantity = 12;
|
||||
double unitQuantity = 30;
|
||||
double bmi = 0;
|
||||
@@ -35,11 +36,11 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
double bmiAngle = 0;
|
||||
double bmiTop = 0;
|
||||
double bmiLeft = 0;
|
||||
double weight;
|
||||
double height;
|
||||
late double weight;
|
||||
late double height;
|
||||
double bmrEnergy = 0;
|
||||
int birthYear;
|
||||
String fitnessLevel;
|
||||
late int birthYear;
|
||||
late String fitnessLevel;
|
||||
bool changedWeight = false;
|
||||
bool changedSizes = false;
|
||||
|
||||
@@ -53,23 +54,24 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
final StopWatchTimer stopWatchTimer = StopWatchTimer(
|
||||
isLapHours: false,
|
||||
);
|
||||
int timerValue;
|
||||
late int timerValue;
|
||||
|
||||
@override
|
||||
ExerciseNewBloc({this.exerciseRepository, this.menuBloc, this.customerRepository, ExerciseType exerciseType})
|
||||
ExerciseNewBloc(
|
||||
{required this.exerciseRepository, required this.menuBloc, required this.customerRepository, required ExerciseType exerciseType})
|
||||
: super(ExerciseNewInitial()) {
|
||||
exerciseRepository.exerciseType = exerciseType;
|
||||
exerciseRepository.setUnit(exerciseType.unit);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.exercise.exercisePlanDetailId = 0;
|
||||
exerciseRepository.exercise!.exercisePlanDetailId = 0;
|
||||
exerciseRepository.start = DateTime.now();
|
||||
if (Cache().userLoggedIn != null) {
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
weight = customerRepository.customer.getProperty("Weight");
|
||||
height = customerRepository.customer.getProperty("Height");
|
||||
birthYear = customerRepository.customer.birthYear;
|
||||
fitnessLevel = customerRepository.customer.fitnessLevel;
|
||||
birthYear = customerRepository.customer.birthYear!;
|
||||
fitnessLevel = customerRepository.customer.fitnessLevel!;
|
||||
}
|
||||
if (exerciseType.unit == "second") {
|
||||
stopWatchTimer.rawTime.listen((value) => {timerValue = value, this.setQuantity((value / 1000).toDouble())});
|
||||
@@ -151,7 +153,7 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
// exerciseRepository.initExercise();
|
||||
menuBloc.add(MenuTreeDown(parent: 0));
|
||||
Cache().initBadges();
|
||||
Track().track(TrackingEvent.exercise_new, eventValue: exerciseRepository.exerciseType.name);
|
||||
Track().track(TrackingEvent.exercise_new, eventValue: exerciseRepository.exerciseType!.name);
|
||||
yield ExerciseNewSaved();
|
||||
} else if (event is ExerciseNewBMIAnimate) {
|
||||
yield ExerciseNewLoading();
|
||||
@@ -183,10 +185,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
|
||||
if (customerRepository.customer.sex == "m") {
|
||||
//66.47 + ( 13.75 × tömeg kg-ban ) + ( 5.003 × magasság cm-ben ) − ( 6.755 × életkor évben kifejezve )
|
||||
bmr = 66.47 + (13.75 * weight) + (5.003 * height) - (6.755 * (year - customerRepository.customer.birthYear));
|
||||
bmr = 66.47 + (13.75 * weight) + (5.003 * height) - (6.755 * (year - customerRepository.customer.birthYear!));
|
||||
} else {
|
||||
//BMR = 655.1 + ( 9.563 × ömeg kg-ban ) + ( 1.85 × magasság cm-ben) − ( 4.676 × életkor évben kifejezve )
|
||||
bmr = 655.1 + (9.563 * weight) + (1.85 * height) - (4.676 * (year - customerRepository.customer.birthYear));
|
||||
bmr = 655.1 + (9.563 * weight) + (1.85 * height) - (4.676 * (year - customerRepository.customer.birthYear!));
|
||||
}
|
||||
bmrEnergy = bmr;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class ExerciseNewLoad extends ExerciseNewEvent {
|
||||
|
||||
class ExerciseNewQuantityChange extends ExerciseNewEvent {
|
||||
final double quantity;
|
||||
const ExerciseNewQuantityChange({this.quantity});
|
||||
const ExerciseNewQuantityChange({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -22,7 +22,7 @@ class ExerciseNewQuantityChange extends ExerciseNewEvent {
|
||||
|
||||
class ExerciseNewQuantityUnitChange extends ExerciseNewEvent {
|
||||
final double quantity;
|
||||
const ExerciseNewQuantityUnitChange({this.quantity});
|
||||
const ExerciseNewQuantityUnitChange({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -30,21 +30,21 @@ class ExerciseNewQuantityUnitChange extends ExerciseNewEvent {
|
||||
|
||||
class ExerciseNewBirthyearChange extends ExerciseNewEvent {
|
||||
final int value;
|
||||
const ExerciseNewBirthyearChange({this.value});
|
||||
const ExerciseNewBirthyearChange({required this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class ExerciseNewWeightChange extends ExerciseNewEvent {
|
||||
final double value;
|
||||
const ExerciseNewWeightChange({this.value});
|
||||
const ExerciseNewWeightChange({required this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class ExerciseNewHeightChange extends ExerciseNewEvent {
|
||||
final double value;
|
||||
const ExerciseNewHeightChange({this.value});
|
||||
const ExerciseNewHeightChange({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
@@ -52,7 +52,7 @@ class ExerciseNewHeightChange extends ExerciseNewEvent {
|
||||
|
||||
class ExerciseNewFitnessLevelChange extends ExerciseNewEvent {
|
||||
final String value;
|
||||
const ExerciseNewFitnessLevelChange({this.value});
|
||||
const ExerciseNewFitnessLevelChange({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
@@ -61,7 +61,7 @@ class ExerciseNewFitnessLevelChange extends ExerciseNewEvent {
|
||||
class ExerciseNewSizeChange extends ExerciseNewEvent {
|
||||
final String propertyName;
|
||||
final double value;
|
||||
const ExerciseNewSizeChange({this.propertyName, this.value});
|
||||
const ExerciseNewSizeChange({required this.propertyName, required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [propertyName, value];
|
||||
|
||||
@@ -26,7 +26,7 @@ class ExerciseNewSaved extends ExerciseNewState {
|
||||
|
||||
class ExerciseNewError extends ExerciseNewState {
|
||||
final String message;
|
||||
const ExerciseNewError({this.message});
|
||||
const ExerciseNewError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -17,15 +17,15 @@ part 'exercise_plan_state.dart';
|
||||
class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
late int customerId;
|
||||
|
||||
ExercisePlanBloc({this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
ExercisePlanBloc({required this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
await exercisePlanRepository.getLastExercisePlan();
|
||||
await exercisePlanRepository.getExercisePlanDetails();
|
||||
menuTreeRepository.sortedTree = null;
|
||||
menuTreeRepository.sortedTree.clear();
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
@@ -33,7 +33,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
ExercisePlanDetail planDetail = exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId);
|
||||
ExercisePlanDetail? planDetail = exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId);
|
||||
if (planDetail != null && planDetail.change != ModelChange.deleted) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
@@ -58,10 +58,8 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
yield ExercisePlanLoading();
|
||||
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
if (workoutTree != null) {
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!);
|
||||
workoutTree.selected = true;
|
||||
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanAddExercise) {
|
||||
@@ -76,7 +74,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = true;
|
||||
}
|
||||
});
|
||||
@@ -91,7 +89,7 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,20 +11,18 @@ class ExercisePlanLoad extends ExercisePlanEvent {
|
||||
const ExercisePlanLoad();
|
||||
}
|
||||
|
||||
|
||||
// update UI
|
||||
class ExercisePlanUpdateUI extends ExercisePlanEvent {
|
||||
final WorkoutMenuTree workoutTree;
|
||||
const ExercisePlanUpdateUI({this.workoutTree});
|
||||
const ExercisePlanUpdateUI({required this.workoutTree});
|
||||
|
||||
@override
|
||||
List<Object> get props => [workoutTree];
|
||||
}
|
||||
|
||||
|
||||
class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
const ExercisePlanRemoveExercise({this.exercisePlanDetail});
|
||||
const ExercisePlanRemoveExercise({required this.exercisePlanDetail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
@@ -32,8 +30,8 @@ class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
|
||||
class ExercisePlanAddExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
const ExercisePlanAddExercise({this.exercisePlanDetail});
|
||||
const ExercisePlanAddExercise({required this.exercisePlanDetail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
part of 'exercise_plan_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExercisePlanState extends Equatable{
|
||||
abstract class ExercisePlanState extends Equatable {
|
||||
const ExercisePlanState();
|
||||
|
||||
@override
|
||||
@@ -26,12 +26,8 @@ class ExercisePlanReady extends ExercisePlanState {
|
||||
// error splash screen
|
||||
class ExercisePlanError extends ExercisePlanState {
|
||||
final String message;
|
||||
const ExercisePlanError({this.message});
|
||||
const ExercisePlanError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,23 +22,30 @@ class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, Exercis
|
||||
final ExercisePlanBloc planBloc;
|
||||
final WorkoutMenuTree workoutMenuTree;
|
||||
|
||||
double quantity;
|
||||
double serie;
|
||||
double quantityUnit;
|
||||
late double quantity;
|
||||
double? serie;
|
||||
late double quantityUnit;
|
||||
|
||||
@override
|
||||
ExercisePlanCustomAddBloc({this.exercisePlanRepository, this.planBloc, this.workoutMenuTree}) : super(ExercisePlanCustomAddInitial()) {
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutMenuTree.exerciseType);
|
||||
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)
|
||||
ExercisePlanCustomAddBloc({required this.exercisePlanRepository, required this.planBloc, required this.workoutMenuTree})
|
||||
: super(ExercisePlanCustomAddInitial()) {
|
||||
// init();
|
||||
}
|
||||
|
||||
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;
|
||||
quantityUnit = exercisePlanRepository.getActualPlanDetail()!.weightEquation != null
|
||||
? double.parse(exercisePlanRepository.getActualPlanDetail()!.weightEquation!)
|
||||
: 30;
|
||||
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = quantityUnit.toString();
|
||||
exercisePlanRepository.getActualPlanDetail().serie = serie.toInt();
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = quantity.toInt();
|
||||
exercisePlanRepository.getActualPlanDetail()!.weightEquation = quantityUnit.toString();
|
||||
exercisePlanRepository.getActualPlanDetail()!.serie = serie!.toInt();
|
||||
exercisePlanRepository.getActualPlanDetail()!.repeats = quantity.toInt();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -46,36 +53,37 @@ class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, Exercis
|
||||
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();
|
||||
exercisePlanRepository.getActualPlanDetail()!.serie = event.quantity.toInt();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if (event is ExercisePlanCustomAddChangeQuantity) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
quantity = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = event.quantity.toInt();
|
||||
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);
|
||||
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;
|
||||
exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.add;
|
||||
} else {
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.update;
|
||||
exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.update;
|
||||
}
|
||||
exercisePlanRepository.addDetailToPlan();
|
||||
planBloc.add(ExercisePlanAddExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()));
|
||||
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()));
|
||||
exercisePlanRepository.getActualPlanDetail()!.change = ExercisePlanDetailChange.delete;
|
||||
planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()!));
|
||||
|
||||
yield ExercisePlanCustomAddReady();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class ExercisePlanCustomAddLoad extends ExercisePlanCustomAddEvent {
|
||||
|
||||
class ExercisePlanCustomAddChangeSerie extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeSerie({this.quantity});
|
||||
const ExercisePlanCustomAddChangeSerie({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -22,7 +22,7 @@ class ExercisePlanCustomAddChangeSerie extends ExercisePlanCustomAddEvent {
|
||||
|
||||
class ExercisePlanCustomAddChangeQuantity extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeQuantity({this.quantity});
|
||||
const ExercisePlanCustomAddChangeQuantity({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -30,7 +30,7 @@ class ExercisePlanCustomAddChangeQuantity extends ExercisePlanCustomAddEvent {
|
||||
|
||||
class ExercisePlanCustomAddChangeQuantityUnit extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeQuantityUnit({this.quantity});
|
||||
const ExercisePlanCustomAddChangeQuantityUnit({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -42,4 +42,4 @@ class ExercisePlanCustomAddSubmit extends ExercisePlanCustomAddEvent {
|
||||
|
||||
class ExercisePlanCustomAddRemove extends ExercisePlanCustomAddEvent {
|
||||
const ExercisePlanCustomAddRemove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ class ExercisePlanCustomAddReady extends ExercisePlanCustomAddState {
|
||||
|
||||
class ExercisePlanCustomAddError extends ExercisePlanCustomAddState {
|
||||
final String message;
|
||||
const ExercisePlanCustomAddError({this.message});
|
||||
|
||||
const ExercisePlanCustomAddError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
final bool isRegistration;
|
||||
bool dataPolicyAllowed = false;
|
||||
bool obscure = true;
|
||||
LoginBloc({this.accountBloc, this.userRepository, this.context, this.isRegistration}) : super(LoginInitial());
|
||||
|
||||
LoginBloc({required this.accountBloc, required this.userRepository, required this.context, required this.isRegistration})
|
||||
: super(LoginInitial());
|
||||
|
||||
@override
|
||||
Stream<LoginState> mapEventToState(
|
||||
@@ -43,7 +45,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
} else if (event is LoginSubmit) {
|
||||
yield LoginLoading();
|
||||
await userRepository.getUser();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
Track().track(TrackingEvent.login, eventValue: "email");
|
||||
Cache().setLoginType(LoginType.email);
|
||||
yield LoginSuccess();
|
||||
@@ -51,31 +53,30 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
yield LoginLoading();
|
||||
Cache().setLoginType(LoginType.fb);
|
||||
await userRepository.getUserByFB();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
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));
|
||||
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));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
Track().track(TrackingEvent.login, eventValue: "Apple");
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationSubmit) {
|
||||
yield LoginLoading();
|
||||
if (!this.dataPolicyAllowed) {
|
||||
yield LoginError();
|
||||
throw Exception("Please accept our data policy");
|
||||
}
|
||||
await userRepository.addUser();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "email");
|
||||
Cache().setLoginType(LoginType.email);
|
||||
@@ -83,36 +84,33 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
} else if (event is RegistrationFB) {
|
||||
yield LoginLoading();
|
||||
if (!this.dataPolicyAllowed) {
|
||||
yield LoginError();
|
||||
throw Exception("Please accept our data policy");
|
||||
}
|
||||
Cache().setLoginType(LoginType.fb);
|
||||
await userRepository.addUserFB();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "FB");
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationGoogle) {
|
||||
yield LoginLoading();
|
||||
if (!this.dataPolicyAllowed) {
|
||||
yield LoginError();
|
||||
throw Exception("Please accept our data policy");
|
||||
}
|
||||
Cache().setLoginType(LoginType.google);
|
||||
await userRepository.addUserGoogle();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "Google");
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationApple) {
|
||||
yield LoginLoading();
|
||||
if (!this.dataPolicyAllowed) {
|
||||
yield LoginError();
|
||||
throw Exception("Please accept our data policy");
|
||||
}
|
||||
Cache().setLoginType(LoginType.apple);
|
||||
await userRepository.addUserApple();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn));
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "Apple");
|
||||
|
||||
@@ -132,21 +130,18 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
}
|
||||
|
||||
Future<void> saveCustomer() async {
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
customerRepository.customer.dataPolicyAllowed = 1;
|
||||
await customerRepository.saveCustomer();
|
||||
}
|
||||
|
||||
String emailValidation(String email) {
|
||||
String message = Common.emailValidation(email);
|
||||
if (message != null) {
|
||||
message = t(message);
|
||||
}
|
||||
String? emailValidation(String email) {
|
||||
String? message = Common.emailValidation(email);
|
||||
return message;
|
||||
}
|
||||
|
||||
String passwordValidation(String value) {
|
||||
String message = Common.passwordValidation(value);
|
||||
String? passwordValidation(String value) {
|
||||
String? message = Common.passwordValidation(value);
|
||||
if (message != null) {
|
||||
message = t(message);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class LoginEvent extends Equatable {
|
||||
|
||||
class LoginEmailChange extends LoginEvent {
|
||||
final String email;
|
||||
const LoginEmailChange({this.email});
|
||||
const LoginEmailChange({required this.email});
|
||||
|
||||
@override
|
||||
List<Object> get props => [email];
|
||||
@@ -17,7 +17,7 @@ class LoginEmailChange extends LoginEvent {
|
||||
|
||||
class LoginPasswordChange extends LoginEvent {
|
||||
final String password;
|
||||
const LoginPasswordChange({this.password});
|
||||
const LoginPasswordChange({required this.password});
|
||||
|
||||
@override
|
||||
List<Object> get props => [password];
|
||||
@@ -45,7 +45,7 @@ class LoginApple extends LoginEvent {
|
||||
|
||||
class DataProtectionClicked extends LoginEvent {
|
||||
final bool marked;
|
||||
const DataProtectionClicked({this.marked});
|
||||
const DataProtectionClicked({required this.marked});
|
||||
}
|
||||
|
||||
class RegistrationSubmit extends LoginEvent {
|
||||
|
||||
@@ -25,7 +25,7 @@ class LoginSuccess extends LoginState {
|
||||
|
||||
class LoginError extends LoginState {
|
||||
final String message;
|
||||
const LoginError({this.message});
|
||||
const LoginError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -23,8 +23,8 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
ExerciseDeviceRepository exerciseDeviceRepository = ExerciseDeviceRepository();
|
||||
int parent = 0;
|
||||
WorkoutMenuTree workoutItem;
|
||||
final List<int> listFilterDevice = List();
|
||||
WorkoutMenuTree? workoutItem;
|
||||
final List<int> listFilterDevice = [];
|
||||
|
||||
String infoTitle = "";
|
||||
String infoText = "";
|
||||
@@ -32,13 +32,13 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
String infoText3 = "";
|
||||
String infoLink = "";
|
||||
int missingParent = 0;
|
||||
String missingTreeName = "";
|
||||
String? missingTreeName = "";
|
||||
|
||||
BuildContext context;
|
||||
late BuildContext context;
|
||||
|
||||
ExerciseAbility ability;
|
||||
ExerciseAbility? ability;
|
||||
|
||||
MenuBloc({this.menuTreeRepository}) : super(MenuInitial()) {
|
||||
MenuBloc({required this.menuTreeRepository}) : super(MenuInitial()) {
|
||||
parent = 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
exerciseRepository.getBaseExerciseFinishedPercent();
|
||||
percent = Cache().getPercentExercises();
|
||||
}
|
||||
if (context == null) return;
|
||||
|
||||
percent = percent * 100;
|
||||
//log("Percent " + percent.toString());
|
||||
if (percent == -1 || percent == 0) {
|
||||
@@ -78,7 +78,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
//log("Missing " + missingTreeName);
|
||||
if (missingTreeName != null) {
|
||||
if (percent > 0) {
|
||||
infoText = t("Please continue your tests with a") + " '" + missingTreeName + "' " + t("exercise!");
|
||||
infoText = t("Please continue your tests with a") + " '" + missingTreeName! + "' " + t("exercise!");
|
||||
infoLink = t("Bring me there");
|
||||
}
|
||||
}
|
||||
@@ -97,13 +97,13 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
yield MenuLoading();
|
||||
//await menuTreeRepository.createTree();
|
||||
//menuTreeRepository.getBranch(this.parent);
|
||||
setMenuInfo();
|
||||
exerciseDeviceRepository.setDevices(Cache().getDevices());
|
||||
//setMenuInfo();
|
||||
exerciseDeviceRepository.setDevices(Cache().getDevices()!);
|
||||
yield MenuReady();
|
||||
} else if (event is MenuRecreateTree) {
|
||||
yield MenuLoading();
|
||||
// ie. at language changes
|
||||
await menuTreeRepository.createTree();
|
||||
menuTreeRepository.createTree();
|
||||
yield MenuReady();
|
||||
} else if (event is MenuTreeDown) {
|
||||
yield MenuLoading();
|
||||
@@ -111,7 +111,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
workoutItem = event.item;
|
||||
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem.nameEnglish);
|
||||
setAbility(workoutItem!.nameEnglish);
|
||||
}
|
||||
final LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(event.parent);
|
||||
|
||||
@@ -126,8 +126,8 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
|
||||
LinkedHashMap<String, WorkoutMenuTree> branch;
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem.nameEnglish);
|
||||
branch = menuTreeRepository.getBranch(workoutItem.parent);
|
||||
setAbility(workoutItem!.nameEnglish);
|
||||
branch = menuTreeRepository.getBranch(workoutItem!.parent);
|
||||
await getImages(branch);
|
||||
}
|
||||
|
||||
@@ -138,12 +138,11 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
workoutItem = menuTreeRepository.getParentItem(parent);
|
||||
|
||||
if (workoutItem != null) {
|
||||
setAbility(workoutItem.nameEnglish);
|
||||
}
|
||||
final LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(workoutItem.parent);
|
||||
if (branch != null) {
|
||||
await getImages(branch);
|
||||
setAbility(workoutItem!.nameEnglish);
|
||||
}
|
||||
final LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(workoutItem!.parent);
|
||||
await getImages(branch);
|
||||
|
||||
yield MenuReady();
|
||||
} else if (event is MenuClickExercise) {
|
||||
yield MenuLoading();
|
||||
@@ -193,15 +192,15 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
|
||||
Future<void> putBranchImageToHash(LinkedHashMap<String, WorkoutMenuTree> branch) async {
|
||||
await Future.forEach(branch.keys, (key) async {
|
||||
final WorkoutMenuTree value = branch[key];
|
||||
if (!value.imageName.contains("asset")) {
|
||||
final WorkoutMenuTree? value = branch[key];
|
||||
if (value != null && !value.imageName.contains("asset")) {
|
||||
await wt.ImageCache().putImageToList(value.id, value.imageName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String getImage(int id, String name) {
|
||||
String imageString;
|
||||
String? getImage(int id, String name) {
|
||||
String? imageString;
|
||||
if (name.contains("http")) {
|
||||
imageString = wt.ImageCache().getImageString(id, name);
|
||||
}
|
||||
@@ -212,7 +211,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
return !listFilterDevice.contains(deviceId);
|
||||
}
|
||||
|
||||
LinkedHashMap<String, WorkoutMenuTree> getFilteredBranch(int parent) {
|
||||
LinkedHashMap<String, WorkoutMenuTree> getFilteredBranch(int? parent) {
|
||||
if (parent == null) return LinkedHashMap();
|
||||
|
||||
LinkedHashMap<String, WorkoutMenuTree> branch = menuTreeRepository.getBranch(parent);
|
||||
@@ -224,8 +223,8 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
branch.forEach((key, value) {
|
||||
final WorkoutMenuTree elem = value;
|
||||
if (elem.exerciseType != null) {
|
||||
for (int i = 0; i < elem.exerciseType.devices.length; i++) {
|
||||
if (listFilterDevice.contains(elem.exerciseType.devices[i])) {
|
||||
for (int i = 0; i < elem.exerciseType!.devices.length; i++) {
|
||||
if (listFilterDevice.contains(elem.exerciseType!.devices[i])) {
|
||||
filtered[elem.name] = elem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,26 +16,26 @@ class MenuCreate extends MenuEvent {
|
||||
}
|
||||
|
||||
class MenuTreeDown extends MenuEvent {
|
||||
final WorkoutMenuTree item;
|
||||
final WorkoutMenuTree? item;
|
||||
final int parent;
|
||||
const MenuTreeDown({this.parent, this.item});
|
||||
MenuTreeDown({required this.parent, this.item});
|
||||
|
||||
@override
|
||||
List<Object> get props => [parent, item];
|
||||
List<Object> get props => [parent];
|
||||
}
|
||||
|
||||
class MenuTreeUp extends MenuEvent {
|
||||
final int parent;
|
||||
final WorkoutMenuTree item;
|
||||
const MenuTreeUp({this.parent, this.item});
|
||||
final WorkoutMenuTree? item;
|
||||
const MenuTreeUp({required this.parent, this.item});
|
||||
|
||||
@override
|
||||
List<Object> get props => [parent, item];
|
||||
List<Object> get props => [parent];
|
||||
}
|
||||
|
||||
class MenuTreeJump extends MenuEvent {
|
||||
final int parent;
|
||||
const MenuTreeJump({this.parent});
|
||||
const MenuTreeJump({required this.parent});
|
||||
|
||||
@override
|
||||
List<Object> get props => [parent];
|
||||
@@ -43,7 +43,7 @@ class MenuTreeJump extends MenuEvent {
|
||||
|
||||
class MenuClickExercise extends MenuEvent {
|
||||
final int exerciseTypeId;
|
||||
const MenuClickExercise({this.exerciseTypeId});
|
||||
const MenuClickExercise({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
@@ -55,5 +55,5 @@ class MenuRecreateTree extends MenuEvent {
|
||||
|
||||
class MenuFilterExerciseType extends MenuEvent {
|
||||
final int deviceId;
|
||||
const MenuFilterExerciseType({this.deviceId});
|
||||
const MenuFilterExerciseType({required this.deviceId});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
part of 'menu_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class MenuState extends Equatable {
|
||||
abstract class MenuState extends Equatable {
|
||||
const MenuState();
|
||||
|
||||
@override
|
||||
@@ -12,22 +12,15 @@ class MenuInitial extends MenuState {
|
||||
const MenuInitial();
|
||||
}
|
||||
|
||||
class MenuLoading extends MenuState {
|
||||
|
||||
}
|
||||
class MenuLoading extends MenuState {}
|
||||
|
||||
class MenuReady extends MenuState {
|
||||
final WorkoutMenuTree workoutTree;
|
||||
|
||||
const MenuReady({this.workoutTree});
|
||||
|
||||
@override
|
||||
List<Object> get props => [workoutTree];
|
||||
const MenuReady();
|
||||
}
|
||||
|
||||
class MenuError extends MenuState {
|
||||
final String message;
|
||||
const MenuError({this.message});
|
||||
const MenuError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'password_reset_event.dart';
|
||||
part 'password_reset_state.dart';
|
||||
|
||||
class PasswordResetBloc extends Bloc<PasswordResetEvent, PasswordResetState> {
|
||||
final UserRepository userRepository;
|
||||
PasswordResetBloc({required this.userRepository}) : super(PasswordResetInitial());
|
||||
|
||||
@override
|
||||
Stream<PasswordResetState> 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 PasswordResetReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield PasswordResetError(message: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
String? emailValidation(String email) {
|
||||
String? message = Common.emailValidation(email);
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
part of 'password_reset_bloc.dart';
|
||||
|
||||
abstract class PasswordResetEvent extends Equatable {
|
||||
const PasswordResetEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class PasswordResetEmailChange extends PasswordResetEvent {
|
||||
final String email;
|
||||
const PasswordResetEmailChange({required this.email});
|
||||
|
||||
@override
|
||||
List<Object> get props => [email];
|
||||
}
|
||||
|
||||
class PasswordResetLoad extends PasswordResetEvent {
|
||||
const PasswordResetLoad();
|
||||
}
|
||||
|
||||
class PasswordResetSubmit extends PasswordResetEvent {
|
||||
const PasswordResetSubmit();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'password_reset_bloc.dart';
|
||||
|
||||
abstract class PasswordResetState extends Equatable {
|
||||
const PasswordResetState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class PasswordResetInitial extends PasswordResetState {
|
||||
const PasswordResetInitial();
|
||||
}
|
||||
|
||||
class PasswordResetLoading extends PasswordResetState {
|
||||
const PasswordResetLoading();
|
||||
}
|
||||
|
||||
class PasswordResetError extends PasswordResetState {
|
||||
final String message;
|
||||
const PasswordResetError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class PasswordResetReady extends PasswordResetState {
|
||||
const PasswordResetReady();
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
class ResetPasswordFormBloc extends FormBloc<String, String> with Common {
|
||||
final UserRepository userRepository;
|
||||
bool loading = false;
|
||||
|
||||
final emailField = TextFieldBloc(
|
||||
validators: [
|
||||
FieldBlocValidators.required,
|
||||
],
|
||||
);
|
||||
|
||||
ResetPasswordFormBloc({this.userRepository}) {
|
||||
addFieldBlocs(fieldBlocs: [emailField]);
|
||||
|
||||
emailField.onValueChanges(onData: (previous, current) async* {
|
||||
userRepository.setEmail(current.value);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onSubmitting() async {
|
||||
try {
|
||||
emitLoading(progress: 30);
|
||||
loading = true;
|
||||
if (!validateEmail(userRepository)) {
|
||||
emailField.addFieldError(EMAIL_ERROR, isPermanent: true);
|
||||
|
||||
emitFailure(failureResponse: EMAIL_ERROR);
|
||||
} else {
|
||||
// Emit either Loaded or Error
|
||||
await userRepository.resetPassword();
|
||||
emitSuccess(canSubmitAgain: false);
|
||||
}
|
||||
loading = false;
|
||||
} on Exception catch (ex) {
|
||||
emitFailure(failureResponse: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> close() {
|
||||
emailField.close();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
//import 'package:health/health.dart';
|
||||
|
||||
part 'result_event.dart';
|
||||
@@ -18,9 +18,9 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
final ExerciseResultRepository resultRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final BuildContext context;
|
||||
//List<HealthDataPoint> _healthDataList = List();
|
||||
DateTime startTime;
|
||||
DateTime endTime;
|
||||
//List<HealthDataPoint> _healthDataList = [];
|
||||
DateTime? startTime;
|
||||
DateTime? endTime;
|
||||
/* final HealthFactory health = HealthFactory();
|
||||
final List<HealthDataType> types = [
|
||||
HealthDataType.ACTIVE_ENERGY_BURNED,
|
||||
@@ -34,12 +34,12 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
HealthDataType.RESTING_HEART_RATE
|
||||
]; */
|
||||
|
||||
ResultBloc({this.resultRepository, this.exerciseRepository, this.context}) : super(ResultInitial()) {
|
||||
ResultBloc({required this.resultRepository, required this.exerciseRepository, required this.context}) : super(ResultInitial()) {
|
||||
this.startTime = exerciseRepository.start;
|
||||
this.endTime = exerciseRepository.end;
|
||||
if (this.startTime == null) {
|
||||
this.startTime = exerciseRepository.exercise.dateAdd;
|
||||
exerciseRepository.start = exerciseRepository.exercise.dateAdd;
|
||||
this.startTime = exerciseRepository.exercise!.dateAdd!;
|
||||
exerciseRepository.start = exerciseRepository.exercise!.dateAdd!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
resultRepository.getResults().forEach((element) {
|
||||
element.dateFrom = startTime;
|
||||
element.dateTo = endTime;
|
||||
element.exerciseId = exerciseRepository.actualExerciseList[0].exerciseId;
|
||||
element.exerciseId = exerciseRepository.actualExerciseList![0].exerciseId;
|
||||
switch (element.item) {
|
||||
case ResultItem.bpm_avg:
|
||||
//element.data = _gethHealthDataPointValueAvg(HealthDataType.HEART_RATE);
|
||||
@@ -80,11 +80,10 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
//element.data = _gethHealthDataPointValueSum(HealthDataType.ACTIVE_ENERGY_BURNED);
|
||||
break;
|
||||
case ResultItem.development_percent_bodypart:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case ResultItem.distance:
|
||||
if (exerciseRepository.exerciseType.unit == "meter") {
|
||||
element.data = exerciseRepository.exercise.quantity;
|
||||
if (exerciseRepository.exerciseType!.unit == "meter") {
|
||||
element.data = exerciseRepository.exercise!.quantity!;
|
||||
}
|
||||
break;
|
||||
case ResultItem.fatburn_percent:
|
||||
@@ -109,13 +108,12 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
} */
|
||||
break;
|
||||
case ResultItem.speed_max:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case ResultItem.reps_volume:
|
||||
if (exerciseRepository.exerciseType.unit == "repeat") {
|
||||
if (exerciseRepository.exerciseType!.unit == "repeat") {
|
||||
double value = 0;
|
||||
exerciseRepository.actualExerciseList.forEach((actual) {
|
||||
value += actual.quantity;
|
||||
exerciseRepository.actualExerciseList!.forEach((actual) {
|
||||
value += actual.quantity!;
|
||||
});
|
||||
element.data = value;
|
||||
}
|
||||
@@ -128,10 +126,10 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
element.data = _printDuration(duration);
|
||||
break; */
|
||||
case ResultItem.weight_volume:
|
||||
if (exerciseRepository.exerciseType.unitQuantityUnit == "kilogram") {
|
||||
if (exerciseRepository.exerciseType!.unitQuantityUnit == "kilogram") {
|
||||
double value = 0;
|
||||
exerciseRepository.actualExerciseList.forEach((actual) {
|
||||
value += actual.quantity * actual.unitQuantity;
|
||||
exerciseRepository.actualExerciseList!.forEach((actual) {
|
||||
value += actual.quantity! * actual.unitQuantity!;
|
||||
});
|
||||
element.data = value;
|
||||
}
|
||||
@@ -233,12 +231,12 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
}
|
||||
} */
|
||||
|
||||
double calculate1RM({double percent}) {
|
||||
double calculate1RM({double percent = 0.75}) {
|
||||
if (exerciseRepository.exercise == null) {
|
||||
exerciseRepository.getLastExercise();
|
||||
}
|
||||
double weight = exerciseRepository.exercise.unitQuantity;
|
||||
double repeat = exerciseRepository.exercise.quantity;
|
||||
double weight = exerciseRepository.exercise!.unitQuantity!;
|
||||
double repeat = exerciseRepository.exercise!.quantity!;
|
||||
if (weight == 0 || repeat == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class ResultReady extends ResultState {
|
||||
|
||||
class ResultError extends ResultState {
|
||||
final String error;
|
||||
const ResultError({this.error});
|
||||
const ResultError({required this.error});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.error];
|
||||
|
||||
@@ -8,21 +8,19 @@ import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/model/purchase.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/purchase_service.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/purchases.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flurry/flurry.dart';
|
||||
import 'package:purchases_flutter/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
part 'sales_state.dart';
|
||||
|
||||
class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
List<ProductTest> tests = List();
|
||||
List<Product> product2Display = List();
|
||||
List<ProductTest>? tests = [];
|
||||
List<Product> product2Display = [];
|
||||
int productSet = -1;
|
||||
SalesBloc() : super(SalesInitial());
|
||||
|
||||
@@ -35,7 +33,6 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
yield SalesLoading();
|
||||
log("Load Sales");
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
//await PlatformPurchaseApi().initPurchasePlatform();
|
||||
await RevenueCatPurchases().getOfferings();
|
||||
this.getProductSet();
|
||||
yield SalesReady();
|
||||
@@ -47,27 +44,30 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
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.toString());
|
||||
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());
|
||||
Common.sendMessage("Purchase: " + purchase.toJson().toString());
|
||||
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());
|
||||
}
|
||||
yield SalesSuccessful();
|
||||
} else {
|
||||
yield SalesError(message: "No selected product");
|
||||
}
|
||||
yield SalesSuccessful();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Product getSelectedProduct(int productId) {
|
||||
Product prod;
|
||||
Product? getSelectedProduct(int productId) {
|
||||
Product? prod;
|
||||
for (var product in this.product2Display) {
|
||||
if (product.productId == productId) {
|
||||
prod = product;
|
||||
@@ -78,7 +78,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
|
||||
String getLocalizedPrice(String productId) {
|
||||
String price = "";
|
||||
Offering offering = RevenueCatPurchases().offering;
|
||||
Offering? offering = RevenueCatPurchases().offering;
|
||||
if (offering != null) {
|
||||
for (var package in offering.availablePackages) {
|
||||
log("PlatformProduct " + package.toString());
|
||||
@@ -100,15 +100,19 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
void getProductSet() {
|
||||
int productId = 0;
|
||||
this.tests = Cache().productTests;
|
||||
List<Product>? products = Cache().products;
|
||||
if (products == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tests.isEmpty) {
|
||||
if (tests != null && tests!.isEmpty) {
|
||||
var rand = math.Random.secure();
|
||||
productSet = rand.nextInt(5) + 1;
|
||||
} else {
|
||||
trace("Previous ProductTest: " + tests[0].toJson().toString());
|
||||
productId = tests[0].productId;
|
||||
for (var elem in Cache().products) {
|
||||
final Product product = elem as Product;
|
||||
trace("Previous ProductTest: " + tests![0].toJson().toString());
|
||||
productId = tests![0].productId;
|
||||
for (var elem in products) {
|
||||
final Product product = elem;
|
||||
if (product.productId == productId) {
|
||||
productSet = product.productSet;
|
||||
break;
|
||||
@@ -120,12 +124,12 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
|
||||
productSet = 2;
|
||||
log("ProductSet: " + productSet.toString());
|
||||
for (var elem in Cache().products) {
|
||||
Product product = elem as Product;
|
||||
for (var elem in products) {
|
||||
Product product = elem;
|
||||
|
||||
if (product.productSet == productSet) {
|
||||
productId = product.productId;
|
||||
final String platformProductId = Platform.isAndroid ? product.productIdAndroid : product.productIdIos;
|
||||
final String platformProductId = Platform.isAndroid ? product.productIdAndroid! : product.productIdIos!;
|
||||
product.localizedPrice = getLocalizedPrice(platformProductId);
|
||||
product2Display.add(product);
|
||||
}
|
||||
@@ -136,7 +140,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
});
|
||||
|
||||
productTest.productId = productId;
|
||||
productTest.customerId = Cache().userLoggedIn.customerId;
|
||||
productTest.customerId = Cache().userLoggedIn!.customerId!;
|
||||
productTest.dateView = DateTime.now();
|
||||
//ProductTestApi().saveProductTest(productTest);
|
||||
//Cache().productTests.add(productTest);
|
||||
|
||||
@@ -13,5 +13,5 @@ class SalesLoad extends SalesEvent {
|
||||
|
||||
class SalesPurchase extends SalesEvent {
|
||||
final int productId;
|
||||
const SalesPurchase({this.productId});
|
||||
const SalesPurchase({required this.productId});
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class SalesSuccessful extends SalesState {
|
||||
|
||||
class SalesError extends SalesState {
|
||||
final String message;
|
||||
const SalesError({this.message});
|
||||
const SalesError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -13,7 +13,7 @@ part 'session_state.dart';
|
||||
class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
final Session session;
|
||||
|
||||
SessionBloc({this.session}) : super(SessionInitial());
|
||||
SessionBloc({required this.session}) : super(SessionInitial());
|
||||
|
||||
@override
|
||||
Stream<SessionState> mapEventToState(
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class SessionEvent extends Equatable {
|
||||
|
||||
class SessionStart extends SessionEvent {
|
||||
final SettingsBloc settingsBloc;
|
||||
const SessionStart({this.settingsBloc});
|
||||
const SessionStart({required this.settingsBloc});
|
||||
|
||||
@override
|
||||
List<Object> get props => [settingsBloc];
|
||||
|
||||
@@ -21,7 +21,7 @@ class SessionReady extends SessionState {
|
||||
|
||||
class SessionFailure extends SessionState {
|
||||
final String message;
|
||||
const SessionFailure({this.message});
|
||||
const SessionFailure({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -16,9 +16,9 @@ part 'settings_event.dart';
|
||||
part 'settings_state.dart';
|
||||
|
||||
class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
String language;
|
||||
Locale _locale;
|
||||
BuildContext context;
|
||||
String? language;
|
||||
Locale? _locale;
|
||||
BuildContext? context;
|
||||
|
||||
SettingsBloc({this.context}) : super(SettingsInitial());
|
||||
|
||||
@@ -26,7 +26,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
_locale = locale;
|
||||
}
|
||||
|
||||
Locale getLocale() {
|
||||
Locale? getLocale() {
|
||||
return _locale;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
if (event is SettingsChangeLanguage) {
|
||||
yield SettingsLoading();
|
||||
await _changeLang(event.language);
|
||||
yield SettingsReady(_locale);
|
||||
yield SettingsReady();
|
||||
} else if (event is SettingsGetLanguage) {
|
||||
await AppLanguage().fetchLocale();
|
||||
_locale = AppLanguage().appLocal;
|
||||
yield SettingsReady(_locale);
|
||||
yield SettingsReady();
|
||||
} else if (event is SettingsSetServer) {
|
||||
//yield SettingsLoading();
|
||||
final bool live = event.live;
|
||||
@@ -60,7 +60,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
await _accessHealthData();
|
||||
}
|
||||
Cache().initBadges();
|
||||
yield SettingsReady(_locale);
|
||||
yield SettingsReady();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,17 +97,17 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> with Logging {
|
||||
break;
|
||||
}
|
||||
this.language = lang;
|
||||
AppLanguage().changeLanguage(_locale);
|
||||
AppLanguage().changeLanguage(_locale!);
|
||||
await loadLang();
|
||||
await Cache().initBadges();
|
||||
Cache().initBadges();
|
||||
}
|
||||
|
||||
Future<void> loadLang() async {
|
||||
if (_locale != null) {
|
||||
log(" -- Loading lang $_locale");
|
||||
if (context != null) {
|
||||
AppLocalizations.of(context).setLocale(_locale);
|
||||
await AppLocalizations.of(context).load();
|
||||
AppLocalizations.of(context!)!.setLocale(_locale!);
|
||||
await AppLocalizations.of(context!)!.load();
|
||||
} else {
|
||||
log("no context, does not load");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class SettingsEvent extends Equatable {
|
||||
|
||||
class SettingsChangeLanguage extends SettingsEvent {
|
||||
final String language;
|
||||
const SettingsChangeLanguage({this.language});
|
||||
const SettingsChangeLanguage({required this.language});
|
||||
}
|
||||
|
||||
class SettingsGetLanguage extends SettingsEvent {
|
||||
@@ -18,7 +18,7 @@ class SettingsGetLanguage extends SettingsEvent {
|
||||
|
||||
class SettingsSetServer extends SettingsEvent {
|
||||
final bool live;
|
||||
const SettingsSetServer({this.live});
|
||||
const SettingsSetServer({required this.live});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.live];
|
||||
@@ -26,7 +26,7 @@ class SettingsSetServer extends SettingsEvent {
|
||||
|
||||
class SettingsSetHardware extends SettingsEvent {
|
||||
final bool hasHardware;
|
||||
const SettingsSetHardware({this.hasHardware});
|
||||
const SettingsSetHardware({required this.hasHardware});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.hasHardware];
|
||||
|
||||
@@ -10,31 +10,15 @@ abstract class SettingsState extends Equatable {
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class SettingsInitial extends SettingsState {
|
||||
Locale locale;
|
||||
SettingsInitial();
|
||||
|
||||
setLocale(locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [locale];
|
||||
}
|
||||
|
||||
class SettingsLoading extends SettingsState {
|
||||
final Locale locale;
|
||||
const SettingsLoading({this.locale});
|
||||
|
||||
@override
|
||||
List<Object> get props => [locale];
|
||||
const SettingsLoading();
|
||||
}
|
||||
|
||||
class SettingsReady extends SettingsState {
|
||||
final Locale locale;
|
||||
const SettingsReady(this.locale);
|
||||
|
||||
@override
|
||||
List<Object> get props => [locale];
|
||||
const SettingsReady();
|
||||
}
|
||||
|
||||
class SettingsError extends SettingsState {
|
||||
@@ -43,4 +27,4 @@ class SettingsError extends SettingsState {
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,30 +17,31 @@ class TestSetControlBloc extends Bloc<TestSetControlEvent, TestSetControlState>
|
||||
final TestSetExecuteBloc executeBloc;
|
||||
final ExerciseType exerciseType;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
TestSetControlBloc({this.exercisePlanDetail, this.executeBloc, this.exerciseType}) : super(TestSetControlInitial()) {
|
||||
|
||||
late double initQuantity;
|
||||
late double initUnitQuantity;
|
||||
late double quantity;
|
||||
late double unitQuantity;
|
||||
late double oneRepMax;
|
||||
late int step;
|
||||
|
||||
TestSetControlBloc({required this.exercisePlanDetail, required this.executeBloc, required this.exerciseType})
|
||||
: super(TestSetControlInitial()) {
|
||||
initBloc();
|
||||
}
|
||||
|
||||
void initBloc() {
|
||||
if (exercisePlanDetail.exerciseType.unitQuantity != null) {
|
||||
oneRepMax = executeBloc.calculate1RM(exercisePlanDetail.exercises.last.unitQuantity, exercisePlanDetail.exercises.last.quantity);
|
||||
initQuantity = 12;
|
||||
quantity = initQuantity;
|
||||
initUnitQuantity = oneRepMax * 0.75;
|
||||
unitQuantity = initUnitQuantity;
|
||||
}
|
||||
step = exercisePlanDetail.exercises.length;
|
||||
oneRepMax = executeBloc.calculate1RM(exercisePlanDetail.exercises!.last.unitQuantity, exercisePlanDetail.exercises!.last.quantity);
|
||||
initQuantity = 12;
|
||||
quantity = initQuantity;
|
||||
initUnitQuantity = oneRepMax * 0.75;
|
||||
unitQuantity = initUnitQuantity;
|
||||
|
||||
step = exercisePlanDetail.exercises!.length;
|
||||
exerciseRepository.customer = Cache().userLoggedIn;
|
||||
exerciseRepository.exerciseType = exerciseType;
|
||||
}
|
||||
|
||||
double initQuantity;
|
||||
double initUnitQuantity;
|
||||
double quantity;
|
||||
double unitQuantity;
|
||||
double oneRepMax;
|
||||
int step;
|
||||
|
||||
@override
|
||||
Stream<TestSetControlState> mapEventToState(
|
||||
TestSetControlEvent event,
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestSetControlLoad extends TestSetControlEvent {
|
||||
|
||||
class TestSetControlQuantityChange extends TestSetControlEvent {
|
||||
final double quantity;
|
||||
const TestSetControlQuantityChange({this.quantity});
|
||||
const TestSetControlQuantityChange({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -21,7 +21,7 @@ class TestSetControlQuantityChange extends TestSetControlEvent {
|
||||
|
||||
class TestSetControlUnitQuantityChange extends TestSetControlEvent {
|
||||
final double quantity;
|
||||
const TestSetControlUnitQuantityChange({this.quantity});
|
||||
const TestSetControlUnitQuantityChange({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestSetControlReady extends TestSetControlState {
|
||||
|
||||
class TestSetControlError extends TestSetControlState {
|
||||
final String message;
|
||||
const TestSetControlError({this.message});
|
||||
const TestSetControlError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -21,14 +21,15 @@ part 'test_set_edit_state.dart';
|
||||
class TestSetEditBloc extends Bloc<TestSetEditEvent, TestSetEditState> {
|
||||
final String templateName;
|
||||
final String templateNameTranslation;
|
||||
String templateDescription;
|
||||
late String templateDescription;
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
final MenuBloc menuBloc;
|
||||
final List<ExerciseType> _exerciseTypes = List();
|
||||
final List<ExerciseType> _actualExerciseTypes = List();
|
||||
final HashMap<int, ExerciseType> _exercisePlanDetails = HashMap();
|
||||
final List<ExerciseType> _exerciseTypes = [];
|
||||
final List<ExerciseType> _actualExerciseTypes = [];
|
||||
final HashMap<int, ExerciseType?> _exercisePlanDetails = HashMap();
|
||||
|
||||
TestSetEditBloc({this.templateName, this.templateNameTranslation, this.workoutTreeRepository, this.menuBloc})
|
||||
TestSetEditBloc(
|
||||
{required this.templateName, required this.templateNameTranslation, required this.workoutTreeRepository, required this.menuBloc})
|
||||
: super(TestSetEditInitial()) {
|
||||
if (Cache().exercisePlanTemplates.isNotEmpty) {
|
||||
Cache().exercisePlanTemplates.forEach((element) {
|
||||
@@ -36,10 +37,12 @@ class TestSetEditBloc extends Bloc<TestSetEditEvent, TestSetEditState> {
|
||||
if (template.name == templateName) {
|
||||
templateDescription = template.descriptionTranslation;
|
||||
template.exerciseTypes.forEach((id) {
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(id);
|
||||
_exerciseTypes.add(exerciseType);
|
||||
_actualExerciseTypes.add(exerciseType);
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = exerciseType;
|
||||
final ExerciseType? exerciseType = Cache().getExerciseTypeById(id);
|
||||
if (exerciseType != null) {
|
||||
_exerciseTypes.add(exerciseType);
|
||||
_actualExerciseTypes.add(exerciseType);
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = exerciseType;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -52,17 +55,18 @@ class TestSetEditBloc extends Bloc<TestSetEditEvent, TestSetEditState> {
|
||||
if (event is TestSetEditChangeExerciseType) {
|
||||
yield TestSetEditLoading();
|
||||
final List<ExerciseType> alternatives = workoutTreeRepository.getExerciseTypeAlternatives(event.exerciseTypeId);
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId);
|
||||
|
||||
if (_exercisePlanDetails[event.exerciseTypeId] == null) {
|
||||
/// it was skipped
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = exerciseType;
|
||||
} else {
|
||||
if (event.index == 0) {
|
||||
final ExerciseType? exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId);
|
||||
if (exerciseType != null) {
|
||||
if (_exercisePlanDetails[event.exerciseTypeId] == null) {
|
||||
/// it was skipped
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = exerciseType;
|
||||
} else {
|
||||
final changedExerciseType = alternatives[event.index - 1];
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = changedExerciseType;
|
||||
if (event.index == 0) {
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = exerciseType;
|
||||
} else {
|
||||
final changedExerciseType = alternatives[event.index - 1];
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = changedExerciseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,28 +75,30 @@ class TestSetEditBloc extends Bloc<TestSetEditEvent, TestSetEditState> {
|
||||
yield TestSetEditReady();
|
||||
} else if (event is TestSetEditDeleteExerciseType) {
|
||||
yield TestSetEditLoading();
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId);
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = null;
|
||||
final ExerciseType? exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId);
|
||||
if (exerciseType != null) {
|
||||
_exercisePlanDetails[exerciseType.exerciseTypeId] = null;
|
||||
}
|
||||
refreshActualPlan();
|
||||
yield TestSetEditReady();
|
||||
} else if (event is TestSetEditSubmit) {
|
||||
yield TestSetEditLoading();
|
||||
ExercisePlan exercisePlan = ExercisePlan(templateNameTranslation, Cache().userLoggedIn.customerId);
|
||||
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<ExercisePlanDetail> details = List();
|
||||
List<ExercisePlanDetail> details = [];
|
||||
for (var entry in _exercisePlanDetails.entries) {
|
||||
if (entry.value != null) {
|
||||
ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(entry.value.exerciseTypeId);
|
||||
exercisePlanDetail.exercisePlanId = savedExercisePlan.exercisePlanId;
|
||||
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 = List();
|
||||
exercisePlanDetail.exercises = [];
|
||||
details.add(exercisePlanDetail);
|
||||
}
|
||||
}
|
||||
@@ -112,8 +118,10 @@ class TestSetEditBloc extends Bloc<TestSetEditEvent, TestSetEditState> {
|
||||
void refreshActualPlan() {
|
||||
_actualExerciseTypes.removeRange(0, _actualExerciseTypes.length - 1);
|
||||
_exercisePlanDetails.keys.forEach((element) {
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(element);
|
||||
_actualExerciseTypes.add(exerciseType);
|
||||
final ExerciseType? exerciseType = Cache().getExerciseTypeById(element);
|
||||
if (exerciseType != null) {
|
||||
_actualExerciseTypes.add(exerciseType);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestSetEditLoad extends TestSetEditEvent {
|
||||
class TestSetEditChangeExerciseType extends TestSetEditEvent {
|
||||
final int index;
|
||||
final int exerciseTypeId;
|
||||
const TestSetEditChangeExerciseType({this.index, this.exerciseTypeId});
|
||||
const TestSetEditChangeExerciseType({required this.index, required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [index, exerciseTypeId];
|
||||
@@ -22,7 +22,7 @@ class TestSetEditChangeExerciseType extends TestSetEditEvent {
|
||||
|
||||
class TestSetEditDeleteExerciseType extends TestSetEditEvent {
|
||||
final int exerciseTypeId;
|
||||
const TestSetEditDeleteExerciseType({this.exerciseTypeId});
|
||||
const TestSetEditDeleteExerciseType({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
@@ -30,7 +30,7 @@ class TestSetEditDeleteExerciseType extends TestSetEditEvent {
|
||||
|
||||
class TestSetEditSkipExerciseType extends TestSetEditEvent {
|
||||
final int exerciseTypeId;
|
||||
const TestSetEditSkipExerciseType({this.exerciseTypeId});
|
||||
const TestSetEditSkipExerciseType({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestSetEditLoading extends TestSetEditState {
|
||||
|
||||
class TestSetEditError extends TestSetEditState {
|
||||
final String message;
|
||||
const TestSetEditError({this.message});
|
||||
const TestSetEditError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -18,17 +18,17 @@ part 'test_set_execute_state.dart';
|
||||
|
||||
class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState> {
|
||||
// ignore: close_sinks
|
||||
MenuBloc menuBloc;
|
||||
int exerciseTypeId;
|
||||
String testName;
|
||||
late MenuBloc menuBloc;
|
||||
int? exerciseTypeId;
|
||||
String? testName;
|
||||
String testType = "";
|
||||
bool miniTestSet = false;
|
||||
bool paralellTest = false;
|
||||
double scrollOffset = 0;
|
||||
ExercisePlan exercisePlan;
|
||||
ExercisePlan? exercisePlan;
|
||||
bool isDone100 = false;
|
||||
|
||||
List<ExercisePlanDetail> exercisePlanDetails;
|
||||
List<ExercisePlanDetail>? exercisePlanDetails;
|
||||
|
||||
TestSetExecuteBloc() : super(TestSetExecuteInitial());
|
||||
|
||||
@@ -37,19 +37,19 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
void initExercisePlan() {
|
||||
exercisePlan = Cache().activeExercisePlan;
|
||||
if (exercisePlan != null) {
|
||||
testName = exercisePlan.name;
|
||||
this.miniTestSet = exercisePlan.type != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan.type);
|
||||
this.paralellTest = exercisePlan.type != null && ExerciseAbility.paralell_test.equalsStringTo(exercisePlan.type);
|
||||
testName = exercisePlan!.name;
|
||||
this.miniTestSet = exercisePlan!.type != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan!.type!);
|
||||
this.paralellTest = exercisePlan!.type != null && ExerciseAbility.paralell_test.equalsStringTo(exercisePlan!.type!);
|
||||
|
||||
testType = ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan.type)
|
||||
testType = ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan!.type!)
|
||||
? ExerciseAbility.mini_test_set.description
|
||||
: ExerciseAbility.paralell_test.description;
|
||||
print("exercisePlan: $testName type: $testType");
|
||||
}
|
||||
exercisePlanDetails = Cache().activeExercisePlanDetails;
|
||||
if (exercisePlanDetails != null) {
|
||||
exercisePlanDetails.forEach((element) {
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(element.exerciseTypeId);
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
final ExerciseType? exerciseType = Cache().getExerciseTypeById(element.exerciseTypeId);
|
||||
if (exerciseType != null) {
|
||||
element.exerciseType = exerciseType;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
if (exerciseTypeId != null) {
|
||||
int step = 0;
|
||||
if (exercisePlanDetails != null) {
|
||||
exercisePlanDetails.forEach((element) {
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (element.exerciseTypeId == this.exerciseTypeId) {
|
||||
scrollOffset = (step * 85).toDouble() + 10;
|
||||
}
|
||||
@@ -79,44 +79,44 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
}
|
||||
yield TestSetExecuteReady();
|
||||
} else if (event is TestSetExecuteDeleteActive) {
|
||||
print("Delete: ${exercisePlan.type} paralellTest: $paralellTest");
|
||||
if (exercisePlan != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan.type)) {
|
||||
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);
|
||||
exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1);
|
||||
}
|
||||
await Cache().deleteActiveExercisePlan();
|
||||
}
|
||||
} else if (event is TestSetExecuteDeleteAllActive) {
|
||||
print("DeleteAll Test Set: ${exercisePlan.type}");
|
||||
if (exercisePlan != null) {
|
||||
print("DeleteAll Test Set: ${exercisePlan!.type}");
|
||||
exercisePlan = null;
|
||||
if (exercisePlanDetails != null) {
|
||||
exercisePlanDetails.removeRange(0, exercisePlanDetails.length - 1);
|
||||
exercisePlanDetails!.removeRange(0, exercisePlanDetails!.length - 1);
|
||||
}
|
||||
await Cache().deleteActiveExercisePlan();
|
||||
}
|
||||
} else if (event is TestSetExecuteExerciseFinished) {
|
||||
yield TestSetExecuteLoading();
|
||||
exercisePlanDetails.forEach((element) {
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (element.exerciseTypeId == event.exerciseTypeId) {
|
||||
element.repeats = event.quantity.toInt();
|
||||
element.weightEquation = event.unitQuantity.toString();
|
||||
if (element.exercises == null) {
|
||||
element.exercises = List();
|
||||
element.exercises = [];
|
||||
}
|
||||
final Exercise exercise = Exercise();
|
||||
exercise.customerId = Cache().userLoggedIn.customerId;
|
||||
exercise.customerId = Cache().userLoggedIn!.customerId!;
|
||||
exercise.exerciseTypeId = event.exerciseTypeId;
|
||||
exercise.quantity = event.quantity;
|
||||
exercise.unit = element.exerciseType.unit;
|
||||
exercise.unit = element.exerciseType!.unit;
|
||||
exercise.unitQuantity = event.unitQuantity;
|
||||
exercise.dateAdd = DateTime.now();
|
||||
element.exercises.add(exercise);
|
||||
element.exercises!.add(exercise);
|
||||
setPlanDetailState(element);
|
||||
}
|
||||
});
|
||||
Cache().saveActiveExercisePlan(exercisePlan, exercisePlanDetails);
|
||||
Cache().saveActiveExercisePlan(exercisePlan!, exercisePlanDetails!);
|
||||
if (this.isDone100Percent()) {
|
||||
add(TestSetExecuteFinish());
|
||||
} else {
|
||||
@@ -125,45 +125,51 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
} 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 = 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 = List();
|
||||
exercisePlanDetails = [];
|
||||
}
|
||||
|
||||
if (!this.existsInPlanDetails(event.exerciseTypeId)) {
|
||||
ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(event.exerciseTypeId);
|
||||
exercisePlanDetail.exercisePlanId = exercisePlan.exercisePlanId;
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId);
|
||||
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 = List();
|
||||
exercisePlanDetails.add(exercisePlanDetail);
|
||||
await Cache().saveActiveExercisePlan(exercisePlan, exercisePlanDetails);
|
||||
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;
|
||||
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();
|
||||
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();
|
||||
@@ -181,9 +187,9 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
bool hasBegun() {
|
||||
if (exercisePlanDetails == null ||
|
||||
exercisePlanDetails.isEmpty ||
|
||||
exercisePlanDetails[0].exercises == null ||
|
||||
exercisePlanDetails[0].exercises.length == 0) {
|
||||
exercisePlanDetails!.isEmpty ||
|
||||
exercisePlanDetails![0].exercises == null ||
|
||||
exercisePlanDetails![0].exercises!.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -191,14 +197,14 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
}
|
||||
|
||||
void setPlanDetailState(ExercisePlanDetail exercisePlanDetail) {
|
||||
if (exercisePlanDetail.exercises == null || exercisePlanDetail.exercises.length == 0) {
|
||||
if (exercisePlanDetail.exercises == null || exercisePlanDetail.exercises!.length == 0) {
|
||||
exercisePlanDetail.state = ExercisePlanDetailState.start;
|
||||
} else {
|
||||
int maxLength = 1;
|
||||
if (exercisePlanDetail.exerciseType.unitQuantityUnit != null) {
|
||||
if (exercisePlanDetail.exerciseType!.unitQuantityUnit != null) {
|
||||
maxLength = 4;
|
||||
}
|
||||
if (exercisePlanDetail.exercises.length >= maxLength) {
|
||||
if (exercisePlanDetail.exercises!.length >= maxLength) {
|
||||
exercisePlanDetail.state = ExercisePlanDetailState.finished;
|
||||
} else {
|
||||
exercisePlanDetail.state = ExercisePlanDetailState.inProgress;
|
||||
@@ -208,7 +214,8 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
ExercisePlanDetailState actualState(int exerciseTypeId) {
|
||||
ExercisePlanDetailState state = ExercisePlanDetailState.start;
|
||||
exercisePlanDetails.forEach((element) {
|
||||
if (exercisePlanDetails == null) return state;
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
state = element.state;
|
||||
}
|
||||
@@ -218,7 +225,8 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
bool existsInPlanDetails(int exerciseTypeId) {
|
||||
bool found = false;
|
||||
exercisePlanDetails.forEach((element) {
|
||||
if (exercisePlanDetails == null) return found;
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
found = true;
|
||||
}
|
||||
@@ -226,9 +234,11 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
return found;
|
||||
}
|
||||
|
||||
ExercisePlanDetail actualExercisePlanDetail(int exerciseTypeId) {
|
||||
ExercisePlanDetail found;
|
||||
exercisePlanDetails.forEach((element) {
|
||||
ExercisePlanDetail? actualExercisePlanDetail(int exerciseTypeId) {
|
||||
ExercisePlanDetail? found;
|
||||
if (exercisePlanDetails == null) return found;
|
||||
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
found = element;
|
||||
}
|
||||
@@ -238,10 +248,10 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
bool isDone100Percent() {
|
||||
bool done = true;
|
||||
if (exercisePlanDetails == null || exercisePlanDetails.isEmpty) {
|
||||
if (exercisePlanDetails == null || exercisePlanDetails!.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
exercisePlanDetails.forEach((element) {
|
||||
exercisePlanDetails!.forEach((element) {
|
||||
if (!element.state.equalsTo(ExercisePlanDetailState.finished)) {
|
||||
done = false;
|
||||
}
|
||||
@@ -251,7 +261,7 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
HashMap canAddNewExercise() {
|
||||
HashMap ret = HashMap();
|
||||
if (exercisePlan != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan.type)) {
|
||||
if (exercisePlan != null && ExerciseAbility.mini_test_set.equalsStringTo(exercisePlan!.type!)) {
|
||||
final String message = "You have an active Test Set!";
|
||||
final String message2 = "Do you want you to override it?";
|
||||
ret['message'] = message;
|
||||
@@ -264,8 +274,8 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getActualWorkoutTreeId(int exerciseTypeId) {
|
||||
final WorkoutMenuTree workoutTree = this.menuBloc.menuTreeRepository.getMenuItemByExerciseTypeId(exerciseTypeId);
|
||||
int? getActualWorkoutTreeId(int exerciseTypeId) {
|
||||
final WorkoutMenuTree? workoutTree = this.menuBloc.menuTreeRepository.getMenuItemByExerciseTypeId(exerciseTypeId);
|
||||
if (workoutTree == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -276,7 +286,7 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
if (exerciseTypeId <= 0) {
|
||||
return "";
|
||||
}
|
||||
final WorkoutMenuTree workoutTree = this.menuBloc.menuTreeRepository.getMenuItemByExerciseTypeId(exerciseTypeId);
|
||||
final WorkoutMenuTree? workoutTree = this.menuBloc.menuTreeRepository.getMenuItemByExerciseTypeId(exerciseTypeId);
|
||||
if (workoutTree == null) {
|
||||
return "";
|
||||
}
|
||||
@@ -288,14 +298,14 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
if (exercisePlanDetails == null) {
|
||||
return true;
|
||||
}
|
||||
if (exercisePlanDetails.isEmpty) {
|
||||
if (exercisePlanDetails!.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
return (exercisePlanDetails[0].exercises == null || exercisePlanDetails[0].exercises.length == 0);
|
||||
return (exercisePlanDetails![0].exercises == null || exercisePlanDetails![0].exercises!.length == 0);
|
||||
}
|
||||
|
||||
bool existsActivePlan() {
|
||||
final bool exists = exercisePlan != null && exercisePlanDetails.length > 0;
|
||||
final bool exists = exercisePlan != null && exercisePlanDetails != null && exercisePlanDetails!.isNotEmpty;
|
||||
print("Exists active plan: $exists");
|
||||
return exists;
|
||||
}
|
||||
@@ -304,20 +314,22 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
return (exercisePlanDetail.state.equalsTo(ExercisePlanDetailState.finished));
|
||||
}
|
||||
|
||||
ExercisePlanDetail getNext() {
|
||||
ExercisePlanDetail nextExercisePlanDetail;
|
||||
ExercisePlanDetail? getNext() {
|
||||
ExercisePlanDetail? nextExercisePlanDetail;
|
||||
int minStep = 99;
|
||||
for (final detail in this.exercisePlanDetails) {
|
||||
if (!detail.state.equalsTo(ExercisePlanDetailState.finished)) {
|
||||
if (detail.exercises == null) {
|
||||
nextExercisePlanDetail = detail;
|
||||
minStep = 1;
|
||||
break;
|
||||
} else {
|
||||
final int step = detail.exercises.length;
|
||||
if (step < minStep) {
|
||||
if (this.exercisePlanDetails == null) {
|
||||
for (final detail in this.exercisePlanDetails!) {
|
||||
if (!detail.state.equalsTo(ExercisePlanDetailState.finished)) {
|
||||
if (detail.exercises == null) {
|
||||
nextExercisePlanDetail = detail;
|
||||
minStep = step;
|
||||
minStep = 1;
|
||||
break;
|
||||
} else {
|
||||
final int step = detail.exercises!.length;
|
||||
if (step < minStep) {
|
||||
nextExercisePlanDetail = detail;
|
||||
minStep = step;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,10 +353,10 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
String repeatTimesText(ExercisePlanDetail exercisePlanDetail) {
|
||||
String text = "maximum";
|
||||
if (!hasBegun() || exercisePlanDetail.exerciseType.unitQuantityUnit == null) {
|
||||
if (!hasBegun() || exercisePlanDetail.exerciseType!.unitQuantityUnit == null) {
|
||||
return text;
|
||||
}
|
||||
int step = exercisePlanDetail.exercises.length;
|
||||
int step = exercisePlanDetail.exercises!.length;
|
||||
print("repeatTimes step $step");
|
||||
if (step == 2) {
|
||||
text = "12";
|
||||
@@ -354,13 +366,13 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
String getExerciseWeight(ExercisePlanDetail exercisePlanDetail) {
|
||||
String text = "you are able to do 12-20 repeats with";
|
||||
if (!hasBegun() || exercisePlanDetail.exercises.length < 2) {
|
||||
if (!hasBegun() || exercisePlanDetail.exercises!.length < 2) {
|
||||
return text;
|
||||
}
|
||||
final double unitQuantity = exercisePlanDetail.exercises.last.unitQuantity;
|
||||
final double quantity = exercisePlanDetail.exercises.last.quantity;
|
||||
final double unitQuantity = exercisePlanDetail.exercises!.last.unitQuantity;
|
||||
final double quantity = exercisePlanDetail.exercises!.last.quantity;
|
||||
double oneRepMax = this.calculate1RM(quantity, unitQuantity);
|
||||
text = (oneRepMax * 0.75).round().toStringAsFixed(0) + " " + exercisePlanDetail.exerciseType.unitQuantityUnit;
|
||||
text = (oneRepMax * 0.75).round().toStringAsFixed(0) + " " + exercisePlanDetail.exerciseType!.unitQuantityUnit!;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestSetExecuteLoad extends TestSetExecuteEvent {
|
||||
|
||||
class TestSetExecuteExecute extends TestSetExecuteEvent {
|
||||
final int exerciseTypeId;
|
||||
const TestSetExecuteExecute({this.exerciseTypeId});
|
||||
const TestSetExecuteExecute({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
@@ -27,7 +27,7 @@ class TestSetExecuteExerciseFinished extends TestSetExecuteEvent {
|
||||
final int exerciseTypeId;
|
||||
final double quantity;
|
||||
final double unitQuantity;
|
||||
const TestSetExecuteExerciseFinished({this.exerciseTypeId, this.quantity, this.unitQuantity});
|
||||
const TestSetExecuteExerciseFinished({required this.exerciseTypeId, required this.quantity, required this.unitQuantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId, quantity, unitQuantity];
|
||||
@@ -35,7 +35,7 @@ class TestSetExecuteExerciseFinished extends TestSetExecuteEvent {
|
||||
|
||||
class TestSetExecuteNewExercise extends TestSetExecuteEvent {
|
||||
final int exerciseTypeId;
|
||||
const TestSetExecuteNewExercise({this.exerciseTypeId});
|
||||
const TestSetExecuteNewExercise({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
@@ -43,7 +43,7 @@ class TestSetExecuteNewExercise extends TestSetExecuteEvent {
|
||||
|
||||
class TestSetExecuteDeleteExercise extends TestSetExecuteEvent {
|
||||
final int exerciseTypeId;
|
||||
const TestSetExecuteDeleteExercise({this.exerciseTypeId});
|
||||
const TestSetExecuteDeleteExercise({required this.exerciseTypeId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseTypeId];
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestSetExecuteReady extends TestSetExecuteState {
|
||||
|
||||
class TestSetExecuteError extends TestSetExecuteState {
|
||||
final String message;
|
||||
const TestSetExecuteError({this.message});
|
||||
const TestSetExecuteError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -18,21 +18,23 @@ class TestSetNewBloc extends Bloc<TestSetNewEvent, TestSetNewState> {
|
||||
final int exercisePlanDetailId;
|
||||
final TestSetExecuteBloc executeBloc;
|
||||
|
||||
TestSetNewBloc({this.exerciseRepository, this.exerciseType, this.exercisePlanDetailId, this.executeBloc}) : super(TestSetNewInitial()) {
|
||||
late double quantity;
|
||||
late double unitQuantity;
|
||||
|
||||
TestSetNewBloc(
|
||||
{required this.exerciseRepository, required this.exerciseType, required this.exercisePlanDetailId, required this.executeBloc})
|
||||
: super(TestSetNewInitial()) {
|
||||
exerciseRepository.exerciseType = exerciseType;
|
||||
quantity = 12;
|
||||
unitQuantity = 30;
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnit(exerciseType.unit);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.exercise.exercisePlanDetailId = exercisePlanDetailId;
|
||||
exerciseRepository.exercise!.exercisePlanDetailId = exercisePlanDetailId;
|
||||
exerciseRepository.start = DateTime.now();
|
||||
exerciseRepository.setCustomer(Cache().userLoggedIn);
|
||||
exerciseRepository.setCustomer(Cache().userLoggedIn!);
|
||||
}
|
||||
|
||||
double quantity;
|
||||
double unitQuantity;
|
||||
|
||||
@override
|
||||
Stream<TestSetNewState> mapEventToState(
|
||||
TestSetNewEvent event,
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestSetNewLoad extends TestSetNewEvent {
|
||||
|
||||
class TestSetNewChangeQuantity extends TestSetNewEvent {
|
||||
final double quantity;
|
||||
const TestSetNewChangeQuantity({this.quantity});
|
||||
const TestSetNewChangeQuantity({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
@@ -21,7 +21,7 @@ class TestSetNewChangeQuantity extends TestSetNewEvent {
|
||||
|
||||
class TestSetNewChangeQuantityUnit extends TestSetNewEvent {
|
||||
final double quantity;
|
||||
const TestSetNewChangeQuantityUnit({this.quantity});
|
||||
const TestSetNewChangeQuantityUnit({required this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestSetNewReady extends TestSetNewState {
|
||||
|
||||
class TestSetNewError extends TestSetNewState {
|
||||
final String message;
|
||||
const TestSetNewError({this.message});
|
||||
const TestSetNewError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:audioplayer/audioplayer.dart';
|
||||
//import 'package:audioplayer/audioplayer.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
@@ -8,7 +8,7 @@ part 'timer_event.dart';
|
||||
part 'timer_state.dart';
|
||||
|
||||
class Ticker {
|
||||
Stream<int> tick({int ticks}) {
|
||||
Stream<int> tick({required int ticks}) {
|
||||
return Stream.periodic(Duration(seconds: 1), (x) => compute(ticks, x)).take(ticks);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
|
||||
final Ticker _ticker = Ticker();
|
||||
int _duration = 0;
|
||||
|
||||
final AudioPlayer audioPlayer = AudioPlayer();
|
||||
//final AudioPlayer audioPlayer = AudioPlayer();
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
|
||||
StreamSubscription<int> _tickerSubscription;
|
||||
// ignore: cancel_subscriptions
|
||||
StreamSubscription<int>? _tickerSubscription;
|
||||
|
||||
TimerBloc() : super(TimerReady(300));
|
||||
|
||||
@@ -52,21 +53,27 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
|
||||
yield* _mapTickToState(event);
|
||||
} else if (event is TimerEnd) {
|
||||
print("$event");
|
||||
_tickerSubscription?.cancel();
|
||||
if (_tickerSubscription != null) {
|
||||
_tickerSubscription!.cancel();
|
||||
}
|
||||
yield TimerFinished(state.duration);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_tickerSubscription?.cancel();
|
||||
if (_tickerSubscription != null) {
|
||||
_tickerSubscription!.cancel();
|
||||
}
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Stream<TimerState> _mapStartToState(TimerStart start) async* {
|
||||
//print("$start");
|
||||
yield TimerRunning(start.duration);
|
||||
_tickerSubscription?.cancel();
|
||||
if (_tickerSubscription != null) {
|
||||
_tickerSubscription!.cancel();
|
||||
}
|
||||
_tickerSubscription = _ticker.tick(ticks: start.duration).listen(
|
||||
(localDuration) {
|
||||
//print("local: $localDuration");
|
||||
@@ -77,14 +84,19 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
|
||||
|
||||
Stream<TimerState> _mapPauseToState(TimerPause pause) async* {
|
||||
if (state is TimerRunning) {
|
||||
_tickerSubscription?.pause();
|
||||
if (_tickerSubscription != null) {
|
||||
_tickerSubscription!.pause();
|
||||
}
|
||||
yield TimerPaused(state.duration);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<TimerState> _mapResumeToState(TimerResume pause) async* {
|
||||
if (state is TimerPaused) {
|
||||
_tickerSubscription?.resume();
|
||||
if (_tickerSubscription != null) {
|
||||
_tickerSubscription!.resume();
|
||||
}
|
||||
|
||||
yield TimerRunning(state.duration);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +112,7 @@ class TimerBloc extends Bloc<TimerEvent, TimerState> {
|
||||
yield tick.duration >= 0 ? TimerRunning(tick.duration) : TimerFinished(tick.duration);
|
||||
}
|
||||
|
||||
Future _play() async {
|
||||
/* Future _play() async {
|
||||
await audioPlayer.play('asset/wine-glass.mp3', isLocal: true);
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class TimerEvent extends Equatable {
|
||||
|
||||
class TimerStart extends TimerEvent {
|
||||
final int duration;
|
||||
const TimerStart({this.duration});
|
||||
const TimerStart({required this.duration});
|
||||
|
||||
@override
|
||||
String toString() => "TimerStart { duration: $duration }";
|
||||
@@ -17,12 +17,12 @@ class TimerStart extends TimerEvent {
|
||||
|
||||
class TimerEnd extends TimerEvent {
|
||||
final int duration;
|
||||
const TimerEnd({this.duration});
|
||||
const TimerEnd({required this.duration});
|
||||
}
|
||||
|
||||
class TimerTick extends TimerEvent {
|
||||
final int duration;
|
||||
const TimerTick({this.duration});
|
||||
const TimerTick({required this.duration});
|
||||
|
||||
@override
|
||||
String toString() => "Tick { duration: $duration }";
|
||||
|
||||
@@ -45,5 +45,5 @@ class TimerFinished extends TimerState {
|
||||
|
||||
class TimerError extends TimerState {
|
||||
final String message;
|
||||
TimerError(int duration, {this.message}) : super(duration);
|
||||
TimerError(int duration, {required this.message}) : super(duration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user