import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart'; import 'package:eatvio_app/core/utils/date_time_utils.dart'; import 'package:eatvio_app/core/widgets/custom_drop_down.dart'; import 'package:eatvio_app/features/settings/entities/settings_entity.dart'; import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/widgets/custom_text_form_field.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class GeneralInfoScreen extends StatefulWidget { final SettingsEntity settingsEntity; const GeneralInfoScreen({ super.key, required this.settingsEntity, }); @override State createState() => _GeneralInfoScreenState(); } class _GeneralInfoScreenState extends State { final firstNameController = TextEditingController(); final lastNameController = TextEditingController(); late DateTime selectedDate; late SelectionPopupModel gender; final countryController = TextEditingController(); final cityController = TextEditingController(); final languageController = TextEditingController(); late SelectionPopupModel isPublicProfile; final List genderSelectionPopupList = [ SelectionPopupModel(id: 0, title: 'Женский', value: 'female'), SelectionPopupModel(id: 1, title: 'Мужской', value: 'male'), ]; final List isPublicProfileSelectionPopupList = [ SelectionPopupModel(id: 0, title: 'Только зарегистрированным', value: false), SelectionPopupModel(id: 1, title: 'Всем', value: true), ]; @override void initState() { super.initState(); selectedDate = DateTime.now(); firstNameController.text = widget.settingsEntity.profileDetailsModel.firstName; lastNameController.text = widget.settingsEntity.profileDetailsModel.lastName; selectedDate = DateTime.parse(widget.settingsEntity.profileDetailsModel.birthdate); gender = widget.settingsEntity.profileDetailsModel.gender == 'male' ? genderSelectionPopupList[1] : genderSelectionPopupList[0]; countryController.text = widget.settingsEntity.profileDetailsModel.country; cityController.text = widget.settingsEntity.profileDetailsModel.city; languageController.text = widget.settingsEntity.profileDetailsModel.lang; isPublicProfile = widget.settingsEntity.profileSettingsModel.isPublicProfile == true ? isPublicProfileSelectionPopupList[1] : isPublicProfileSelectionPopupList[0]; } @override Widget build(BuildContext context) { final s = S.of(context); return Scaffold( appBar: AppBar( title: Text('Общая информация'), ), bottomSheet: _saveButton(), body: SingleChildScrollView( physics: const BouncingScrollPhysics(), padding: EdgeInsets.all(16) + EdgeInsets.only(bottom: 64), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(s.first_name), SizedBox(height: 4), CustomTextFormField( controller: firstNameController, hintText: 'Введите имя', onChanged: (newValue) {}, ), SizedBox(height: 16), Text(s.last_name), SizedBox(height: 4), CustomTextFormField( controller: lastNameController, hintText: 'Введите фамилию', onChanged: (newValue) {}, ), SizedBox(height: 16), Text(s.date_of_birth), SizedBox(height: 4), ListTile( onTap: onTapCalendar(context), trailing: Icon( Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade700, ), contentPadding: EdgeInsets.symmetric(horizontal: 12), title: Text(selectedDate.format('dd MMMM yyyy', 'ru')), tileColor: Color(0xFFF6F6F6), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), ), ), SizedBox(height: 16), Text('Пол'), SizedBox(height: 4), CustomDropDown( items: genderSelectionPopupList, value: gender, onChanged: (newValue) { setState(() { gender = newValue; }); }, ), SizedBox(height: 16), Text('Страна'), SizedBox(height: 4), CustomTextFormField( controller: countryController, ), SizedBox(height: 16), Text('Город'), SizedBox(height: 4), CustomTextFormField( controller: cityController, ), SizedBox(height: 16), Text('Предпочтительный язык общения'), SizedBox(height: 4), CustomTextFormField( controller: languageController, ), SizedBox(height: 16), Text('Показывать анкету'), SizedBox(height: 4), CustomDropDown( items: isPublicProfileSelectionPopupList, value: isPublicProfile, onChanged: (newValue) { setState(() { isPublicProfile = newValue; }); }, ), ], ), ), ); } onTapCalendar(BuildContext context) { return () { _showDialog( CupertinoDatePicker( initialDateTime: selectedDate, maximumDate: DateTime.now(), minimumDate: DateTime(1900), mode: CupertinoDatePickerMode.date, onDateTimeChanged: (DateTime newDateTime) { setState(() { selectedDate = newDateTime; }); }, ), ); }; } void _showDialog(Widget child) { showCupertinoModalPopup( context: context, builder: (BuildContext context) => Container( height: 216, padding: const EdgeInsets.only(top: 6), margin: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), color: CupertinoColors.systemBackground.resolveFrom(context), child: SafeArea( top: false, child: child, ), ), ); } _saveButton() { return InkWell( onTap: () { widget.settingsEntity.settingsCubit.updateProfileDetails( profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith( firstName: firstNameController.text, lastName: lastNameController.text, birthdate: selectedDate.toString(), gender: gender.value, country: countryController.text, city: cityController.text, lang: languageController.text, ), ); widget.settingsEntity.settingsCubit.updateProfileSettings( profileSettingsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith( isPublicProfile: isPublicProfile.value, ), ); GoRouter.of(context).pop(); }, borderRadius: BorderRadius.circular(20), child: Ink( height: 52, width: MediaQuery.of(context).size.width - 32, decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), color: appTheme.blueA400, ), child: Center( child: Text( 'Сохранить', style: TextStyle( color: Colors.white, height: 1, fontWeight: FontWeight.w600, fontSize: 18, ), ), ), ), ); } }