Merge pull request 'feat(profile): Activity level select added to settings profile edit' (#20) from diary into main

Reviewed-on: maxxkim/eatvio_app#20
This commit is contained in:
2024-04-04 11:51:50 +00:00
3 changed files with 81 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
hyperFormController: currentState.hyperFormController,
selectedCity: currentState.selectedCity,
selectedCountry: currentState.selectedCountry,
selectedActivity: currentState.selectedActivity,
));
} else {
var plans = []
@@ -168,7 +169,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
};
}
}
print(data['userDetails']);
/*print(chartPoints);
print(circumferences);*/
/*print(weights);
@@ -229,6 +230,8 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
TextEditingController(text: data['userDetails']['birthdate']),
selectedCity: data['userDetails']['city'],
selectedCountry: data['userDetails']['country'],
selectedActivity: determineActivityLevel(
double.parse(data['userDetails']['activity_coefficient'])),
));
}
} else {
@@ -245,4 +248,18 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
emit(MyProfileErrorState('Ошибка при получении данных профиля: $e'));
}
}
String determineActivityLevel(double activityFactor) {
if (activityFactor <= 1.2) {
return "сидячий";
} else if (activityFactor <= 1.375) {
return "низкий (1-3 тренировки в неделю по 20 мин)";
} else if (activityFactor <= 1.55) {
return "умеренный (3-4 тренировки в неделю по 30-60 мин)";
} else if (activityFactor <= 1.7) {
return "высокий (5-7 тренировок по 30-60 мин)";
} else {
return "экстремальный (несколько интенсивных тренировок в день)";
}
} // колхоз, но свитчкейсы в дарте странно ведут себя при сравнении double
}

View File

@@ -32,6 +32,7 @@ class MyProfileLoadedState extends MyProfileState {
this.token,
this.selectedCountry,
this.selectedCity,
this.selectedActivity,
this.chestCircumferenceFormController,
this.waistCircumferenceFormController,
this.hipCircumferenceFormController,
@@ -87,6 +88,7 @@ class MyProfileLoadedState extends MyProfileState {
String? token;
String? selectedCountry;
String? selectedCity;
String? selectedActivity;
String? hypoFormController;
String? hyperFormController;
@override
@@ -122,6 +124,7 @@ class MyProfileLoadedState extends MyProfileState {
additionalFormController,
selectedCountry,
selectedCity,
selectedActivity,
hypoFormController,
hyperFormController,
];
@@ -158,6 +161,7 @@ class MyProfileLoadedState extends MyProfileState {
String? token,
String? selectedCountry,
String? selectedCity,
String? selectedActivity,
String? hypoFormController,
String? hyperFormController,
}) {
@@ -209,6 +213,7 @@ class MyProfileLoadedState extends MyProfileState {
token: token ?? this.token,
selectedCountry: selectedCountry ?? this.selectedCountry,
selectedCity: selectedCity ?? this.selectedCity,
selectedActivity: selectedActivity ?? this.selectedActivity,
hypoFormController: hypoFormController ?? this.hypoFormController,
hyperFormController: hyperFormController ?? this.hyperFormController,
);

View File

@@ -116,6 +116,13 @@ class _ExpandableListState extends State<ExpandableList> {
List<String> countries = [
'Россия',
];
List<String> activities = [
'сидячий',
'низкий (1-3 тренировки в неделю по 20 мин)',
'умеренный (3-4 тренировки в неделю по 30-60 мин)',
'высокий (5-7 тренировок по 30-60 мин)',
'экстремальный (несколько интенсивных тренировок в день)'
];
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
return Column(children: [
TextField(
@@ -219,6 +226,24 @@ class _ExpandableListState extends State<ExpandableList> {
decoration: InputDecoration(labelText: 'additional_information'.tr),
maxLines: null,
),
DropdownButtonFormField<String>(
hint: Text(state.selectedActivity ?? "Не выбрано"),
value: state.selectedActivity,
onChanged: setActivity(state),
items: activities.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: SizedBox(
// Используем SizedBox для ограничения ширины элемента списка
width: MediaQuery.of(context).size.width *
0.8, // Устанавливаем желаемую ширину элемента списка
child: Text(value),
),
);
}).toList(),
isExpanded: true, // Расширяем список на всю доступную ширину
decoration: InputDecoration(labelText: 'Активность'),
),
Row(
children: [
HypoSwitch('do_you_have_hypotension_tendency'.tr, state),
@@ -257,6 +282,13 @@ class _ExpandableListState extends State<ExpandableList> {
};
}
setActivity(MyProfileLoadedState state) {
return (newValue) {
// Обработчик изменения выбранной страны
setSelectedActivity(state, newValue);
};
}
inputTime(BuildContext context, MyProfileLoadedState state) {
return () {
showDatePicker(
@@ -287,6 +319,12 @@ class _ExpandableListState extends State<ExpandableList> {
});
}
void setSelectedActivity(MyProfileLoadedState? state, String? newValue) {
setState(() {
state!.selectedActivity = newValue;
});
}
Future<void> sendProfileData(MyProfileLoadedState? state) async {
try {
// Создаем JSON объект с данными профиля
@@ -311,6 +349,9 @@ class _ExpandableListState extends State<ExpandableList> {
'city': state?.selectedCity ?? 'Москва',
'has_hypo': state?.hypoFormController,
'has_hyper': state?.hyperFormController,
'activity_coefficient':
determineActivityFactor(state?.selectedActivity ?? 'сидячий')
.toString,
};
final box = await Hive.openBox('token');
final token = box.get('token');
@@ -357,4 +398,21 @@ class _ExpandableListState extends State<ExpandableList> {
Navigator.pop(context);
};
}
double determineActivityFactor(String activityLevel) {
switch (activityLevel) {
case "сидячий":
return 1.2;
case "низкий (1-3 тренировки в неделю по 20 мин)":
return 1.375;
case "умеренный (3-4 тренировки в неделю по 30-60 мин)":
return 1.55;
case "высокий (5-7 тренировок по 30-60 мин)":
return 1.7;
case "экстремальный (несколько интенсивных тренировок в день)":
return 1.9;
default:
return 1.2; // Возвращаемое значение по умолчанию, если уровень активности не распознан
}
}
}