forked from eatvio/eatvio_app
feat(setting): added profile data apdating for sttings screen, added validation for general info form
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.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';
|
||||
@@ -8,15 +10,11 @@ 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,
|
||||
});
|
||||
const GeneralInfoScreen({super.key, required this.settingsEntity});
|
||||
|
||||
@override
|
||||
State<GeneralInfoScreen> createState() => _GeneralInfoScreenState();
|
||||
@@ -31,6 +29,10 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
final cityController = TextEditingController();
|
||||
final languageController = TextEditingController();
|
||||
late SelectionPopupModel isPublicProfile;
|
||||
bool isLoading = false;
|
||||
bool isNameMissing = false;
|
||||
bool isLastNameMissing = false;
|
||||
bool isLanguageMissing = false;
|
||||
|
||||
final List<SelectionPopupModel> genderSelectionPopupList = [
|
||||
const SelectionPopupModel(id: 0, title: 'Женский', value: 'female'),
|
||||
@@ -53,8 +55,9 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
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];
|
||||
isPublicProfile = widget.settingsEntity.profileSettingsModel.isPublicProfile == true
|
||||
? isPublicProfileSelectionPopupList[1]
|
||||
: isPublicProfileSelectionPopupList[0];
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -62,9 +65,7 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
final s = S.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Общая информация'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Общая информация')),
|
||||
bottomSheet: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
@@ -80,34 +81,31 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
children: [
|
||||
Text(s.first_name),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: firstNameController,
|
||||
hintText: 'Введите имя',
|
||||
onChanged: (newValue) {},
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(hasError: isNameMissing, controller: firstNameController, hintText: 'Введите имя', onChanged: (newValue) {}),
|
||||
if (isNameMissing) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Имя не может быть пустым')],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(s.last_name),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: lastNameController,
|
||||
hintText: 'Введите фамилию',
|
||||
onChanged: (newValue) {},
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(hasError: isLastNameMissing, controller: lastNameController, hintText: 'Введите фамилию', onChanged: (newValue) {}),
|
||||
if (isLastNameMissing) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Фамилия не может быть пустой')],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(s.date_of_birth),
|
||||
const SizedBox(height: 4),
|
||||
ListTile(
|
||||
onTap: onTapCalendar(context),
|
||||
trailing: Icon(
|
||||
Icons.keyboard_arrow_down_rounded,
|
||||
color: Colors.grey.shade700,
|
||||
),
|
||||
trailing: Icon(Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade700),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
title: Text(selectedDate.format('dd MMMM yyyy', 'ru')),
|
||||
tileColor: const Color(0xFFF6F6F6),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Пол'),
|
||||
@@ -124,20 +122,19 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
const SizedBox(height: 16),
|
||||
const Text('Страна'),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: countryController,
|
||||
),
|
||||
CustomTextFormField(controller: countryController),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Город'),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: cityController,
|
||||
),
|
||||
CustomTextFormField(controller: cityController),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Предпочтительный язык общения'),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(
|
||||
controller: languageController,
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(hasError: isLanguageMissing, controller: languageController),
|
||||
if (isLanguageMissing) ...[const SizedBox(height: 4), const ValidationErrorWidget(error: 'Язык не может быть пустым')],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Показывать анкету'),
|
||||
@@ -181,59 +178,92 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
||||
builder: (BuildContext context) => Container(
|
||||
height: 216,
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
margin: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
color: CupertinoColors.systemBackground.resolveFrom(context),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: child,
|
||||
),
|
||||
child: SafeArea(top: false, child: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InkWell _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,
|
||||
bool _checkFields() {
|
||||
bool hasError = false;
|
||||
if (firstNameController.text.isEmpty) {
|
||||
setState(() {
|
||||
isNameMissing = true;
|
||||
});
|
||||
hasError = true;
|
||||
} else {
|
||||
setState(() {
|
||||
isNameMissing = false;
|
||||
});
|
||||
}
|
||||
if (lastNameController.text.isEmpty) {
|
||||
setState(() {
|
||||
isLastNameMissing = true;
|
||||
});
|
||||
hasError = true;
|
||||
} else {
|
||||
setState(() {
|
||||
isLastNameMissing = false;
|
||||
});
|
||||
}
|
||||
if (languageController.text.isEmpty) {
|
||||
setState(() {
|
||||
isLanguageMissing = true;
|
||||
});
|
||||
hasError = true;
|
||||
} else {
|
||||
setState(() {
|
||||
isLanguageMissing = false;
|
||||
});
|
||||
}
|
||||
return hasError;
|
||||
}
|
||||
|
||||
Widget _saveButton() {
|
||||
return isLoading
|
||||
? const Center(child: Loader())
|
||||
: InkWell(
|
||||
onTap: () async {
|
||||
final hasError = _checkFields();
|
||||
if (hasError) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
await 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,
|
||||
),
|
||||
);
|
||||
await widget.settingsEntity.settingsCubit.updateProfileSettings(
|
||||
profileSettingsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||
isPublicProfile: isPublicProfile.value,
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
},
|
||||
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: const Center(
|
||||
child: Text(
|
||||
'Сохранить',
|
||||
style: TextStyle(color: Colors.white, height: 1, fontWeight: FontWeight.w600, fontSize: 18),
|
||||
),
|
||||
),
|
||||
);
|
||||
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: const Center(
|
||||
child: Text(
|
||||
'Сохранить',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user