diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart index 474e4705..69207e24 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart @@ -91,6 +91,7 @@ class MyProfileBloc extends Bloc { hyperFormController: currentState.hyperFormController, selectedCity: currentState.selectedCity, selectedCountry: currentState.selectedCountry, + selectedActivity: currentState.selectedActivity, )); } else { var plans = [] @@ -168,7 +169,7 @@ class MyProfileBloc extends Bloc { }; } } - + print(data['userDetails']); /*print(chartPoints); print(circumferences);*/ /*print(weights); @@ -229,6 +230,8 @@ class MyProfileBloc extends Bloc { 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 { 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 } diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart index 5350abe5..acf48231 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart @@ -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, ); diff --git a/lib/widgets/custom_expandable_list.dart b/lib/widgets/custom_expandable_list.dart index f20ac19e..3d2190a5 100644 --- a/lib/widgets/custom_expandable_list.dart +++ b/lib/widgets/custom_expandable_list.dart @@ -116,6 +116,13 @@ class _ExpandableListState extends State { List countries = [ 'Россия', ]; + List 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 { decoration: InputDecoration(labelText: 'additional_information'.tr), maxLines: null, ), + DropdownButtonFormField( + hint: Text(state.selectedActivity ?? "Не выбрано"), + value: state.selectedActivity, + onChanged: setActivity(state), + items: activities.map>((String value) { + return DropdownMenuItem( + 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 { }; } + setActivity(MyProfileLoadedState state) { + return (newValue) { + // Обработчик изменения выбранной страны + setSelectedActivity(state, newValue); + }; + } + inputTime(BuildContext context, MyProfileLoadedState state) { return () { showDatePicker( @@ -287,6 +319,12 @@ class _ExpandableListState extends State { }); } + void setSelectedActivity(MyProfileLoadedState? state, String? newValue) { + setState(() { + state!.selectedActivity = newValue; + }); + } + Future sendProfileData(MyProfileLoadedState? state) async { try { // Создаем JSON объект с данными профиля @@ -311,6 +349,9 @@ class _ExpandableListState extends State { '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 { 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; // Возвращаемое значение по умолчанию, если уровень активности не распознан + } + } }