Files
eatvio_app/lib/features/settings/presentation/pages/general_info_screen.dart
2024-09-30 12:54:55 +03:00

177 lines
5.4 KiB
Dart

import 'package:eatvio_app/core/utils/date_time_utils.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:eatvio_app/theme/theme_helper.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;
const GeneralInfoScreen({
super.key,
required this.profileDetailsModel,
});
@override
State<GeneralInfoScreen> createState() => _GeneralInfoScreenState();
}
class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
final firstNameController = TextEditingController();
final lastNameController = TextEditingController();
late DateTime selectedDate;
@override
void initState() {
super.initState();
selectedDate = DateTime.now();
firstNameController.text = widget.profileDetailsModel.firstName;
lastNameController.text = widget.profileDetailsModel.lastName;
selectedDate = DateTime.parse(widget.profileDetailsModel.birthdate);
}
@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),
CustomTextFormField(
initialValue: selectedDate.format('dd MMMM yyyy', 'ru'),
),
SizedBox(height: 16),
Text('Пол'),
SizedBox(height: 4),
CustomTextFormField(
initialValue: 'Мужской',
onChanged: (newValue) {},
),
SizedBox(height: 16),
Text('Страна'),
SizedBox(height: 4),
CustomTextFormField(
initialValue: 'Россия',
onChanged: (newValue) {},
),
SizedBox(height: 16),
Text('Город'),
SizedBox(height: 4),
CustomTextFormField(
initialValue: 'Москва',
onChanged: (newValue) {},
),
SizedBox(height: 16),
Text('Предпочтительный язык общения'),
SizedBox(height: 4),
CustomTextFormField(
initialValue: 'Русский',
onChanged: (newValue) {},
),
SizedBox(height: 16),
Text('Показывать анкету'),
SizedBox(height: 4),
CustomTextFormField(
initialValue: 'Всем',
onChanged: (newValue) {},
),
],
),
),
);
}
onTapCalendar(BuildContext context) {
return () {
_showDialog(
CupertinoDatePicker(
initialDateTime: selectedDate,
maximumDate: DateTime.now(),
minimumDate: DateTime(1900),
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (DateTime newDateTime) {
setState(() {
selectedDate = newDateTime;
// final registrationCubit = context.read<RegistrationCubit>();
// registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(birthdate: selectedDate.toString()));
});
},
),
);
};
}
void _showDialog(Widget child) {
showCupertinoModalPopup<void>(
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: () => 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,
),
),
),
),
);
}
}