import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart'; import 'package:eatvio_app/core/utils/image_constant.dart'; import 'package:eatvio_app/core/widgets/custom_drop_down.dart'; import 'package:eatvio_app/features/registration/models/user_registration_model.dart'; import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:eatvio_app/core/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class BloodPressureScreen extends StatefulWidget { final UserRegistrationSheet sheet; const BloodPressureScreen({super.key, required this.sheet}); @override State createState() => _BloodPressureScreenState(); } class _BloodPressureScreenState extends State { final List selectionPopupList = [ SelectionPopupModel( id: 1, title: "Да", ), SelectionPopupModel( id: 0, title: "Нет", ), ]; late SelectionPopupModel selectedPopupHypo; late SelectionPopupModel selectedPopupHyper; final digitsOnly = FilteringTextInputFormatter.digitsOnly; final upPressureController = TextEditingController(); final downPressureController = TextEditingController(); final upFocusNode = FocusNode(); @override void initState() { super.initState(); selectedPopupHypo = selectionPopupList[1]; selectedPopupHyper = selectionPopupList[1]; if (widget.sheet.bloodPressureUp != 0) upPressureController.text = widget.sheet.bloodPressureUp.toString(); if (widget.sheet.bloodPressureDown != 0) downPressureController.text = widget.sheet.bloodPressureDown.toString(); widget.sheet.hasHyper == 1 ? selectedPopupHyper = selectionPopupList[0] : selectedPopupHyper = selectionPopupList[1]; widget.sheet.hasHypo == 1 ? selectedPopupHypo = selectionPopupList[0] : selectedPopupHypo = selectionPopupList[1]; upFocusNode.requestFocus(); } @override Widget build(BuildContext context) { final s = S.of(context); return SingleChildScrollView( padding: EdgeInsets.only(bottom: 80, left: 16, right: 16, top: 16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(s.up_pressure + ' (не обязательно)'), SizedBox(height: 4), CustomTextFormField( inputFormatters: [digitsOnly], controller: upPressureController, autofocus: true, focusNode: upFocusNode, hintText: "90", onChanged: (newValue) { final registrationCubit = context.read(); registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(bloodPressureUp: int.parse(newValue))); }, ), SizedBox(height: 16), Text(s.down_pressure + ' (не обязательно)'), SizedBox(height: 4), CustomTextFormField( inputFormatters: [digitsOnly], controller: downPressureController, hintText: '90', onChanged: (newValue) { final registrationCubit = context.read(); registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(bloodPressureDown: int.parse(newValue))); }, ), SizedBox(height: 16), Text(s.do_you_have_hypotension_tendency + ' (не обязательно)'), SizedBox(height: 4), CustomDropDown( icon: Container( margin: EdgeInsets.all(16), decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), ), child: Image.asset( ImageConstant.imgFavorite, height: 16, width: 16, ), ), hintText: "Не выбрано", items: selectionPopupList, value: selectedPopupHypo, onChanged: (newPopup) { setState(() { selectedPopupHypo = newPopup; final registrationCubit = context.read(); registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(hasHypo: selectedPopupHypo.id!)); }); }, ), SizedBox(height: 16), Text(s.do_you_have_hypertension_tendency + ' (не обязательно)'), SizedBox(height: 4), CustomDropDown( icon: Container( margin: EdgeInsets.all(16), decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), ), child: Image.asset( ImageConstant.imgFavorite, height: 16, width: 16, ), ), hintText: "Не выбрано", items: selectionPopupList, value: selectedPopupHyper, onChanged: (newPopup) { setState(() { selectedPopupHyper = newPopup; final registrationCubit = context.read(); registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(hasHyper: selectedPopupHyper.id!)); }); }, ), ], ), ); } }