WT 1.26
This commit is contained in:
@@ -119,15 +119,9 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveWeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Weight") == null) {
|
||||
throw Exception("Please select your weight");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveHeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Height") == null) {
|
||||
throw Exception("Please select your height");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSave) {
|
||||
yield CustomerSaving();
|
||||
|
||||
@@ -1,28 +1,142 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/calculate.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/group_data.dart';
|
||||
import 'package:aitrainer_app/util/diagram_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:fl_chart/fl_chart.dart';
|
||||
|
||||
part 'development_by_muscle_event.dart';
|
||||
|
||||
part 'development_by_muscle_state.dart';
|
||||
|
||||
enum DiagramType { sumMass, oneRepMax, percent }
|
||||
enum DiagramDateType { daily, weekly, monthly, yearly }
|
||||
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<DiagramData> outputList;
|
||||
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
|
||||
late DiagramType diagramType;
|
||||
late DiagramDateType dateRate;
|
||||
|
||||
GroupDate({required this.inputList, required this.outputList});
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if (this.diagramType == DiagramType.sumMass) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = exercise.quantity! * exercise.unitQuantity!;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
_sumQuantity = _sumQuantity + newQuantity;
|
||||
if (_maxQuantity < newQuantity) {
|
||||
_maxQuantity = newQuantity;
|
||||
}
|
||||
_countExercises = _countExercises + 1;
|
||||
_origDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
_origExercise = exercise;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date, DiagramDateType dateRate) {
|
||||
String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if (dateRate == DiagramDateType.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if (dateRate == DiagramDateType.monthly) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateType.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateType.daily) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origDatePart == null) {
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(_origExercise);
|
||||
this.resetTemp();
|
||||
this.addTempData(element);
|
||||
}
|
||||
} else {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void temp2Output(Exercise exercise) {
|
||||
if (exercise.unitQuantity == null) {
|
||||
return;
|
||||
}
|
||||
Exercise newExercise = exercise.copy();
|
||||
newExercise.datePart = _origDatePart;
|
||||
if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
newExercise.calculated = _maxQuantity;
|
||||
} else {
|
||||
newExercise.calculated = _sumQuantity / _countExercises;
|
||||
}
|
||||
DiagramData data = DiagramData(newExercise.datePart!, newExercise.calculated);
|
||||
outputList.add(data);
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_countExercises = 0;
|
||||
_sumQuantity = 0;
|
||||
_maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class DiagramType {
|
||||
static String sumMass = "sumMass";
|
||||
static String oneRepMax = "oneRepMax";
|
||||
@@ -33,7 +147,7 @@ class DiagramType {
|
||||
=========== GROUPDATE CLASS
|
||||
*/
|
||||
|
||||
class GroupDate extends GroupData with Calculate, Common {
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<Exercise> outputList;
|
||||
|
||||
@@ -136,7 +250,7 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
/*
|
||||
=========== CHART DATA CLASS
|
||||
*/
|
||||
class GroupChart extends GroupData with Calculate {
|
||||
class GroupChart extends GroupData with Common {
|
||||
final List<dynamic> inputList;
|
||||
LinkedHashMap<int, ChartDataExtended> outputList = LinkedHashMap();
|
||||
|
||||
@@ -186,9 +300,8 @@ class GroupChart extends GroupData with Calculate {
|
||||
_minData = diagramValue;
|
||||
}
|
||||
|
||||
BarChartGroupData data = BarChartGroupData(x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, colors: [Colors.lightBlue, Colors.lightBlueAccent])
|
||||
]);
|
||||
BarChartGroupData data = BarChartGroupData(
|
||||
x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [BarChartRodData(toY: diagramValue, width: 12, color: Colors.lightBlue)]);
|
||||
_chartData.add(data);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
}
|
||||
@@ -262,7 +375,7 @@ class ChartDataExtended {
|
||||
element.barRods.forEach((rods) {
|
||||
var barChartData = {
|
||||
'x': element.x,
|
||||
'y': rods.y,
|
||||
'y': rods.toY,
|
||||
};
|
||||
listBarChartData.add(barChartData);
|
||||
});
|
||||
@@ -274,20 +387,20 @@ class ChartDataExtended {
|
||||
};
|
||||
return chartData;
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate, Logging {
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Common, Logging {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
LinkedHashMap<int, ChartDataExtended> listChartData = LinkedHashMap();
|
||||
late List<BarChartGroupData> chartData;
|
||||
String diagramType = DiagramType.sumMass;
|
||||
String dateRate = DateRate.daily;
|
||||
double basePercent = 0;
|
||||
final List<DiagramData> diagramData = [];
|
||||
int actualExerciseType = 0;
|
||||
DiagramType diagramType = DiagramType.sumMass;
|
||||
DiagramDateType diagramDateType = DiagramDateType.monthly;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial()) {
|
||||
on<DevelopmentByMuscleLoad>(_onLoad);
|
||||
}
|
||||
|
||||
Future<void> getData() async {
|
||||
workoutTreeRepository.sortedTree.clear();
|
||||
@@ -299,93 +412,13 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
workoutTree.selected = false;
|
||||
});
|
||||
});
|
||||
|
||||
this.getChartData();
|
||||
}
|
||||
|
||||
void getChartData() {
|
||||
List<Exercise>? exercises = exerciseRepository.getExerciseList();
|
||||
|
||||
//print("-- Start calculate --- ");
|
||||
exercises = this.groupByDate(exercises);
|
||||
|
||||
exercises = sort(exercises, true);
|
||||
/* exercises.forEach((exercise) {
|
||||
print ("Chart exercise " + exercise.toJsonDatePart().toString());
|
||||
});*/
|
||||
|
||||
listChartData = LinkedHashMap();
|
||||
GroupChart groupChart = GroupChart(inputList: exercises, outputList: listChartData);
|
||||
groupChart.diagramType = this.diagramType;
|
||||
groupChart.iteration();
|
||||
listChartData = groupChart.outputList;
|
||||
|
||||
listChartData.forEach((key, value) {
|
||||
//trace("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
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());
|
||||
});
|
||||
|
||||
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());
|
||||
});*/
|
||||
|
||||
return groupedExercises;
|
||||
}
|
||||
|
||||
List<Exercise> sort(List<Exercise> exercises, bool asc) {
|
||||
exercises.sort((a, b) {
|
||||
var aDateId = a.exerciseTypeId.toString() + "_" + a.datePart.toString();
|
||||
var bDateId = b.exerciseTypeId.toString() + "_" + b.datePart.toString();
|
||||
|
||||
return asc ? aDateId.compareTo(bDateId) : bDateId.compareTo(aDateId);
|
||||
});
|
||||
return exercises;
|
||||
}
|
||||
|
||||
String getDateFormat(DateTime datetime) {
|
||||
return DateFormat('yMd', AppLanguage().appLocal.toString()).format(datetime);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<DevelopmentByMuscleState> mapEventToState(DevelopmentByMuscleEvent event) async* {
|
||||
try {
|
||||
if (event is DevelopmentByMuscleLoad) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
Track().track(TrackingEvent.my_muscle_development);
|
||||
Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen);
|
||||
await getData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if (event is DevelopmentByMuscleDiagramTypeChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String type = event.diagramType;
|
||||
this.diagramType = type;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if (event is DevelopmentByMuscleDateRateChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String dateRate = event.dateRate;
|
||||
this.dateRate = dateRate;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield DevelopmentByMuscleErrorState(message: e.toString());
|
||||
}
|
||||
void _onLoad(DevelopmentByMuscleLoad event, Emitter<DevelopmentByMuscleState> emit) async {
|
||||
emit(DevelopmentByMuscleLoadingState());
|
||||
Track().track(TrackingEvent.my_muscle_development);
|
||||
Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen);
|
||||
await getData();
|
||||
emit(DevelopmentByMuscleReadyState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent {
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
final String dateRate;
|
||||
final DiagramDateType dateRate;
|
||||
const DevelopmentByMuscleDateRateChange({required this.dateRate});
|
||||
|
||||
@override
|
||||
@@ -21,7 +21,7 @@ class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent {
|
||||
final String diagramType;
|
||||
final DiagramType diagramType;
|
||||
const DevelopmentByMuscleDiagramTypeChange({required this.diagramType});
|
||||
|
||||
@override
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/util/diagram_data.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'development_diagram_event.dart';
|
||||
part 'development_diagram_state.dart';
|
||||
|
||||
enum DiagramDataSource { customerProperty, exercise }
|
||||
|
||||
extension DiagramDataSourceExt on DiagramDataSource {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramDataSource filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
enum DiagramDateFilter { daily, monthly, weekly, yearly }
|
||||
|
||||
extension DiagramDateFilterExt on DiagramDateFilter {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramDateFilter filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
enum DiagramGroup { none, sumMass, oneRepMax, percent }
|
||||
|
||||
extension DiagramGroupExt on DiagramDateFilter {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramGroup filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
class DevelopmentDiagramBloc extends Bloc<DevelopmentDiagramEvent, DevelopmentDiagramState> with Common {
|
||||
DiagramDateFilter dateFilter = DiagramDateFilter.monthly;
|
||||
DiagramGroup group = DiagramGroup.sumMass;
|
||||
final List<DiagramData> diagramData = [];
|
||||
|
||||
CustomerRepository? customerRepository;
|
||||
ExerciseRepository? exerciseRepository;
|
||||
String? propertyName;
|
||||
int? exerciseTypeId;
|
||||
final String diagramTitle;
|
||||
bool isGroup = true;
|
||||
|
||||
DevelopmentDiagramBloc({required this.diagramTitle, this.customerRepository, this.exerciseRepository, this.propertyName, this.exerciseTypeId})
|
||||
: super(DevelopmentDiagramInitial()) {
|
||||
_init();
|
||||
on<DevelopmentDiagramLoad>(_onLoad);
|
||||
on<DevelopmentDiagramChangeDateFormat>(_onChangeDateFormat);
|
||||
on<DevelopmentDiagramChangeGroup>(_onChangeGroup);
|
||||
}
|
||||
|
||||
void _onLoad(DevelopmentDiagramLoad event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
if (Cache().userLoggedIn == null) {
|
||||
emit(DevelopmentDiagramError(message: "Please log in"));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void _init() {
|
||||
if (customerRepository != null) {
|
||||
final List<CustomerProperty> properties = this.customerRepository!.getAllCustomerPropertyByName(this.propertyName!);
|
||||
this.fillDataCustomerProperty(properties, this.dateFilter);
|
||||
this.isGroup = false;
|
||||
} else {
|
||||
this.isGroup = true;
|
||||
this.getExerciseData();
|
||||
}
|
||||
this.dateFilter = DiagramDateFilter.monthly;
|
||||
}
|
||||
|
||||
void _onChangeDateFormat(DevelopmentDiagramChangeDateFormat event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
this.dateFilter = event.dateFilter;
|
||||
print("Filter: ${this.dateFilter} - property: ${this.propertyName}");
|
||||
if (customerRepository != null) {
|
||||
final List<CustomerProperty> properties = this.customerRepository!.getAllCustomerPropertyByName(this.propertyName!);
|
||||
this.fillDataCustomerProperty(properties, this.dateFilter);
|
||||
} else {
|
||||
this.getExerciseData();
|
||||
}
|
||||
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void _onChangeGroup(DevelopmentDiagramChangeGroup event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
this.group = event.group;
|
||||
this.getExerciseData();
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void getExerciseData() {
|
||||
this.diagramData.clear();
|
||||
this.getChartData();
|
||||
}
|
||||
|
||||
List<DiagramData> getChartData() {
|
||||
List<Exercise>? exercises = exerciseRepository!.getExerciseList();
|
||||
List<Exercise> _exercises = [];
|
||||
if (this.exerciseTypeId != null) {
|
||||
exercises!.forEach((element) {
|
||||
if (element.exerciseTypeId == this.exerciseTypeId) {
|
||||
_exercises.add(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_exercises = sort(_exercises, true);
|
||||
|
||||
GroupDate groupDate = GroupDate(inputList: _exercises, outputList: this.diagramData);
|
||||
groupDate.dateRate = this.dateFilter;
|
||||
groupDate.diagramType = this.group;
|
||||
groupDate.iteration();
|
||||
|
||||
return this.diagramData;
|
||||
}
|
||||
|
||||
List<Exercise> sort(List<Exercise> _exercises, bool asc) {
|
||||
_exercises.sort((a, b) {
|
||||
var aDateId = a.exerciseTypeId.toString() + "_" + a.datePart.toString();
|
||||
var bDateId = b.exerciseTypeId.toString() + "_" + b.datePart.toString();
|
||||
|
||||
return asc ? aDateId.compareTo(bDateId) : bDateId.compareTo(aDateId);
|
||||
});
|
||||
return _exercises;
|
||||
}
|
||||
|
||||
void fillDataCustomerProperty(List<CustomerProperty> customerProperties, DiagramDateFilter filter) {
|
||||
this.diagramData.clear();
|
||||
this.dateFilter = filter;
|
||||
customerProperties.sort((a, b) => a.dateAdd!.compareTo(b.dateAdd!) > 0 ? 1 : -1);
|
||||
|
||||
double avg = 0;
|
||||
String? preFilter;
|
||||
if (this.dateFilter == DiagramDateFilter.daily) {
|
||||
preFilter = customerProperties[0].dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.weekly) {
|
||||
preFilter = customerProperties[0].dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.monthly) {
|
||||
preFilter = customerProperties[0].dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.yearly) {
|
||||
preFilter = customerProperties[0].dateY;
|
||||
}
|
||||
int counter = 0;
|
||||
customerProperties.forEach((element) {
|
||||
String? condition;
|
||||
if (this.dateFilter == DiagramDateFilter.daily) {
|
||||
condition = element.dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.monthly) {
|
||||
condition = element.dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.weekly) {
|
||||
condition = element.dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.yearly) {
|
||||
condition = element.dateY;
|
||||
}
|
||||
|
||||
if (preFilter != condition) {
|
||||
int count = counter == 0 ? 1 : counter;
|
||||
DiagramData data = DiagramData(preFilter!, avg / count);
|
||||
//print("Sum: $avg count: $count Data: $data");
|
||||
diagramData.add(data);
|
||||
counter = 1;
|
||||
preFilter = condition;
|
||||
avg = element.propertyValue;
|
||||
} else {
|
||||
avg += element.propertyValue;
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
int count = counter == 0 ? 1 : counter;
|
||||
if (preFilter != null) {
|
||||
DiagramData data = DiagramData(preFilter!, avg / count);
|
||||
diagramData.add(data);
|
||||
}
|
||||
print("Diagramdata: --- ${this.diagramData}");
|
||||
}
|
||||
}
|
||||
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<DiagramData> outputList;
|
||||
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
double? _basePercent;
|
||||
|
||||
late DiagramGroup diagramType;
|
||||
late DiagramDateFilter dateRate;
|
||||
|
||||
GroupDate({required this.inputList, required this.outputList});
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if (this.diagramType == DiagramGroup.sumMass) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = exercise.quantity! * exercise.unitQuantity!;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramGroup.oneRepMax) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramGroup.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
if (_basePercent == null) {
|
||||
_basePercent = sum;
|
||||
}
|
||||
sum = (sum / this._basePercent!) * 100;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
if (_basePercent == null) {
|
||||
_basePercent = sum;
|
||||
}
|
||||
sum = (sum / this._basePercent!) * 100;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
_sumQuantity = _sumQuantity + newQuantity;
|
||||
if (_maxQuantity < newQuantity) {
|
||||
_maxQuantity = newQuantity;
|
||||
}
|
||||
_countExercises = _countExercises + 1;
|
||||
_origDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
_origExercise = exercise;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date, DiagramDateFilter dateRate) {
|
||||
String datePart = DateFormat('yy.MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if (dateRate == DiagramDateFilter.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if (dateRate == DiagramDateFilter.monthly) {
|
||||
datePart = DateFormat('yy.MM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateFilter.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateFilter.daily) {
|
||||
datePart = DateFormat('yy.MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origDatePart == null) {
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(_origExercise);
|
||||
this.resetTemp();
|
||||
this.addTempData(element);
|
||||
}
|
||||
} else {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void temp2Output(Exercise exercise) {
|
||||
if (exercise.unitQuantity == null) {
|
||||
return;
|
||||
}
|
||||
Exercise newExercise = exercise.copy();
|
||||
newExercise.datePart = _origDatePart;
|
||||
if (this.diagramType == DiagramGroup.oneRepMax || this.diagramType == DiagramGroup.percent) {
|
||||
newExercise.calculated = _maxQuantity;
|
||||
} else {
|
||||
newExercise.calculated = _sumQuantity / _countExercises;
|
||||
}
|
||||
DiagramData data = DiagramData(newExercise.datePart!, newExercise.calculated);
|
||||
print("chart add $data");
|
||||
outputList.add(data);
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_countExercises = 0;
|
||||
_sumQuantity = 0;
|
||||
_maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
part of 'development_diagram_bloc.dart';
|
||||
|
||||
abstract class DevelopmentDiagramEvent extends Equatable {
|
||||
const DevelopmentDiagramEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramLoad extends DevelopmentDiagramEvent {
|
||||
const DevelopmentDiagramLoad();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramChangeDateFormat extends DevelopmentDiagramEvent {
|
||||
final DiagramDateFilter dateFilter;
|
||||
const DevelopmentDiagramChangeDateFormat({required this.dateFilter});
|
||||
}
|
||||
|
||||
class DevelopmentDiagramChangeGroup extends DevelopmentDiagramEvent {
|
||||
final DiagramGroup group;
|
||||
const DevelopmentDiagramChangeGroup({required this.group});
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitCustomerData extends DevelopmentDiagramEvent {
|
||||
final CustomerRepository customerRepository;
|
||||
final String propertyName;
|
||||
|
||||
const DevelopmentDiagramInitCustomerData({required this.customerRepository, required this.propertyName});
|
||||
@override
|
||||
List<Object> get props => [customerRepository, propertyName];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitExerciseData extends DevelopmentDiagramEvent {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final int exerciseTypeId;
|
||||
|
||||
const DevelopmentDiagramInitExerciseData({required this.exerciseRepository, required this.exerciseTypeId});
|
||||
@override
|
||||
List<Object> get props => [exerciseRepository, exerciseTypeId];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'development_diagram_bloc.dart';
|
||||
|
||||
abstract class DevelopmentDiagramState extends Equatable {
|
||||
const DevelopmentDiagramState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitial extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramInitial();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramLoading extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramLoading();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramReady extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramReady();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramError extends DevelopmentDiagramState {
|
||||
final String message;
|
||||
const DevelopmentDiagramError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.message];
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
@@ -11,22 +9,26 @@ part 'development_sizes_state.dart';
|
||||
class DevelopmentSizesBloc extends Bloc<DevelopmentSizesEvent, DevelopmentSizesState> {
|
||||
final CustomerRepository customerRepository;
|
||||
DevelopmentSizesBloc({required this.customerRepository}) : super(DevelopmentSizesInitial()) {
|
||||
isMan = Cache().userLoggedIn!.sex == "m";
|
||||
isMan = true;
|
||||
if ( Cache().userLoggedIn == null) {
|
||||
isMan = Cache().userLoggedIn!.sex == "m";
|
||||
}
|
||||
|
||||
on<DevelopmentSizesLoad>(_onLoad);
|
||||
}
|
||||
|
||||
late bool isMan;
|
||||
|
||||
@override
|
||||
Stream<DevelopmentSizesState> mapEventToState(
|
||||
DevelopmentSizesEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (state is DevelopmentSizesLoad) {
|
||||
yield DevelopmentSizesLoading();
|
||||
yield DevelopmentSizesReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield DevelopmentSizesError(message: e.toString());
|
||||
void _onLoad(DevelopmentSizesLoad event, Emitter<DevelopmentSizesState> emit) {
|
||||
emit( DevelopmentSizesLoading());
|
||||
if ( Cache().userLoggedIn == null) {
|
||||
emit(DevelopmentSizesError(message: "Please log in" ));
|
||||
return;
|
||||
}
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
emit( DevelopmentSizesReady());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ 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:purchases_flutter/offering_wrapper.dart';
|
||||
import 'package:purchases_flutter/models/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
part 'sales_state.dart';
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'package:flutter/material.dart';
|
||||
part 'training_evaluation_event.dart';
|
||||
part 'training_evaluation_state.dart';
|
||||
|
||||
class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvaluationState> {
|
||||
class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvaluationState> with Common {
|
||||
final TrainingPlanBloc trainingPlanBloc;
|
||||
final String day;
|
||||
TrainingEvaluationBloc({required this.trainingPlanBloc, required this.day}) : super(TrainingEvaluationInitial()) {
|
||||
@@ -42,32 +42,6 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@override
|
||||
Stream<TrainingEvaluationState> mapEventToState(
|
||||
TrainingEvaluationEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is TrainingEvaluationLoad) {
|
||||
//yield TrainingEvaluationLoading();
|
||||
await saveResult();
|
||||
getDuration();
|
||||
getTotalLift();
|
||||
getMaxRepeats();
|
||||
getTotalRepeats();
|
||||
createEvaluationData();
|
||||
getMaxLift();
|
||||
if (end == null || DateTime.now().difference(end!).inMinutes > 5) {
|
||||
yield TrainingEvaluationReady();
|
||||
} else {
|
||||
yield TrainingEvaluationVictoryReady();
|
||||
}
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield TrainingEvaluationError(message: e.toString());
|
||||
}
|
||||
} */
|
||||
|
||||
void createEvaluationData() {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return;
|
||||
@@ -114,7 +88,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
exercise.trend = getTrendEvaluationRepeats(exercise);
|
||||
} else {
|
||||
exercise.type = TrainingEvaluationExerciseType.weightBased;
|
||||
exercise.oneRepMax = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
exercise.oneRepMax = calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
exercise.max1RM = getMax1RMByExerciseType(detail.exerciseTypeId!);
|
||||
exercise.totalLift = getTotalLiftBySameExercise(detail.exerciseTypeId!);
|
||||
exercise.maxTotalLift = getMaxTotalLiftByExerciseType(detail.exerciseTypeId!);
|
||||
@@ -300,7 +274,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
if (element.dateAdd != null) {
|
||||
final String formattedExerciseDate = formatter.format(element.dateAdd!);
|
||||
if (element.exerciseTypeId == exerciseTypeId && formattedToday != formattedExerciseDate) {
|
||||
final double oneRepMax = Common.calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
final double oneRepMax = calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
}
|
||||
@@ -330,7 +304,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
if (detail.weight == null) {
|
||||
return 0;
|
||||
}
|
||||
return Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
return calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
}
|
||||
|
||||
double getTotalLiftExercise(CustomerTrainingPlanDetails detail) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import 'package:flutter/material.dart';
|
||||
part 'training_plan_event.dart';
|
||||
part 'training_plan_state.dart';
|
||||
|
||||
class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> with Common {
|
||||
final TrainingPlanRepository trainingPlanRepository;
|
||||
final MenuBloc menuBloc;
|
||||
TrainingPlanBloc({required this.trainingPlanRepository, required this.menuBloc}) : super(TrainingPlanInitial()) {
|
||||
@@ -198,7 +198,6 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
|
||||
int baseCustomerTrainingPlanDetailsId = 0;
|
||||
if (eventDetail.exerciseType!.unitQuantity != null && eventDetail.weight! > 0) {
|
||||
double calculatedWeight = 0;
|
||||
for (var nextDetail in _myPlan!.details) {
|
||||
if (nextDetail.exerciseTypeId == eventDetail.exerciseTypeId) {
|
||||
if (id == 0 && nextDetail.customerTrainingPlanDetailsId == eventDetail.customerTrainingPlanDetailsId) {
|
||||
@@ -214,7 +213,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
if (nextDetail.weight == -2 && nextDetail.customerTrainingPlanDetailsId != eventDetail.customerTrainingPlanDetailsId) {
|
||||
print("Nr 1. - recalculating -2 ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, eventDetail, nextDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} /* else if (weightFromPlan == -1 && nextDetail.set! > 1 && nextDetail.exercises.length == 1) {
|
||||
print("Nr 2. recalculating -1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeats(_myPlan!.trainingPlanId!, nextDetail);
|
||||
@@ -223,22 +222,21 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
else if (nextDetail.weight == -1 && nextDetail.set! == 1) {
|
||||
print("Nr 3. recalculating -1, set 1 ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (eventDetail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! == id + 1 &&
|
||||
recalculate) {
|
||||
print("Nr 4. recalculating after the first exercise ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
calculatedWeight = nextDetail.weight!;
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (eventDetail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! > id + 1 &&
|
||||
recalculate) {
|
||||
print("Nr 5. recalculating after the second exercise ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (id != 0) {
|
||||
// calculate weight and repeat based on the first baseOneRepMax
|
||||
if (baseCustomerTrainingPlanDetailsId != 0) {
|
||||
@@ -918,8 +916,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
if (_myDetail == null || _myDetail!.exerciseType == null) {
|
||||
return exerciseName;
|
||||
}
|
||||
exerciseName =
|
||||
AppLanguage().appLocal == Locale("en") ? getMyDetail()!.exerciseType!.name : getMyDetail()!.exerciseType!.nameTranslation;
|
||||
exerciseName = AppLanguage().appLocal == Locale("en") ? getMyDetail()!.exerciseType!.name : getMyDetail()!.exerciseType!.nameTranslation;
|
||||
return exerciseName;
|
||||
}
|
||||
|
||||
@@ -1007,8 +1004,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
if (listDetail.exercises.length >= listDetail.set!) {
|
||||
listDetail.state = ExercisePlanDetailState.finished;
|
||||
}
|
||||
allFinished =
|
||||
allFinished && (listDetail.exercises.length >= listDetail.set! || listDetail.state.equalsTo(ExercisePlanDetailState.skipped));
|
||||
allFinished = allFinished && (listDetail.exercises.length >= listDetail.set! || listDetail.state.equalsTo(ExercisePlanDetailState.skipped));
|
||||
}
|
||||
//print("All finished: $allFinished for ${detail.exerciseTypeId}");
|
||||
return allFinished;
|
||||
|
||||
@@ -121,8 +121,7 @@ class AnimatedButton extends StatefulWidget {
|
||||
this.borderWidth = 1,
|
||||
this.blurColor = Colors.black,
|
||||
this.shadowColor,
|
||||
}) : assert(child != null),
|
||||
super(key: key);
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AnimatedButtonState createState() => _AnimatedButtonState(
|
||||
|
||||
@@ -258,7 +258,7 @@ class _BottomNavigationTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: item.title,
|
||||
child: Text(item.label!),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -288,7 +288,7 @@ class _BottomNavigationTile extends StatelessWidget {
|
||||
fontSize: _kActiveFontSize,
|
||||
color: Colors.white,
|
||||
),
|
||||
child: item.title!,
|
||||
child: Text(item.label!),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -44,6 +44,7 @@ import 'package:aitrainer_app/view/test_set_execute.dart';
|
||||
import 'package:aitrainer_app/view/test_set_new.dart';
|
||||
import 'package:aitrainer_app/view/training_plan_activate_page.dart';
|
||||
import 'package:aitrainer_app/view/training_plan_exercise.dart';
|
||||
import 'package:aitrainer_app/widgets/development_diagram.dart';
|
||||
import 'package:aitrainer_app/widgets/home.dart';
|
||||
import 'package:aitrainer_app/library/facebook_app_events/facebook_app_events.dart';
|
||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||
@@ -282,6 +283,7 @@ class WorkoutTestApp extends StatelessWidget {
|
||||
'mydevelopmentMusclePage': (context) => MyDevelopmentMusclePage(),
|
||||
'mydevelopmentBodyPage': (context) => MyDevelopmentBodyPage(),
|
||||
'mydevelopmentSizesPage': (context) => SizesDevelopmentPage(),
|
||||
'developmentDiagramPage': (context) => DevelopmentDiagram(),
|
||||
'evaluationPage': (context) => EvaluationPage(),
|
||||
'salesPage': (context) => SalesPage(),
|
||||
'testSetEdit': (context) => TestSetEdit(),
|
||||
|
||||
+14
-4
@@ -2,6 +2,7 @@ import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/customer_activity.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/customer_training_plan.dart';
|
||||
import 'package:aitrainer_app/model/description.dart';
|
||||
import 'package:aitrainer_app/model/evaluation.dart';
|
||||
@@ -158,6 +159,7 @@ class Cache with Logging {
|
||||
List<CustomerExerciseDevice>? _customerDevices;
|
||||
List<CustomerActivity>? _customerActivities;
|
||||
List<CustomerTrainingPlan>? _customerTrainingPlans;
|
||||
List<CustomerProperty>? _customerPropertyAll;
|
||||
|
||||
List<Tutorial>? _tutorials;
|
||||
List<Description>? _descriptions;
|
||||
@@ -542,8 +544,7 @@ class Cache with Logging {
|
||||
|
||||
ExercisePlan? getMyExercisePlan() => _myExercisePlan;
|
||||
|
||||
void setMyExercisePlanDetails(LinkedHashMap<int, ExercisePlanDetail> listExercisePlanDetail) =>
|
||||
_myExercisesPlanDetails = listExercisePlanDetail;
|
||||
void setMyExercisePlanDetails(LinkedHashMap<int, ExercisePlanDetail> listExercisePlanDetail) => _myExercisesPlanDetails = listExercisePlanDetail;
|
||||
|
||||
void addToMyExercisePlanDetails(ExercisePlanDetail detail) => _myExercisesPlanDetails[detail.exerciseTypeId] = detail;
|
||||
|
||||
@@ -557,8 +558,7 @@ class Cache with Logging {
|
||||
|
||||
void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => this.deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId);
|
||||
|
||||
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) =>
|
||||
this._myExercisesPlanDetails[detail.exerciseTypeId]!.change = ModelChange.deleted;
|
||||
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) => this._myExercisesPlanDetails[detail.exerciseTypeId]!.change = ModelChange.deleted;
|
||||
|
||||
void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) {
|
||||
this._myExercisesPlanDetails[exerciseTypeId]!.change = ModelChange.delete;
|
||||
@@ -772,10 +772,20 @@ class Cache with Logging {
|
||||
List<TrainingPlanDay> getTrainingPlanDays() => this._trainingPlanDays;
|
||||
setTrainingPlanDays(value) => this._trainingPlanDays = value;
|
||||
|
||||
List<CustomerProperty>? getCustomerPropertyAll() => this._customerPropertyAll;
|
||||
setCustomerPropertyAll(value) => this._customerPropertyAll = value;
|
||||
addCustomerProperty(CustomerProperty property) {
|
||||
if (this._customerPropertyAll == null) {
|
||||
this._customerPropertyAll = [];
|
||||
}
|
||||
this._customerPropertyAll!.add(property);
|
||||
}
|
||||
|
||||
bool canTrial() {
|
||||
bool can = true;
|
||||
if (Cache().userLoggedIn == null) {
|
||||
can = false;
|
||||
return can;
|
||||
}
|
||||
for (var element in _purchases) {
|
||||
if (element.customerId == Cache().userLoggedIn!.customerId) {
|
||||
|
||||
@@ -5,17 +5,33 @@ class CustomerProperty {
|
||||
late int propertyId;
|
||||
late int customerId;
|
||||
DateTime? dateAdd;
|
||||
String? dateYmd;
|
||||
String? dateYm;
|
||||
String? dateY;
|
||||
late double propertyValue;
|
||||
bool newData = false;
|
||||
|
||||
CustomerProperty({required this.propertyId, required this.customerId, required this.dateAdd, required this.propertyValue});
|
||||
CustomerProperty(
|
||||
{required this.propertyId,
|
||||
required this.customerId,
|
||||
required this.dateAdd,
|
||||
required this.propertyValue});
|
||||
|
||||
CustomerProperty.fromJson(Map json) {
|
||||
this.customerPropertyId = json['customerPropertyId'];
|
||||
this.propertyId = json['propertyId'];
|
||||
this.customerId = json['customerId'];
|
||||
this.dateAdd = json['dataAdd'] ?? DateTime.now();
|
||||
this.dateAdd = DateTime.parse(json['dateAdd']);
|
||||
|
||||
if (this.dateAdd != null) {
|
||||
dateYmd = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
|
||||
dateYm = DateFormat('yyyy-MM').format(this.dateAdd!);
|
||||
dateY = DateFormat('yyyy').format(this.dateAdd!);
|
||||
}
|
||||
|
||||
this.propertyValue = json['propertyValue'];
|
||||
|
||||
print("Json $json, ${this.toString()}");
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -36,4 +52,18 @@ class CustomerProperty {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
String toString() {
|
||||
Map<String, dynamic> json = {
|
||||
"customerPropertyId": this.customerPropertyId,
|
||||
"propertyId": this.propertyId,
|
||||
"customerId": this.customerId,
|
||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
|
||||
"propertyValue": this.propertyValue,
|
||||
"dateYmd": this.dateYmd,
|
||||
"dateYm": this.dateYm,
|
||||
"dateY": this.dateY,
|
||||
};
|
||||
return json.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -12,6 +12,17 @@ class Property {
|
||||
this.propertyName = json['propertyName'];
|
||||
this.propertyUnit = json['propertyUnit'];
|
||||
this.propertyNameTranslation =
|
||||
json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['propertyName'] : this.propertyName;
|
||||
json['translations'] != null && (json['translations']).length > 0
|
||||
? json['translations'][0]['propertyName']
|
||||
: this.propertyName;
|
||||
}
|
||||
|
||||
String toString() {
|
||||
Map<String, dynamic> json = {
|
||||
"propertyId": propertyId,
|
||||
"propertyName": propertyName,
|
||||
"propertyUnit": propertyUnit
|
||||
};
|
||||
return json.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ class CustomerRepository with Logging {
|
||||
Customer? customer;
|
||||
Customer? _trainee;
|
||||
List<Customer>? _trainees;
|
||||
List<CustomerProperty>? _allProperties;
|
||||
List<CustomerProperty>? _properties;
|
||||
List<CustomerProperty>? _allCustomerProperties;
|
||||
final PropertyRepository propertyRepository = PropertyRepository();
|
||||
final List<Property> womanSizes = [];
|
||||
final List<Property> manSizes = [];
|
||||
@@ -43,6 +44,8 @@ class CustomerRepository with Logging {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
isMan = (Cache().userLoggedIn!.sex == "m");
|
||||
}
|
||||
|
||||
_allCustomerProperties = Cache().getCustomerPropertyAll();
|
||||
}
|
||||
|
||||
String? getGenderByName(String name) {
|
||||
@@ -164,7 +167,9 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
setCustomerProperty(String propertyName, double value, {id = 0}) {
|
||||
if (this.customer == null) throw Exception("Initialize the customer object");
|
||||
if (this.customer == null) {
|
||||
throw Exception("Initialize the customer object");
|
||||
}
|
||||
if (this.customer!.properties[propertyName] == null) {
|
||||
this.customer!.properties[propertyName] = CustomerProperty(
|
||||
propertyId: propertyRepository.getPropertyByName("Height")!.propertyId,
|
||||
@@ -179,6 +184,7 @@ class CustomerRepository with Logging {
|
||||
if (id > 0) {
|
||||
this.customer!.properties[propertyName]!.customerPropertyId = id;
|
||||
}
|
||||
Cache().addCustomerProperty(this.customer!.properties[propertyName]!);
|
||||
}
|
||||
|
||||
double getWeight() {
|
||||
@@ -277,7 +283,7 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
Future<void> savePropertyByName(String name) async {
|
||||
await Future.forEach(this._allProperties!, (element) async {
|
||||
await Future.forEach(this._properties!, (element) async {
|
||||
final CustomerProperty customerProperty = element as CustomerProperty;
|
||||
final Property? property = propertyRepository.getPropertyByName(name);
|
||||
if (property != null) {
|
||||
@@ -303,12 +309,12 @@ class CustomerRepository with Logging {
|
||||
Future<List<CustomerProperty>> getAllCustomerProperties() async {
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
final results = await CustomerApi().getAllProperties(customerId);
|
||||
this._allProperties = results;
|
||||
this._properties = results;
|
||||
return results;
|
||||
}
|
||||
|
||||
List<CustomerProperty>? getAllProperties() {
|
||||
return this._allProperties;
|
||||
return this._properties;
|
||||
}
|
||||
|
||||
List<Customer>? getTraineesList() {
|
||||
@@ -547,4 +553,21 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<CustomerProperty> getAllCustomerPropertyByName(String propertyName) {
|
||||
List<CustomerProperty> allProperties = [];
|
||||
|
||||
Property? property = propertyRepository.getPropertyByName(propertyName);
|
||||
print(property);
|
||||
if (property == null || Cache().getCustomerPropertyAll() == null) {
|
||||
return allProperties;
|
||||
}
|
||||
|
||||
Cache().getCustomerPropertyAll()!.forEach((element) {
|
||||
if (element.propertyId == property.propertyId) {
|
||||
allProperties.add(element);
|
||||
}
|
||||
});
|
||||
return allProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'package:aitrainer_app/repository/training_plan_day_repository.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
|
||||
class TrainingPlanRepository {
|
||||
class TrainingPlanRepository with Common {
|
||||
ExerciseTree? parentTree;
|
||||
List<TrainingPlan> getPlansByParent(String parent) {
|
||||
final List<TrainingPlan> resultList = [];
|
||||
@@ -165,7 +165,7 @@ class TrainingPlanRepository {
|
||||
|
||||
detail.state = ExercisePlanDetailState.start;
|
||||
if (detail.weight != null && detail.weight! > 0) {
|
||||
detail.baseOneRepMax = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
detail.baseOneRepMax = calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
}
|
||||
|
||||
// first repeat: 50% more
|
||||
@@ -173,7 +173,7 @@ class TrainingPlanRepository {
|
||||
CustomerTrainingPlanDetails firstDetail = CustomerTrainingPlanDetails();
|
||||
firstDetail.copy(detail);
|
||||
firstDetail.repeats = (detail.repeats! * 1.5).round();
|
||||
firstDetail.baseOneRepMax = Common.calculate1RM(firstDetail.weight!, firstDetail.repeats!.toDouble());
|
||||
firstDetail.baseOneRepMax = calculate1RM(firstDetail.weight!, firstDetail.repeats!.toDouble());
|
||||
firstDetail.set = 1;
|
||||
detail.set = detail.set! - 1;
|
||||
if (detail.set! > 0) {
|
||||
@@ -189,8 +189,7 @@ class TrainingPlanRepository {
|
||||
return list;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails isWeightCalculatedByExerciseType(
|
||||
int exerciseTypeId, CustomerTrainingPlanDetails detail, CustomerTrainingPlan plan) {
|
||||
CustomerTrainingPlanDetails isWeightCalculatedByExerciseType(int exerciseTypeId, CustomerTrainingPlanDetails detail, CustomerTrainingPlan plan) {
|
||||
CustomerTrainingPlanDetails calculated = detail;
|
||||
for (var element in plan.details) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
@@ -290,7 +289,7 @@ class TrainingPlanRepository {
|
||||
actual.dateAdd!.year == exercise.dateAdd!.year &&
|
||||
actual.dateAdd!.month == exercise.dateAdd!.month &&
|
||||
actual.dateAdd!.day == exercise.dateAdd!.day) {
|
||||
double oneRepMax = Common.calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
double oneRepMax = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
}
|
||||
@@ -350,16 +349,14 @@ class TrainingPlanRepository {
|
||||
}
|
||||
int originalRepeats = getOriginalRepeats(trainingPlanId, detail);
|
||||
|
||||
detail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detailWithData.weight!, detailWithData.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
detail.weight = Common.calculateWeigthByChangedQuantity(detailWithData.weight!, detailWithData.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
detail.weight = Common.roundWeight(detail.weight!);
|
||||
print("Recalculated weight: ${detail.weight}");
|
||||
detail.repeats = originalRepeats;
|
||||
return detail;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails recalculateDetail(
|
||||
int trainingPlanId, CustomerTrainingPlanDetails detail, CustomerTrainingPlanDetails nextDetail) {
|
||||
CustomerTrainingPlanDetails recalculateDetail(int trainingPlanId, CustomerTrainingPlanDetails detail, CustomerTrainingPlanDetails nextDetail) {
|
||||
CustomerTrainingPlanDetails recalculatedDetail = nextDetail;
|
||||
|
||||
// 1. get original repeats
|
||||
@@ -379,8 +376,7 @@ class TrainingPlanRepository {
|
||||
});
|
||||
|
||||
// 2 get recalculated repeats
|
||||
recalculatedDetail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
recalculatedDetail.weight = Common.roundWeight(recalculatedDetail.weight!);
|
||||
print("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
|
||||
//recalculatedDetail.repeats = originalRepeats;
|
||||
|
||||
@@ -44,44 +44,62 @@ class PackageApi {
|
||||
final List<String> headRecord = element.split("***");
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
if (headRecord[0] == "ExerciseDevice") {
|
||||
final List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
||||
final List<ExerciseDevice> devices =
|
||||
json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
||||
Cache().setDevices(devices);
|
||||
} else if (headRecord[0] == "Product") {
|
||||
final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
|
||||
final List<Product> products =
|
||||
json.map((product) => Product.fromJson(product)).toList();
|
||||
Cache().setProducts(products);
|
||||
} else if (headRecord[0] == "Property") {
|
||||
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
||||
final List<Property> properties =
|
||||
json.map((property) => Property.fromJson(property)).toList();
|
||||
Cache().setProperties(properties);
|
||||
} else if (headRecord[0] == "ExerciseTree") {
|
||||
exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
exerciseTree = json
|
||||
.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree))
|
||||
.toList();
|
||||
} else if (headRecord[0] == "ExerciseType") {
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
final List<ExerciseType> exerciseTypes = json
|
||||
.map((exerciseType) => ExerciseType.fromJson(exerciseType))
|
||||
.toList();
|
||||
await Future.forEach(exerciseTypes, (elem) async {
|
||||
final ExerciseType exerciseType = elem as ExerciseType;
|
||||
exerciseType.imageUrl = await ExerciseTypeApi().buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||
exerciseType.imageUrl = await ExerciseTypeApi()
|
||||
.buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
|
||||
});
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
} else if (headRecord[0] == "ExerciseAbility") {
|
||||
} else if (headRecord[0] == "ExercisePlanTemplate") {
|
||||
final List<ExercisePlanTemplate> exercisePlanTemplates =
|
||||
json.map((exercisePlanTemplate) => ExercisePlanTemplate.fromJson(exercisePlanTemplate)).toList();
|
||||
final List<ExercisePlanTemplate> exercisePlanTemplates = json
|
||||
.map((exercisePlanTemplate) =>
|
||||
ExercisePlanTemplate.fromJson(exercisePlanTemplate))
|
||||
.toList();
|
||||
Cache().setExercisePlanTemplates(exercisePlanTemplates);
|
||||
} else if (headRecord[0] == "ExerciseTreeParents") {
|
||||
exerciseTreeParents = json.map((exerciseTreeParent) => ExerciseTreeParents.fromJson(exerciseTreeParent)).toList();
|
||||
exerciseTreeParents = json
|
||||
.map((exerciseTreeParent) =>
|
||||
ExerciseTreeParents.fromJson(exerciseTreeParent))
|
||||
.toList();
|
||||
} else if (headRecord[0] == "Evaluation") {
|
||||
final List<Evaluation> evaluations = json.map((evaluation) => Evaluation.fromJson(evaluation)).toList();
|
||||
final List<Evaluation> evaluations =
|
||||
json.map((evaluation) => Evaluation.fromJson(evaluation)).toList();
|
||||
Cache().evaluations = evaluations;
|
||||
} else if (headRecord[0] == "Sport") {
|
||||
final List<Sport> sports = json.map((sport) => Sport.fromJson(sport)).toList();
|
||||
final List<Sport> sports =
|
||||
json.map((sport) => Sport.fromJson(sport)).toList();
|
||||
Cache().setSports(sports);
|
||||
} else if (headRecord[0] == "Tutorial") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<Tutorial> tutorials = json.map((tutorial) => Tutorial.fromJson(tutorial)).toList();
|
||||
final List<Tutorial> tutorials =
|
||||
json.map((tutorial) => Tutorial.fromJson(tutorial)).toList();
|
||||
|
||||
Cache().setTutorials(tutorials);
|
||||
} else if (headRecord[0] == "Description") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<Description>? descriptions = json.map((description) => Description.fromJson(description)).toList();
|
||||
final List<Description>? descriptions = json
|
||||
.map((description) => Description.fromJson(description))
|
||||
.toList();
|
||||
//print("Description: $descriptions");
|
||||
Cache().setDescriptions(descriptions);
|
||||
} else if (headRecord[0] == "Faq") {
|
||||
@@ -91,7 +109,8 @@ class PackageApi {
|
||||
Cache().setFaqs(faqs);
|
||||
} else if (headRecord[0] == "TrainingPlan") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<TrainingPlan>? plans = json.map((plan) => TrainingPlan.fromJson(plan)).toList();
|
||||
final List<TrainingPlan>? plans =
|
||||
json.map((plan) => TrainingPlan.fromJson(plan)).toList();
|
||||
|
||||
List<TrainingPlan> activePlans = [];
|
||||
if (plans != null) {
|
||||
@@ -104,31 +123,38 @@ class PackageApi {
|
||||
Cache().setTrainingPlans(activePlans);
|
||||
} else if (headRecord[0] == "SplitTests") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<SplitTest>? tests = json.map((test) => SplitTest.fromJson(test)).toList();
|
||||
final List<SplitTest>? tests =
|
||||
json.map((test) => SplitTest.fromJson(test)).toList();
|
||||
//print("A/B tests: $tests");
|
||||
Cache().setSplitTests(tests);
|
||||
} else if (headRecord[0] == "TrainingPlanDay") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<TrainingPlanDay>? days = json.map((day) => TrainingPlanDay.fromJson(day)).toList();
|
||||
final List<TrainingPlanDay>? days =
|
||||
json.map((day) => TrainingPlanDay.fromJson(day)).toList();
|
||||
Cache().setTrainingPlanDays(days);
|
||||
}
|
||||
});
|
||||
|
||||
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
exerciseTree =
|
||||
this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
ExerciseTree tree = element as ExerciseTree;
|
||||
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||
tree.imageUrl =
|
||||
await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||
});
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
|
||||
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
|
||||
TrainingPlanDayRepository trainingPlanDayRepository =
|
||||
TrainingPlanDayRepository();
|
||||
trainingPlanDayRepository.assignTrainingPlanDays();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
List<ExerciseTree> getExerciseTreeParents(final List<ExerciseTree> exerciseTree, final List<ExerciseTreeParents> exerciseTreeParents) {
|
||||
List<ExerciseTree> getExerciseTreeParents(
|
||||
final List<ExerciseTree> exerciseTree,
|
||||
final List<ExerciseTreeParents> exerciseTreeParents) {
|
||||
List<ExerciseTree> copyList = ExerciseTreeApi().copyList(exerciseTree);
|
||||
|
||||
int treeIndex = 0;
|
||||
@@ -158,7 +184,8 @@ class PackageApi {
|
||||
|
||||
Future<void> getCustomerPackage(int customerId) async {
|
||||
try {
|
||||
final body = await _client.get("app_customer_package/" + customerId.toString(), "");
|
||||
final body = await _client.get(
|
||||
"app_customer_package/" + customerId.toString(), "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (elem) async {
|
||||
@@ -170,21 +197,35 @@ class PackageApi {
|
||||
Cache().userLoggedIn = customer;
|
||||
} else if (headRecord[0] == "CustomerExerciseDevice") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<CustomerExerciseDevice> devices = json.map((device) => CustomerExerciseDevice.fromJson(device)).toList();
|
||||
final List<CustomerExerciseDevice> devices = json
|
||||
.map((device) => CustomerExerciseDevice.fromJson(device))
|
||||
.toList();
|
||||
Cache().setCustomerDevices(devices);
|
||||
// ToDo
|
||||
} else if (headRecord[0] == "Exercises") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<Exercise> exercises = json.map((exerciseType) => Exercise.fromJson(exerciseType)).toList();
|
||||
final List<Exercise> exercises = json
|
||||
.map((exerciseType) => Exercise.fromJson(exerciseType))
|
||||
.toList();
|
||||
Cache().setExercises(exercises);
|
||||
} else if (headRecord[0] == "Purchase") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<Purchase> purchases = json.map((purchase) => Purchase.fromJson(purchase)).toList();
|
||||
final List<Purchase> purchases =
|
||||
json.map((purchase) => Purchase.fromJson(purchase)).toList();
|
||||
Cache().setPurchases(purchases);
|
||||
} else if (headRecord[0] == "CustomerProperty") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<CustomerProperty> customerProperties = json.map((property) => CustomerProperty.fromJson(property)).toList();
|
||||
final List<CustomerProperty> customerProperties = json
|
||||
.map((property) => CustomerProperty.fromJson(property))
|
||||
.toList();
|
||||
CustomerApi().initProperties(customerProperties);
|
||||
} else if (headRecord[0] == "CustomerPropertyAll") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<CustomerProperty> allCustomerProperties = json
|
||||
.map((property) => CustomerProperty.fromJson(property))
|
||||
.toList();
|
||||
print(" All Properties ---- $allCustomerProperties");
|
||||
Cache().setCustomerPropertyAll(allCustomerProperties);
|
||||
} else if (headRecord[0] == "ExerciseResult") {
|
||||
/*final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<ExerciseResult> exerciseResults = json.map((exerciseResult) {
|
||||
@@ -194,7 +235,9 @@ class PackageApi {
|
||||
// ToDo */
|
||||
} else if (headRecord[0] == "CustomerActivity") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<CustomerActivity> customerActivities = json.map((activity) => CustomerActivity.fromJson(activity)).toList();
|
||||
final List<CustomerActivity> customerActivities = json
|
||||
.map((activity) => CustomerActivity.fromJson(activity))
|
||||
.toList();
|
||||
Cache().setCustomerActivities(customerActivities);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
mixin Calculate {
|
||||
|
||||
double calculate1RM(double quantity, double unitQuantity) {
|
||||
double weight = unitQuantity;
|
||||
double repeat = quantity;
|
||||
if ( weight == 0 || repeat == 0) {
|
||||
return 0;
|
||||
}
|
||||
double rmWendler = weight * repeat * 0.0333 + weight;
|
||||
double rmOconner = weight * (1 + repeat / 40);
|
||||
double average = (rmWendler + rmOconner)/2;
|
||||
|
||||
return average;
|
||||
}
|
||||
}
|
||||
+3
-18
@@ -44,7 +44,7 @@ mixin Common {
|
||||
String getDateLocale(DateTime datetime, bool timeDisplay) {
|
||||
var date = datetime;
|
||||
|
||||
String dateName = DateFormat(DateFormat.YEAR_MONTH_DAY, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
String dateName = DateFormat(DateFormat.YEAR_NUM_MONTH_DAY, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
if (timeDisplay) {
|
||||
dateName += " " + DateFormat(DateFormat.HOUR_MINUTE, AppLanguage().appLocal.toString()).format(date.toUtc());
|
||||
}
|
||||
@@ -82,20 +82,6 @@ mixin Common {
|
||||
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date, String dateRate) {
|
||||
String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if (dateRate == DateRate.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if (dateRate == DateRate.monthly) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DateRate.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DateRate.daily) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
static String? emailValidation(String? email) {
|
||||
final String error = "Please type an email address";
|
||||
if (email == null) {
|
||||
@@ -146,7 +132,7 @@ mixin Common {
|
||||
return value;
|
||||
}
|
||||
|
||||
static double calculate1RM(double weight, double repeat) {
|
||||
double calculate1RM(double weight, double repeat) {
|
||||
if (weight == 0 || repeat == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -207,8 +193,7 @@ mixin Common {
|
||||
final double repeatWendler = (rmWendler - changedWeight) / 0.0333 / changedWeight;
|
||||
final double repeatOconner = (rmOconner / changedWeight - 1) * 40;
|
||||
final newRepeat = ((repeatOconner + repeatWendler) / 2).ceil();
|
||||
print(
|
||||
"Weight: $weight changedWeight: $changedWeight repeatWendler: $repeatWendler repeat Oconner: $repeatOconner. NEW REPEAT: $newRepeat");
|
||||
print("Weight: $weight changedWeight: $changedWeight repeatWendler: $repeatWendler repeat Oconner: $repeatOconner. NEW REPEAT: $newRepeat");
|
||||
return newRepeat;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
|
||||
abstract class GroupData {
|
||||
void iteration();
|
||||
|
||||
bool checkNewType(Exercise exercise);
|
||||
|
||||
void addTempData(Exercise element);
|
||||
|
||||
void temp2Output(Exercise exercise);
|
||||
|
||||
void resetTemp();
|
||||
}
|
||||
|
||||
class DiagramData {
|
||||
final String x;
|
||||
final double? y;
|
||||
DiagramData(this.x, this.y);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> json = {"x": this.x, "y": this.y};
|
||||
return json;
|
||||
}
|
||||
|
||||
String toString() => this.toJson().toString();
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
|
||||
abstract class GroupData {
|
||||
|
||||
void iteration();
|
||||
|
||||
bool checkNewType(Exercise exercise);
|
||||
|
||||
void addTempData(Exercise element);
|
||||
|
||||
void temp2Output(Exercise exercise);
|
||||
|
||||
void resetTemp();
|
||||
|
||||
}
|
||||
@@ -207,9 +207,7 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24,
|
||||
border: Border.all(color: Colors.black, width: 0.4),
|
||||
borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
color: Colors.white24, border: Border.all(color: Colors.black, width: 0.4), borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
child: Column(children: [
|
||||
Text(t("Birth Year"),
|
||||
style: GoogleFonts.inter(
|
||||
@@ -257,8 +255,8 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
orientation: LinearGaugeOrientation.horizontal,
|
||||
majorTickStyle: LinearTickStyle(length: 20),
|
||||
axisLabelStyle: TextStyle(fontSize: 12.0, color: Colors.black),
|
||||
axisTrackStyle: LinearAxisTrackStyle(
|
||||
color: Colors.cyan, edgeStyle: LinearEdgeStyle.bothFlat, thickness: 1.0, borderColor: Colors.grey)),
|
||||
axisTrackStyle:
|
||||
LinearAxisTrackStyle(color: Colors.cyan, edgeStyle: LinearEdgeStyle.bothFlat, thickness: 1.0, borderColor: Colors.grey)),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
@@ -270,9 +268,7 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24,
|
||||
border: Border.all(color: Colors.black, width: 0.4),
|
||||
borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
color: Colors.white24, border: Border.all(color: Colors.black, width: 0.4), borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
child: Column(children: [
|
||||
Text(t("Weight"),
|
||||
style: GoogleFonts.inter(
|
||||
@@ -300,9 +296,7 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24,
|
||||
border: Border.all(color: Colors.black, width: 0.4),
|
||||
borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
color: Colors.white24, border: Border.all(color: Colors.black, width: 0.4), borderRadius: BorderRadius.all(Radius.circular(12))),
|
||||
child: Column(children: [
|
||||
Text(t("Height"),
|
||||
style: GoogleFonts.inter(
|
||||
@@ -376,14 +370,15 @@ class CustomerModifyPage extends StatelessWidget with Trans {
|
||||
minHeight: 50.0,
|
||||
fontSize: 14.0,
|
||||
initialLabelIndex: customerBloc.customerRepository.customer!.sex == "m" ? 0 : 1,
|
||||
activeBgColor: Colors.indigo,
|
||||
activeBgColor: [Colors.indigo],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.white30,
|
||||
inactiveFgColor: Colors.grey[900],
|
||||
labels: [t('Man'), t('Woman')],
|
||||
onToggle: (index) {
|
||||
customerBloc.add(CustomerGenderChange(gender: index));
|
||||
customerBloc.add(CustomerGenderChange(gender: index!));
|
||||
},
|
||||
totalSwitches: 2,
|
||||
),
|
||||
Divider(),
|
||||
Divider(),
|
||||
|
||||
@@ -34,8 +34,8 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
|
||||
create: (context) => TrainingLogBloc()..add(TrainingLogLoad()),
|
||||
child: BlocConsumer<TrainingLogBloc, TrainingLogState>(listener: (context, state) {
|
||||
if (state is TrainingLogError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
final bloc = BlocProvider.of<TrainingLogBloc>(context);
|
||||
@@ -88,7 +88,14 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
|
||||
Widget getCalendar(TrainingLogBloc bloc) {
|
||||
return Expanded(
|
||||
child: SfCalendarTheme(
|
||||
data: SfCalendarThemeData(brightness: Brightness.dark, backgroundColor: Colors.transparent),
|
||||
data: SfCalendarThemeData(
|
||||
brightness: Brightness.dark,
|
||||
backgroundColor: Colors.transparent,
|
||||
agendaDayTextStyle: GoogleFonts.inter(color: Colors.white),
|
||||
agendaDateTextStyle: GoogleFonts.inter(color: Colors.white),
|
||||
weekNumberTextStyle: GoogleFonts.inter(color: Colors.white),
|
||||
viewHeaderDayTextStyle: GoogleFonts.inter(color: Colors.white),
|
||||
),
|
||||
child: SfCalendar(
|
||||
dataSource: TrainingDataSource(bloc.results),
|
||||
allowedViews: [
|
||||
@@ -97,14 +104,22 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
|
||||
],
|
||||
view: CalendarView.month,
|
||||
monthViewSettings: MonthViewSettings(
|
||||
showAgenda: true,
|
||||
appointmentDisplayMode: MonthAppointmentDisplayMode.indicator,
|
||||
showTrailingAndLeadingDates: true,
|
||||
appointmentDisplayCount: 12,
|
||||
),
|
||||
showAgenda: true,
|
||||
appointmentDisplayMode: MonthAppointmentDisplayMode.indicator,
|
||||
showTrailingAndLeadingDates: true,
|
||||
appointmentDisplayCount: 12,
|
||||
monthCellStyle: MonthCellStyle(
|
||||
textStyle: GoogleFonts.inter(color: Colors.white),
|
||||
leadingDatesTextStyle: GoogleFonts.inter(color: Colors.white54),
|
||||
trailingDatesTextStyle: GoogleFonts.inter(color: Colors.white54),
|
||||
)),
|
||||
appointmentTimeTextFormat: 'HH:mm',
|
||||
headerDateFormat: "y MMMM",
|
||||
headerStyle: CalendarHeaderStyle(
|
||||
textStyle: GoogleFonts.inter(color: Colors.white),
|
||||
),
|
||||
firstDayOfWeek: 1, // Monday
|
||||
cellBorderColor: Colors.white54,
|
||||
selectionDecoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
border: Border.all(color: Color(0xffb4f500), width: 2),
|
||||
@@ -145,8 +160,7 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
|
||||
fit: FlexFit.tight,
|
||||
flex: 30,
|
||||
child: Text(result.eventName,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: result.isExercise ? 14 : 16, color: result.color, fontWeight: FontWeight.bold)),
|
||||
style: GoogleFonts.inter(fontSize: result.isExercise ? 14 : 16, color: result.color, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Visibility(
|
||||
visible: result.isExercise,
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_premium.dart';
|
||||
import 'package:aitrainer_app/widgets/treeview_parent_widget.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/bloc/development_by_muscle/development_by_muscle_bloc.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
@@ -21,7 +20,6 @@ class MyDevelopmentMusclePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyDevelopmentMuscleState extends State<MyDevelopmentMusclePage> with Common, Trans {
|
||||
// ignore: close_sinks
|
||||
late DevelopmentByMuscleBloc bloc;
|
||||
late double cWidth;
|
||||
|
||||
@@ -88,7 +86,7 @@ class _MyDevelopmentMuscleState extends State<MyDevelopmentMusclePage> with Comm
|
||||
} else {
|
||||
return TreeView(
|
||||
startExpanded: false,
|
||||
children: _getTreeChildren(bloc.workoutTreeRepository.sortedTree, bloc),
|
||||
children: _getTreeChildren(bloc),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -98,9 +96,7 @@ class _MyDevelopmentMuscleState extends State<MyDevelopmentMusclePage> with Comm
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _getTreeChildren(SplayTreeMap tree, DevelopmentByMuscleBloc bloc) {
|
||||
List<Widget> exerciseTypes = [];
|
||||
|
||||
Card getExplanation(DevelopmentByMuscleBloc bloc) {
|
||||
Card explanation = Card(
|
||||
color: Colors.white60,
|
||||
child: Container(
|
||||
@@ -128,97 +124,27 @@ class _MyDevelopmentMuscleState extends State<MyDevelopmentMusclePage> with Comm
|
||||
t("Here you see you development in the last period."),
|
||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
avatar: Icon(
|
||||
Icons.bubble_chart,
|
||||
),
|
||||
label: Text(t('Sum Of Mass')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.diagramType == DiagramType.sumMass,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDiagramTypeChange(diagramType: DiagramType.sumMass))},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(Icons.accessibility_new),
|
||||
label: Text(t('One Rep Max')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.diagramType == DiagramType.oneRepMax,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDiagramTypeChange(diagramType: DiagramType.oneRepMax))},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(Icons.perm_device_information),
|
||||
label: Text(t('Percent')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.diagramType == DiagramType.percent,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDiagramTypeChange(diagramType: DiagramType.percent))},
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Detailed')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
disabledColor: Colors.black26,
|
||||
selectedColor: Colors.greenAccent,
|
||||
selected: bloc.dateRate == DateRate.daily,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDateRateChange(dateRate: DateRate.daily))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Weekly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.white12,
|
||||
tooltip: "Heti bontás",
|
||||
selected: bloc.dateRate == DateRate.weekly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDateRateChange(dateRate: DateRate.weekly))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Monthly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.black26,
|
||||
selected: bloc.dateRate == DateRate.monthly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDateRateChange(dateRate: DateRate.monthly))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Yearly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.white70,
|
||||
selected: bloc.dateRate == DateRate.yearly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentByMuscleDateRateChange(dateRate: DateRate.yearly))},
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)));
|
||||
return explanation;
|
||||
}
|
||||
|
||||
List<Widget> _getTreeChildren(DevelopmentByMuscleBloc bloc) {
|
||||
List<Widget> exerciseTypes = [];
|
||||
|
||||
Card explanation = this.getExplanation(bloc);
|
||||
exerciseTypes.add(explanation);
|
||||
|
||||
LinkedHashMap<String, dynamic> rc = LinkedHashMap();
|
||||
tree.forEach((name, list) {
|
||||
bloc.workoutTreeRepository.sortedTree.forEach((name, list) {
|
||||
rc = _getChildList(list, bloc);
|
||||
final List<Widget> children = rc['list'];
|
||||
final bool hasNoData = rc['hasNoData'];
|
||||
exerciseTypes.add(Container(
|
||||
margin: const EdgeInsets.only(left: 4.0),
|
||||
margin: const EdgeInsets.only(left: 8.0),
|
||||
child: TreeViewChild(
|
||||
startExpanded: false,
|
||||
parent: _getExerciseWidget(exerciseTypeName: name, noData: hasNoData),
|
||||
parent: _getExerciseGroupWidget(exerciseTypeName: name, noData: hasNoData),
|
||||
children: children,
|
||||
)));
|
||||
});
|
||||
@@ -226,104 +152,47 @@ class _MyDevelopmentMuscleState extends State<MyDevelopmentMusclePage> with Comm
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
Widget _getExerciseGroupWidget({required String exerciseTypeName, bool noData = false}) {
|
||||
return TreeviewParentWidget(
|
||||
text: exerciseTypeName,
|
||||
backgroundColor: !noData ? Colors.white38 : Colors.white12,
|
||||
color: !noData ? Colors.blue[800] : Colors.blue[100],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getExerciseWidget({required String exerciseTypeName, bool noData = false}) {
|
||||
return TreeviewParentWidget(
|
||||
text: exerciseTypeName,
|
||||
backgroundColor: !noData ? Colors.white38 : Colors.white12,
|
||||
color: !noData ? Colors.blue[800] : Colors.grey[400]);
|
||||
text: exerciseTypeName,
|
||||
backgroundColor: !noData ? Colors.white38 : Colors.white12,
|
||||
color: !noData ? Colors.blue[700] : Colors.blue[100],
|
||||
fontSize: 16,
|
||||
);
|
||||
}
|
||||
|
||||
LinkedHashMap<String, dynamic> _getChildList(List<WorkoutMenuTree> listWorkoutTree, DevelopmentByMuscleBloc bloc) {
|
||||
LinkedHashMap<String, dynamic> rc = LinkedHashMap();
|
||||
List<Widget> list = [];
|
||||
bool hasSummaryNoData = true;
|
||||
listWorkoutTree.forEach((element) {
|
||||
final bool hasNoData = (bloc.listChartData[element.exerciseTypeId] == null);
|
||||
hasSummaryNoData = hasSummaryNoData && hasNoData;
|
||||
String unit = " kg";
|
||||
if (bloc.diagramType == DiagramType.percent) {
|
||||
unit = " %";
|
||||
}
|
||||
list.add(SizedBox(
|
||||
width: cWidth * 0.85,
|
||||
height: hasNoData ? 0 : 200,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 5, top: 5, right: 5, bottom: 5),
|
||||
color: Colors.white70,
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
hasNoData
|
||||
? Container()
|
||||
: Text(
|
||||
element.exerciseType!.nameTranslation,
|
||||
style: TextStyle(color: Colors.deepOrange),
|
||||
),
|
||||
hasNoData
|
||||
? Container(
|
||||
//child: Text("no data for " + element.exerciseType.nameTranslation),
|
||||
)
|
||||
: Expanded(
|
||||
//fit: FlexFit.loose,
|
||||
child: BarChart(
|
||||
BarChartData(
|
||||
alignment: BarChartAlignment.spaceAround,
|
||||
barTouchData: BarTouchData(
|
||||
touchTooltipData: BarTouchTooltipData(
|
||||
tooltipBgColor: Colors.white70,
|
||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||
return BarTooltipItem(
|
||||
rod.y.toStringAsFixed(0) + unit,
|
||||
TextStyle(color: Colors.black54, fontSize: 12, fontWeight: FontWeight.bold),
|
||||
);
|
||||
}),
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
bottomTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTextStyles: (_) => TextStyle(fontSize: 8, color: Colors.blueGrey),
|
||||
getTitles: (double value) {
|
||||
var date = new DateTime.fromMillisecondsSinceEpoch(value.toInt());
|
||||
String strDate = getDatePart(date, bloc.dateRate);
|
||||
return strDate;
|
||||
},
|
||||
),
|
||||
leftTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTextStyles: (_) => TextStyle(fontSize: 8, color: Colors.blueGrey),
|
||||
interval: bloc.listChartData[element.exerciseTypeId] == null ||
|
||||
bloc.listChartData[element.exerciseTypeId]!.interval == 0
|
||||
? 100
|
||||
: bloc.listChartData[element.exerciseTypeId]!.interval,
|
||||
margin: 10,
|
||||
getTitles: (double value) {
|
||||
return value.toStringAsFixed(0) + unit;
|
||||
})),
|
||||
borderData: FlBorderData(
|
||||
show: false,
|
||||
),
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
checkToShowHorizontalLine: (value) => value % bloc.listChartData[element.exerciseTypeId]!.gridInterval == 0,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return FlLine(
|
||||
color: Colors.black26,
|
||||
strokeWidth: 0.5,
|
||||
);
|
||||
},
|
||||
),
|
||||
groupsSpace: 2,
|
||||
barGroups:
|
||||
bloc.listChartData[element.exerciseTypeId] == null ? [] : bloc.listChartData[element.exerciseTypeId]!.data,
|
||||
),
|
||||
swapAnimationDuration: Duration(milliseconds: 1200),
|
||||
),
|
||||
)
|
||||
]),
|
||||
),
|
||||
));
|
||||
});
|
||||
rc['list'] = list;
|
||||
rc['hasNoData'] = hasSummaryNoData;
|
||||
rc['hasNoData'] = false;
|
||||
listWorkoutTree.forEach((element) {
|
||||
list.add(Container(
|
||||
margin: const EdgeInsets.only(left: 8.0),
|
||||
child: TreeViewChild(
|
||||
parent: _getExerciseWidget(exerciseTypeName: element.exerciseType!.nameTranslation),
|
||||
children: [],
|
||||
onTap: () => onPressed(bloc, element),
|
||||
)));
|
||||
});
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void onPressed(DevelopmentByMuscleBloc bloc, WorkoutMenuTree element) {
|
||||
HashMap<String, dynamic> args = HashMap();
|
||||
args['exerciseRepository'] = bloc.exerciseRepository;
|
||||
args['workoutTreeRepository'] = bloc.workoutTreeRepository;
|
||||
args['exerciseTypeId'] = element.exerciseTypeId;
|
||||
args['title'] = t("Muscle development") + ": " + "${element.exerciseType!.nameTranslation}";
|
||||
Navigator.of(context).pushNamed('developmentDiagramPage', arguments: args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_common.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_premium.dart';
|
||||
import 'package:badges/badges.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
@@ -68,10 +66,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
text: t("My Training Logs"),
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
image: "asset/image/edzesnaplom400400.jpg",
|
||||
left: 5,
|
||||
onTap: () => Navigator.of(context).pushNamed('mydevelopmentLog', arguments: args),
|
||||
@@ -110,10 +105,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
text: t("My Whole Body Development"),
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
backgroundColor: Colors.black54.withOpacity(0.4)),
|
||||
fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4)),
|
||||
),
|
||||
image: "asset/image/testemfejl400x400.jpg",
|
||||
left: 5,
|
||||
@@ -132,8 +124,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
warning: true,
|
||||
title: t("Warning"),
|
||||
descriptions: t("Please log in"),
|
||||
description2:
|
||||
t("because only that way can we show you the personalized development diagrams and analysises"),
|
||||
description2: t("because only that way can we show you the personalized development diagrams and analysises"),
|
||||
text: "OK",
|
||||
onTap: () => Navigator.of(context).popAndPushNamed("login"),
|
||||
onCancel: () => {
|
||||
@@ -199,65 +190,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
onTap: () => {Navigator.of(context).pushNamed('mydevelopmentMusclePage', arguments: args)},
|
||||
isLocked: true,
|
||||
))),
|
||||
Badge(
|
||||
elevation: 0,
|
||||
padding: EdgeInsets.all(0),
|
||||
position: BadgePosition.topStart(top: -12, start: -12),
|
||||
animationDuration: Duration(milliseconds: 1500),
|
||||
animationType: BadgeAnimationType.fade,
|
||||
badgeColor: Colors.transparent,
|
||||
showBadge: Cache().hasPurchased,
|
||||
badgeContent: IconButton(
|
||||
iconSize: 36,
|
||||
onPressed: () => showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
title: t("Premium function"),
|
||||
descriptions: Cache().canTrial()
|
||||
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
|
||||
: t("This is a premium function, you can reach it only with a valid subscription"),
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
text: '',
|
||||
);
|
||||
}),
|
||||
icon: Icon(
|
||||
Icons.star,
|
||||
color: Colors.orange[600],
|
||||
)),
|
||||
child: ImageButton(
|
||||
width: imageWidth,
|
||||
left: 5,
|
||||
textAlignment: Alignment.topLeft,
|
||||
text: t("Predictions"),
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
image: "asset/image/predictions.jpg",
|
||||
onTap: () => {
|
||||
if (Cache().userLoggedIn != null)
|
||||
{
|
||||
Track().track(TrackingEvent.prediction),
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogPremium(
|
||||
unlocked: Cache().hasPurchased,
|
||||
unlockRound: 12,
|
||||
function: "Predictions",
|
||||
unlockedText: null,
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
);
|
||||
})
|
||||
}
|
||||
},
|
||||
isLocked: true,
|
||||
)),
|
||||
//developmentWidget(imageWidth, "Development Size", "asset/image/predictions.jpg", TrackingEvent.my_size_development, args),
|
||||
developmentWidget(imageWidth, t("Development of My Sizes"), "asset/image/sizes_q.jpg", TrackingEvent.my_size_development, args),
|
||||
hiddenWidget(customerRepository, exerciseRepository),
|
||||
]),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
@@ -278,15 +211,14 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
textAlignment: Alignment.topLeft,
|
||||
text: t(title),
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle:
|
||||
TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
textStyle: TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
image: imageUrl,
|
||||
onTap: () => {
|
||||
if (Cache().userLoggedIn != null)
|
||||
{
|
||||
Track().track(trackingEvent),
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]),
|
||||
Future.delayed(Duration(seconds: 400)),
|
||||
//SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]),
|
||||
//Future.delayed(Duration(seconds: 400)),
|
||||
Navigator.of(context).pushNamed('mydevelopmentSizesPage', arguments: args),
|
||||
|
||||
/* showDialog(
|
||||
@@ -302,7 +234,7 @@ class _MyDevelopmentPage extends State<MyDevelopmentPage> with Trans {
|
||||
}) */
|
||||
}
|
||||
},
|
||||
isLocked: true,
|
||||
isLocked: false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/development_sizes/development_sizes_bloc.dart';
|
||||
import 'package:aitrainer_app/library/custom_icon_icons.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
@@ -7,7 +10,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/input_dialog_widget.dart';
|
||||
|
||||
class SizesDevelopmentPage extends StatefulWidget {
|
||||
const SizesDevelopmentPage();
|
||||
@@ -24,8 +26,8 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
create: (context) => DevelopmentSizesBloc(customerRepository: CustomerRepository())..add(DevelopmentSizesLoad()),
|
||||
child: BlocConsumer<DevelopmentSizesBloc, DevelopmentSizesState>(listener: (context, state) {
|
||||
if (state is DevelopmentSizesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white)))));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar((SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white)))));
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
final bloc = BlocProvider.of<DevelopmentSizesBloc>(context);
|
||||
@@ -41,30 +43,31 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
}
|
||||
|
||||
Widget getForm(DevelopmentSizesBloc bloc) {
|
||||
return Form(
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
appBar: AppBarNav(depth: 1),
|
||||
body: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_black_background.jpg'),
|
||||
fit: BoxFit.fill,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
appBar: AppBarNav(depth: 1),
|
||||
body: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_black_background.jpg'),
|
||||
fit: BoxFit.fill,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Stack(
|
||||
alignment: Alignment.center,
|
||||
children: getSizeFigure(bloc),
|
||||
)
|
||||
]))),
|
||||
)));
|
||||
getHeader(bloc),
|
||||
Stack(
|
||||
alignment: Alignment.center,
|
||||
children: getSizeFigure(bloc),
|
||||
)
|
||||
])))),
|
||||
));
|
||||
}
|
||||
|
||||
List<Widget> getSizeFigure(DevelopmentSizesBloc bloc) {
|
||||
@@ -91,7 +94,6 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
top: bloc.customerRepository.getWeightCoordinate(bloc.isMan, isTop: true)!.toDouble(),
|
||||
left: bloc.customerRepository.getWeightCoordinate(bloc.isMan, isTop: false, isLeft: true)!.toDouble() - 45,
|
||||
child: GestureDetector(
|
||||
//onTap: () => onPressed(bloc.customerRepository.getPropertyByName("Weight")),
|
||||
child: Image.asset(
|
||||
"asset/image/merleg.png",
|
||||
height: 120,
|
||||
@@ -101,30 +103,6 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
));
|
||||
|
||||
list.addAll(getSizeElements(bloc));
|
||||
list.add(
|
||||
Positioned(
|
||||
top: mediaHeight * .07,
|
||||
left: bloc.isMan ? mediaWidth * .62 : mediaWidth * .65,
|
||||
child: Stack(
|
||||
alignment: Alignment.topLeft,
|
||||
children: [
|
||||
SizedBox(height: 80, width: 100),
|
||||
Text(t("Your Size Diagrams"),
|
||||
maxLines: 2,
|
||||
style: GoogleFonts.archivoBlack(
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(5.0, 5.0),
|
||||
blurRadius: 3.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
],
|
||||
fontSize: 20,
|
||||
color: Colors.orange[500],
|
||||
)),
|
||||
],
|
||||
)),
|
||||
);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -139,21 +117,21 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
left: element.left!.toDouble(),
|
||||
child: element.value != 0
|
||||
? Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: bloc.isMan ? Colors.green[800] : Color(0xFFEA776C),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(20),
|
||||
Radius.circular(40),
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.trending_up, color: Colors.green),
|
||||
padding: EdgeInsets.zero,
|
||||
color: Colors.red[800],
|
||||
splashColor: Colors.amber,
|
||||
onPressed: () => onPressed(element),
|
||||
padding: EdgeInsets.only(left: 1, top: 1, right: 1, bottom: 1),
|
||||
child: TextButton(
|
||||
child: Text(
|
||||
bloc.customerRepository.getCustomerProperty(element.propertyName)!.propertyValue.toStringAsFixed(0),
|
||||
style: GoogleFonts.inter(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
onPressed: () => onPressed(element, bloc, element.propertyName),
|
||||
))
|
||||
: Container(
|
||||
width: 23,
|
||||
@@ -166,11 +144,11 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.trending_up, color: Colors.red),
|
||||
icon: Icon(CustomIcon.minus_circle, color: Colors.red),
|
||||
padding: EdgeInsets.zero,
|
||||
color: Colors.red[800],
|
||||
splashColor: Colors.amber,
|
||||
onPressed: () => onPressed(element),
|
||||
onPressed: () => onPressed(element, bloc, element.propertyName),
|
||||
))),
|
||||
);
|
||||
});
|
||||
@@ -178,17 +156,53 @@ class _SizeState extends State<SizesDevelopmentPage> with Trans {
|
||||
return list;
|
||||
}
|
||||
|
||||
void onPressed(Property element) {
|
||||
print(element.propertyName);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => InputDialog(
|
||||
title: t("Size Of Your"),
|
||||
subtitle: element.propertyNameTranslation,
|
||||
initialValue: element.value!,
|
||||
onChanged: (value) {
|
||||
//widget.exerciseBloc.add(ExerciseNewSizeChange(propertyName: element.propertyName, value: value));
|
||||
},
|
||||
));
|
||||
void onPressed(Property element, DevelopmentSizesBloc bloc, String propertyName) {
|
||||
HashMap<String, dynamic> args = HashMap();
|
||||
args['customerRepository'] = bloc.customerRepository;
|
||||
args['property'] = element;
|
||||
args['title'] = t("Size development: ") + " " + propertyName;
|
||||
Navigator.of(context).pushNamed('developmentDiagramPage', arguments: args);
|
||||
}
|
||||
|
||||
Widget getHeader(DevelopmentSizesBloc bloc) {
|
||||
return Card(
|
||||
color: Colors.white60,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_plainblack_background.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.only(left: 10, right: 5, top: 12, bottom: 8),
|
||||
child: Column(children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info,
|
||||
color: Colors.orangeAccent,
|
||||
),
|
||||
Text(" "),
|
||||
Text(
|
||||
t("Red icon means you have not saved this size."),
|
||||
overflow: TextOverflow.clip,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
t("Tap on the green icon to see your development in a diagram"),
|
||||
overflow: TextOverflow.clip,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
child: Form(
|
||||
child: BlocConsumer<SettingsBloc, SettingsState>(listener: (context, state) {
|
||||
if (state is SettingsError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
} else if (state is SettingsReady) {
|
||||
menuBloc.add(MenuRecreateTree());
|
||||
Navigator.of(context).pushNamed("home");
|
||||
@@ -110,7 +110,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
? 1
|
||||
: 0
|
||||
: 1,
|
||||
activeBgColor: Colors.indigo,
|
||||
activeBgColor: [Colors.indigo],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.white60,
|
||||
inactiveFgColor: Colors.grey[900],
|
||||
@@ -120,6 +120,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
print("Server setting to: $live");
|
||||
settingsBloc.add(SettingsSetServer(live: index == 0));
|
||||
},
|
||||
totalSwitches: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -133,7 +134,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
minHeight: 30.0,
|
||||
fontSize: 14.0,
|
||||
initialLabelIndex: Cache().hasHardware! ? 0 : 1,
|
||||
activeBgColor: Colors.indigo,
|
||||
activeBgColor: [Colors.indigo],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.white60,
|
||||
inactiveFgColor: Colors.grey[900],
|
||||
@@ -141,6 +142,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
onToggle: (index) {
|
||||
settingsBloc.add(SettingsSetHardware(hasHardware: index == 0));
|
||||
},
|
||||
totalSwitches: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -155,7 +157,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
minHeight: 30.0,
|
||||
fontSize: 14.0,
|
||||
initialLabelIndex: 0,
|
||||
activeBgColor: Colors.indigo,
|
||||
activeBgColor: [Colors.indigo],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.white60,
|
||||
inactiveFgColor: Colors.grey[900],
|
||||
@@ -173,6 +175,7 @@ class SettingsPage extends StatelessWidget with Trans {
|
||||
tutorialBloc.add(TutorialStart());
|
||||
Track().track(TrackingEvent.tutorial_activate);
|
||||
},
|
||||
totalSwitches: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/development_diagram/development_diagram_bloc.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/diagram_data.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
import '../repository/customer_repository.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class DevelopmentDiagram extends StatelessWidget with Common, Trans {
|
||||
CustomerRepository? customerRepository;
|
||||
ExerciseRepository? exerciseRepository;
|
||||
WorkoutTreeRepository? workoutTreeRepository;
|
||||
int? exerciseTypeId;
|
||||
Property? property;
|
||||
late String title;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setContext(context);
|
||||
final HashMap<String, dynamic> args = ModalRoute.of(context)!.settings.arguments as HashMap<String, dynamic>;
|
||||
this.customerRepository = args['customerRepository'];
|
||||
this.exerciseRepository = args['exerciseRepository'];
|
||||
this.exerciseTypeId = args['exerciseTypeId'];
|
||||
this.property = args['property'];
|
||||
this.title = args['title'];
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 1),
|
||||
body: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_plainblack_background.jpg'),
|
||||
fit: BoxFit.fill,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: BlocProvider(
|
||||
create: (context) => customerRepository == null
|
||||
? DevelopmentDiagramBloc(diagramTitle: title, exerciseRepository: exerciseRepository, exerciseTypeId: exerciseTypeId)
|
||||
: DevelopmentDiagramBloc(
|
||||
diagramTitle: title,
|
||||
customerRepository: customerRepository,
|
||||
propertyName: property!.propertyName,
|
||||
),
|
||||
child: BlocConsumer<DevelopmentDiagramBloc, DevelopmentDiagramState>(
|
||||
listener: (context, state) {
|
||||
if (state is DevelopmentDiagramError) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
warning: true,
|
||||
title: t("Warning"),
|
||||
descriptions: t(state.message),
|
||||
text: "OK",
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
onCancel: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final DevelopmentDiagramBloc bloc = BlocProvider.of<DevelopmentDiagramBloc>(context);
|
||||
return ModalProgressHUD(
|
||||
child: getDiagramWidget(bloc),
|
||||
inAsyncCall: state is DevelopmentDiagramLoading,
|
||||
opacity: 0.5,
|
||||
color: Colors.black54,
|
||||
progressIndicator: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
)));
|
||||
}
|
||||
|
||||
Widget getExplanation(DevelopmentDiagramBloc bloc) {
|
||||
return Container(
|
||||
color: Colors.white54,
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Wrap(
|
||||
direction: Axis.horizontal,
|
||||
runSpacing: 5,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info,
|
||||
color: Colors.orangeAccent,
|
||||
),
|
||||
Text(" "),
|
||||
Text(
|
||||
bloc.diagramTitle,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getFilterData(DevelopmentDiagramBloc bloc) {
|
||||
return bloc.isGroup
|
||||
? Container(
|
||||
color: Colors.transparent,
|
||||
// padding: EdgeInsets.all(5),
|
||||
child: Wrap(
|
||||
direction: Axis.horizontal,
|
||||
spacing: 10,
|
||||
runSpacing: 5,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
avatar: Icon(
|
||||
Icons.bubble_chart,
|
||||
),
|
||||
label: Text(t('Sum Of Mass')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.group == DiagramGroup.sumMass,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeGroup(group: DiagramGroup.sumMass))},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(Icons.accessibility_new),
|
||||
label: Text(t('One Rep Max')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.group == DiagramGroup.oneRepMax,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeGroup(group: DiagramGroup.oneRepMax))},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(Icons.perm_device_information),
|
||||
label: Text(t('Percent')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.lightBlueAccent,
|
||||
selected: bloc.group == DiagramGroup.percent,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeGroup(group: DiagramGroup.percent))},
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Offstage();
|
||||
}
|
||||
|
||||
Widget getGroupDate(DevelopmentDiagramBloc bloc) {
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
//padding: EdgeInsets.all(5),
|
||||
child: Wrap(
|
||||
direction: Axis.horizontal,
|
||||
spacing: 10,
|
||||
runSpacing: 5,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Detailed')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
disabledColor: Colors.black26,
|
||||
selectedColor: Colors.greenAccent,
|
||||
selected: bloc.dateFilter == DiagramDateFilter.daily,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeDateFormat(dateFilter: DiagramDateFilter.daily))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Weekly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.white12,
|
||||
selected: bloc.dateFilter == DiagramDateFilter.weekly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeDateFormat(dateFilter: DiagramDateFilter.weekly))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Monthly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.black26,
|
||||
selected: bloc.dateFilter == DiagramDateFilter.monthly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeDateFormat(dateFilter: DiagramDateFilter.monthly))},
|
||||
),
|
||||
ChoiceChip(
|
||||
labelPadding: EdgeInsets.only(right: 5),
|
||||
avatar: Icon(Icons.timer),
|
||||
label: Text(t('Yearly')),
|
||||
labelStyle: TextStyle(fontSize: 9, color: Colors.black),
|
||||
selectedColor: Colors.greenAccent,
|
||||
disabledColor: Colors.white70,
|
||||
selected: bloc.dateFilter == DiagramDateFilter.yearly,
|
||||
onSelected: (value) => {bloc.add(DevelopmentDiagramChangeDateFormat(dateFilter: DiagramDateFilter.yearly))},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getDiagramWidget(DevelopmentDiagramBloc bloc) {
|
||||
double cHeight = MediaQuery.of(context).size.height;
|
||||
return SingleChildScrollView(
|
||||
child: Column(children: [
|
||||
getExplanation(bloc),
|
||||
getFilterData(bloc),
|
||||
getGroupDate(bloc),
|
||||
Container(
|
||||
height: cHeight * .70,
|
||||
child: SfCartesianChart(
|
||||
/* title: ChartTitle(
|
||||
text: property.propertyNameTranslation,
|
||||
textStyle: TextStyle(color: Colors.white, fontFamily: 'Roboto', fontSize: 20, fontWeight: FontWeight.w800)), */
|
||||
plotAreaBorderColor: Colors.amber[50],
|
||||
primaryXAxis: CategoryAxis(
|
||||
borderColor: Colors.white12,
|
||||
axisLine: AxisLine(color: Colors.deepOrange, width: 2, dashArray: <double>[5, 5]),
|
||||
labelStyle:
|
||||
TextStyle(color: Colors.deepOrange, fontFamily: 'Roboto', fontSize: 14, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500),
|
||||
//title: AxisTitle(text: t('Date'), textStyle: TextStyle(color: Colors.white, fontFamily: 'Roboto', fontSize: 20, fontWeight: FontWeight.w800))
|
||||
),
|
||||
primaryYAxis: CategoryAxis(
|
||||
borderColor: Colors.white12,
|
||||
labelStyle:
|
||||
TextStyle(color: Colors.deepOrange, fontFamily: 'Roboto', fontSize: 14, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500),
|
||||
axisLine: AxisLine(color: Colors.deepOrange, width: 2, dashArray: <double>[15, 5]),
|
||||
),
|
||||
palette: <Color>[Colors.white, Colors.orange, Colors.yellow],
|
||||
zoomPanBehavior: ZoomPanBehavior(
|
||||
// Performs zooming on double tap
|
||||
|
||||
enableDoubleTapZooming: true),
|
||||
/* trackballBehavior: TrackballBehavior(
|
||||
// Enables the trackball
|
||||
enable: true,
|
||||
activationMode: ActivationMode.singleTap,
|
||||
tooltipSettings: InteractiveTooltip(
|
||||
enable: true,
|
||||
color: Colors.white,
|
||||
format: 'point.x : point.y',
|
||||
)), */
|
||||
annotations: <CartesianChartAnnotation>[
|
||||
/* CartesianChartAnnotation(
|
||||
coordinateUnit: CoordinateUnit.percentage,
|
||||
verticalAlignment: ChartAlignment.center,
|
||||
horizontalAlignment: ChartAlignment.center,
|
||||
widget: getExplanation(bloc),
|
||||
x: '50%',
|
||||
y: '3%'), */
|
||||
CartesianChartAnnotation(
|
||||
coordinateUnit: CoordinateUnit.percentage,
|
||||
verticalAlignment: ChartAlignment.center,
|
||||
horizontalAlignment: ChartAlignment.center,
|
||||
widget: Text(t("Double Tap: Zoom"), style: GoogleFonts.inter(color: Colors.yellow, fontSize: 12)),
|
||||
x: '55%',
|
||||
y: '85%')
|
||||
],
|
||||
series: <ChartSeries>[
|
||||
SplineSeries<DiagramData, String>(
|
||||
markerSettings: MarkerSettings(isVisible: true, shape: DataMarkerType.diamond),
|
||||
dataSource: bloc.diagramData,
|
||||
dataLabelSettings: DataLabelSettings(isVisible: true, color: Colors.white),
|
||||
xValueMapper: (DiagramData data, _) => data.x,
|
||||
yValueMapper: (DiagramData data, _) => data.y,
|
||||
dataLabelMapper: (DiagramData data, _) => data.y!.toStringAsFixed(1))
|
||||
],
|
||||
))
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,11 @@ class _SizeState extends State<SizeWidget> with Trans {
|
||||
45,
|
||||
child: GestureDetector(
|
||||
onTap: () => {
|
||||
if (widget.exerciseBloc.customerRepository.getPropertyByName("Weight") != null)
|
||||
|
||||
if (widget.exerciseBloc.customerRepository.getPropertyByName("Weight") != null)
|
||||
{
|
||||
onPressed(widget.exerciseBloc.customerRepository.getPropertyByName("Weight")!),
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Image.asset(
|
||||
"asset/image/merleg.png",
|
||||
|
||||
Reference in New Issue
Block a user