Files
eatvio_app/lib/features/settings/presentation/pages/pressure_screen.dart

151 lines
5.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<PressureScreen> createState() => _PressureScreenState();
}
class _PressureScreenState extends State<PressureScreen> {
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<SelectionPopupModel> selectionPopupList = [
const SelectionPopupModel(id: 0, title: 'Нет', value: false),
const SelectionPopupModel(id: 1, title: 'Да', value: true),
];
@override
Widget build(BuildContext context) {
final s = S.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Давление'),
),
bottomSheet: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.only(bottom: 56), // высота bottomNavigationBar
child: _saveButton(),
),
),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.all(16) + const EdgeInsets.only(bottom: 120), // 52 (кнопка) + 56 (навигация) + 12 (отступ)
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(s.up_pressure),
const SizedBox(height: 4),
CustomTextFormField(
controller: bloodPressureUpController,
inputFormatters: [digitsOnly],
hintText: "90",
onChanged: (newValue) {},
),
const SizedBox(height: 16),
Text(s.down_pressure),
const SizedBox(height: 4),
CustomTextFormField(
controller: bloodPressureDownController,
inputFormatters: [digitsOnly],
hintText: '90',
onChanged: (newValue) {},
),
const SizedBox(height: 16),
Text(s.do_you_have_hypotension_tendency),
const SizedBox(height: 4),
CustomDropDown(
items: selectionPopupList,
value: hypo,
hintText: "Не выбрано",
onChanged: (newPopup) {
setState(() {
hypo = newPopup;
});
},
),
const SizedBox(height: 16),
Text(s.do_you_have_hypertension_tendency),
const SizedBox(height: 4),
CustomDropDown(
items: selectionPopupList,
value: hyper,
hintText: "Не выбрано",
onChanged: (newPopup) {
setState(() {
hyper = newPopup;
});
},
),
],
),
),
);
}
InkWell _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: const Center(
child: Text(
'Сохранить',
style: TextStyle(
color: Colors.white,
height: 1,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
),
),
);
}
}