forked from eatvio/eatvio_app
feat: settings (data save) + new fields
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.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/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/widgets/custom_drop_down.dart';
|
||||
import 'package:eatvio_app/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 ProfileDetailsModel profileDetailsModel;
|
||||
final bool isPublicProfile;
|
||||
final SettingsEntity settingsEntity;
|
||||
|
||||
const GeneralInfoScreen({
|
||||
super.key,
|
||||
required this.profileDetailsModel,
|
||||
required this.isPublicProfile,
|
||||
required this.settingsEntity,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -24,25 +25,36 @@ class GeneralInfoScreen extends StatefulWidget {
|
||||
class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
final firstNameController = TextEditingController();
|
||||
final lastNameController = TextEditingController();
|
||||
final genderController = TextEditingController();
|
||||
late DateTime selectedDate;
|
||||
late SelectionPopupModel gender;
|
||||
final countryController = TextEditingController();
|
||||
final cityController = TextEditingController();
|
||||
final languageController = TextEditingController();
|
||||
late DateTime selectedDate;
|
||||
late bool isPublicProfile;
|
||||
late SelectionPopupModel isPublicProfile;
|
||||
|
||||
final List<SelectionPopupModel> genderSelectionPopupList = [
|
||||
SelectionPopupModel(id: 0, title: 'Женский', value: 'female'),
|
||||
SelectionPopupModel(id: 1, title: 'Мужской', value: 'male'),
|
||||
];
|
||||
|
||||
final List<SelectionPopupModel> isPublicProfileSelectionPopupList = [
|
||||
SelectionPopupModel(id: 0, title: 'Только зарегистрированным', value: false),
|
||||
SelectionPopupModel(id: 1, title: 'Всем', value: true),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
selectedDate = DateTime.now();
|
||||
firstNameController.text = widget.profileDetailsModel.firstName;
|
||||
lastNameController.text = widget.profileDetailsModel.lastName;
|
||||
selectedDate = DateTime.parse(widget.profileDetailsModel.birthdate);
|
||||
genderController.text = widget.profileDetailsModel.gender;
|
||||
countryController.text = widget.profileDetailsModel.country;
|
||||
cityController.text = widget.profileDetailsModel.city;
|
||||
languageController.text = widget.profileDetailsModel.lang;
|
||||
isPublicProfile = widget.isPublicProfile;
|
||||
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
|
||||
@@ -78,43 +90,60 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
SizedBox(height: 16),
|
||||
Text(s.date_of_birth),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
initialValue: selectedDate.format('dd MMMM yyyy', 'ru'),
|
||||
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),
|
||||
CustomTextFormField(
|
||||
controller: genderController,
|
||||
onChanged: (newValue) {},
|
||||
CustomDropDown(
|
||||
items: genderSelectionPopupList,
|
||||
value: gender,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
gender = newValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Страна'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: countryController,
|
||||
onChanged: (newValue) {},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Город'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: cityController,
|
||||
onChanged: (newValue) {},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Предпочтительный язык общения'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: languageController,
|
||||
onChanged: (newValue) {},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('Показывать анкету'),
|
||||
SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
initialValue: isPublicProfile ? 'Всем' : 'Только зарегистрированным',
|
||||
onChanged: (newValue) {},
|
||||
CustomDropDown(
|
||||
items: isPublicProfileSelectionPopupList,
|
||||
value: isPublicProfile,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
isPublicProfile = newValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -133,8 +162,6 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
onDateTimeChanged: (DateTime newDateTime) {
|
||||
setState(() {
|
||||
selectedDate = newDateTime;
|
||||
// final registrationCubit = context.read<RegistrationCubit>();
|
||||
// registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(birthdate: selectedDate.toString()));
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -162,7 +189,25 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
|
||||
_saveButton() {
|
||||
return InkWell(
|
||||
onTap: () => GoRouter.of(context).pop(),
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user