import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.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/material.dart'; import 'package:flutter/services.dart'; import 'package:go_router/go_router.dart'; class PressureScreen extends StatefulWidget { final SettingsEntity settingsEntity; const PressureScreen({ super.key, required this.settingsEntity, }); @override State createState() => _PressureScreenState(); } class _PressureScreenState extends State { final digitsOnly = FilteringTextInputFormatter.digitsOnly; final bloodPressureUpController = TextEditingController(); final bloodPressureDownController = TextEditingController(); late SelectionPopupModel hypo; late SelectionPopupModel hyper; @override void initState() { super.initState(); bloodPressureUpController.text = widget.settingsEntity.profileDetailsModel.bloodPressureUp.toString(); bloodPressureDownController.text = widget.settingsEntity.profileDetailsModel.bloodPressureDown.toString(); hypo = widget.settingsEntity.profileDetailsModel.hasHypo ? selectionPopupList[1] : selectionPopupList[0]; hyper = widget.settingsEntity.profileDetailsModel.hasHyper ? selectionPopupList[1] : selectionPopupList[0]; } final List selectionPopupList = [ SelectionPopupModel(id: 0, title: 'Нет', value: false), SelectionPopupModel(id: 1, title: 'Да', value: true), ]; @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.up_pressure), SizedBox(height: 4), CustomTextFormField( controller: bloodPressureUpController, inputFormatters: [digitsOnly], hintText: "90", onChanged: (newValue) {}, ), SizedBox(height: 16), Text(s.down_pressure), SizedBox(height: 4), CustomTextFormField( controller: bloodPressureDownController, inputFormatters: [digitsOnly], hintText: '90', onChanged: (newValue) {}, ), SizedBox(height: 16), Text(s.do_you_have_hypotension_tendency), SizedBox(height: 4), CustomDropDown( items: selectionPopupList, value: hypo, hintText: "Не выбрано", onChanged: (newPopup) { setState(() { hypo = newPopup; }); }, ), SizedBox(height: 16), Text(s.do_you_have_hypertension_tendency), SizedBox(height: 4), CustomDropDown( items: selectionPopupList, value: hyper, hintText: "Не выбрано", onChanged: (newPopup) { setState(() { hyper = newPopup; }); }, ), ], ), ), ); } _saveButton() { return InkWell( onTap: () { widget.settingsEntity.settingsCubit.updateProfileDetails( profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith( bloodPressureUp: int.parse(bloodPressureUpController.text), bloodPressureDown: int.parse(bloodPressureDownController.text), hasHyper: hyper.value, hasHypo: hypo.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, ), ), ), ), ); } }