From 1cdbc47223d3779b4a638a2a54a13039900f9c87 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 31 Jan 2024 13:17:32 +0300 Subject: [PATCH] Country and city of living selectors added for profile edit. HintText is loaded dynamically --- lib/localization/ru/ru_translations.dart | 1 + .../bloc/my_profile_state.dart | 10 +++ .../my_profile_screen/my_settings_screen.dart | 81 +++++++++++++++++-- 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/lib/localization/ru/ru_translations.dart b/lib/localization/ru/ru_translations.dart index 3408bb9d..779c4f78 100644 --- a/lib/localization/ru/ru_translations.dart +++ b/lib/localization/ru/ru_translations.dart @@ -112,6 +112,7 @@ final Map ru = { "loading": "Загрузка...", "weight_chart": "График веса", "circumferences_chart": "График обхватов", + "city_of_living": "Город проживания", "bodymass_chart": "График ИМТ", "chest": "Грудь", "waist": "Талия", 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 ae748d6e..d82c46af 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 @@ -29,6 +29,8 @@ class MyProfileLoadedState extends MyProfileState { this.chartPoints, this.plans, this.token, + this.selectedCountry, + this.selectedCity, this.chestCircumferenceFormController, this.waistCircumferenceFormController, this.hipCircumferenceFormController, @@ -73,6 +75,8 @@ class MyProfileLoadedState extends MyProfileState { TextEditingController? pillsFormController; TextEditingController? sportsFormController; String? token; + String? selectedCountry; + String? selectedCity; @override List get props => [ @@ -101,6 +105,8 @@ class MyProfileLoadedState extends MyProfileState { allergiesFormController, pillsFormController, sportsFormController, + selectedCountry, + selectedCity, ]; MyProfileLoadedState copyWith({ MyProfileModel? myProfileModelObj, @@ -127,6 +133,8 @@ class MyProfileLoadedState extends MyProfileState { TextEditingController? pillsFormController, TextEditingController? sportsFormController, String? token, + String? selectedCountry, + String? selectedCity, TextEditingController? downPressureFormController, TextEditingController? upPressureFormController, }) { @@ -169,6 +177,8 @@ class MyProfileLoadedState extends MyProfileState { pillsFormController: pillsFormController ?? this.pillsFormController, sportsFormController: sportsFormController ?? this.sportsFormController, token: token ?? this.token, + selectedCountry: selectedCountry ?? this.selectedCountry, + selectedCity: selectedCity ?? this.selectedCity, ); } } diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 7b009b6d..72d10dec 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -306,6 +306,41 @@ class _ExpandableListState extends State { } Widget _buildForm(BuildContext context, MyProfileLoadedState state) { + List cities = [ + 'Москва', + 'Санкт-Петербург', + 'Новосибирск', + 'Екатеринбург', + 'Нижний Новгород', + 'Казань', + 'Челябинск', + 'Омск', + 'Самара', + 'Ростов-на-Дону', + 'Уфа', + 'Красноярск', + 'Воронеж', + 'Пермь', + 'Волгоград', + 'Краснодар', + 'Саратов', + 'Тюмень', + 'Тольятти', + 'Ижевск', + 'Барнаул', + 'Ульяновск', + 'Иркутск', + 'Хабаровск', + 'Ярославль', + 'Владивосток', + 'Махачкала', + 'Томск', + 'Оренбург', + 'Кемерово' + ]; + List countries = [ + 'Россия', + ]; return Column(children: [ TextField( controller: state.firstNameFormController, @@ -328,18 +363,40 @@ class _ExpandableListState extends State { if (selectedDate != null) { setState(() { state.dateFormController!.text = - DateFormat('yyyy-MM-dd').format(selectedDate); + DateFormat('dd-MM-yyyy').format(selectedDate); }); } }); }), - TextField( - controller: state.countryFormController, + DropdownButtonFormField( + value: state.selectedCountry, + hint: Text(state.countryFormController!.text), + onChanged: (newValue) { + // Обработчик изменения выбранной страны + setSelectedCountry(state, newValue); + }, + items: countries.map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), decoration: InputDecoration(labelText: 'country'.tr), ), - TextField( - controller: state.cityFormController, - decoration: InputDecoration(labelText: 'place_of_living'.tr), + DropdownButtonFormField( + hint: Text(state.cityFormController!.text), + value: state.selectedCity, + onChanged: (newValue) { + // Обработчик изменения выбранного города + setSelectedCity(state, newValue); + }, + items: cities.map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + decoration: InputDecoration(labelText: 'city_of_living'.tr), ), TextField( controller: state.weightFormController, @@ -407,4 +464,16 @@ class _ExpandableListState extends State { margin: EdgeInsets.only(top: 20.h, bottom: 20.h)), ]); } + + void setSelectedCity(MyProfileLoadedState? state, String? newValue) { + setState(() { + state!.selectedCity = newValue; + }); + } + + void setSelectedCountry(MyProfileLoadedState? state, String? newValue) { + setState(() { + state!.selectedCountry = newValue; + }); + } }