123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/pages/check/models/form.dart';
- import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
- import 'package:vitalapp/pages/medical/models/item.dart';
- import 'package:vnote_device_plugin/models/exams/nibp.dart';
- /// 小弹窗输入
- class VDialogBloodPressure extends StatelessWidget {
- /// 标题
- final String? title;
- /// 描述
- final String? description;
- /// 输入占位符
- final String? placeholder;
- /// 初始值
- final List<String>? initialValue;
- const VDialogBloodPressure({
- super.key,
- this.title,
- this.description,
- this.placeholder,
- this.initialValue,
- });
- Future<String?> show<String>() => VAlertDialog.showDialog<String>(this);
- @override
- Widget build(BuildContext context) {
- final controller1 = TextEditingController(text: initialValue?.first);
- final controller2 = TextEditingController(text: initialValue?.last);
- return VAlertDialog(
- title: title,
- width: 440,
- contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
- content: _buildContent(context, controller1, controller2),
- showCancel: true,
- onConfirm: () {
- Get.back(result: json.encode([controller1.text, controller2.text]));
- },
- );
- }
- Widget _buildContent(
- BuildContext context,
- TextEditingController controller1,
- TextEditingController controller2,
- ) {
- final children = <Widget>[];
- if (description != null) {
- children.add(
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 4),
- child: Text(
- description!,
- style: const TextStyle(color: Colors.black87, fontSize: 18),
- ),
- ),
- );
- children.add(const SizedBox(height: 8));
- } else {
- children.add(const SizedBox(height: 12));
- }
- children.add(_buildInputWidget(context, controller1, controller2));
- return SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: children,
- ),
- );
- }
- Widget _buildInputWidget(
- BuildContext context,
- TextEditingController controller1,
- TextEditingController controller2,
- ) {
- const fontSize = 20.0;
- return Row(
- children: [
- _buildItem(context, controller1, '高压'),
- const Text(
- '/',
- style: TextStyle(fontSize: fontSize),
- ),
- _buildItem(context, controller2, '低压'),
- ],
- );
- }
- Widget _buildItem(
- BuildContext context,
- TextEditingController controller,
- String hintText,
- ) {
- const fontSize = 20.0;
- const height = 56.0;
- return Expanded(
- child: SizedBox(
- height: height,
- child: TextField(
- controller: controller,
- readOnly: false,
- autofocus: true,
- keyboardType: const TextInputType.numberWithOptions(
- decimal: true), // 允许输入数字和小数点
- inputFormatters: [
- FilteringTextInputFormatter.allow(
- RegExp(r'^\d+\.?\d{0,2}'),
- ), // 只允许输入数字和小数点,俩位小数
- ],
- style: const TextStyle(fontSize: fontSize),
- decoration: InputDecoration(
- border: const UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(),
- ),
- enabledBorder: const UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(
- color: Colors.black54,
- ),
- ),
- focusedBorder: UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(
- color: Theme.of(context).primaryColor.withOpacity(.4),
- ),
- ),
- filled: true,
- fillColor: Colors.white,
- contentPadding: const EdgeInsets.symmetric(
- vertical: (height - fontSize * 1.2) / 2,
- horizontal: 8,
- ),
- hintStyle: const TextStyle(fontSize: fontSize),
- labelStyle: const TextStyle(fontSize: fontSize),
- hintText: hintText,
- isCollapsed: true,
- ),
- onSubmitted: (value) {
- print(value);
- Get.back(result: value);
- },
- ),
- ),
- );
- }
- }
- /// TODO 优化血压组件,存储需要重新设计
- // ignore: must_be_immutable
- class FollowBloodPressure extends StatefulWidget {
- FollowBloodPressure({
- super.key,
- required this.currentValue,
- required this.bloodPressure,
- required this.currentFormObject,
- });
- Map currentValue;
- Function(Map) bloodPressure;
- final FormObject currentFormObject;
- @override
- State<FollowBloodPressure> createState() => _FollowBloodPressureState();
- }
- class _FollowBloodPressureState extends State<FollowBloodPressure> {
- PressureStatus pressureStatus = PressureStatus.left;
- NibpExamValue? value;
- NibpExamValue? _nibpExamValue;
- @override
- void initState() {
- if (widget.currentValue['Blood'] != null) {
- String currentValue = widget.currentValue['Blood'];
- _nibpExamValue = NibpExamValue(
- systolicPressure: int.parse(jsonDecode(currentValue).first.toString()),
- diastolicPressure: int.parse(jsonDecode(currentValue).last.toString()),
- pulse: 0,
- );
- }
- super.initState();
- }
- void didUpdateWidget(FollowBloodPressure oldWidget) {
- if (oldWidget.currentValue != widget.currentValue) {
- if (widget.currentValue['Blood'] != null) {
- String currentValue = widget.currentValue['Blood'];
- _nibpExamValue = NibpExamValue(
- systolicPressure:
- int.parse(jsonDecode(currentValue).first.toString()),
- diastolicPressure:
- int.parse(jsonDecode(currentValue).last.toString()),
- pulse: 0,
- );
- setState(() {});
- }
- }
- super.didUpdateWidget(oldWidget);
- }
- @override
- void dispose() {
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Stack(
- children: [
- ExamCard(
- content: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- InkWell(
- child: SideBar(
- title: '血压',
- value: _buildResult(
- _nibpExamValue,
- ' mmHg',
- ),
- unit: 'mmHg',
- required: widget.currentFormObject.required,
- ),
- onTap: () async {
- String? result = await VDialogBloodPressure(
- title: '血压',
- initialValue: [
- _nibpExamValue?.systolicPressure.toString() ?? '',
- _nibpExamValue?.diastolicPressure.toString() ?? '',
- ],
- ).show();
- if (result != null) {
- _nibpExamValue = NibpExamValue(
- diastolicPressure: int.parse(jsonDecode(result).last),
- systolicPressure: int.parse(jsonDecode(result).first),
- pulse: 0,
- );
- widget.bloodPressure({
- "Blood": result,
- });
- }
- setState(() {});
- },
- ),
- ],
- ),
- ),
- ],
- );
- }
- Widget _buildResult(NibpExamValue? nibpExamValue, String? unit) {
- const textStyle = TextStyle(fontSize: 26, color: Colors.black);
- return Row(
- children: [
- Column(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Align(
- alignment: Alignment.centerLeft,
- child: RichText(
- text: TextSpan(
- text: nibpExamValue?.systolicPressure.toString() ?? '',
- style: textStyle,
- children: [
- TextSpan(
- text: unit ?? '',
- style: textStyle.copyWith(fontSize: 20),
- ),
- ]),
- ),
- ),
- Align(
- alignment: Alignment.centerRight,
- child: RichText(
- text: TextSpan(
- text: nibpExamValue?.diastolicPressure.toString() ?? '',
- style: textStyle,
- children: [
- TextSpan(
- text: unit ?? '',
- style: textStyle.copyWith(fontSize: 20),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ],
- );
- }
- }
- class SideBar extends StatelessWidget {
- final String title;
- final Widget value;
- final String unit;
- final bool? required;
- const SideBar({
- required this.title,
- required this.value,
- required this.unit,
- this.required,
- });
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- // padding: const EdgeInsets.symmetric(horizontal: 30),
- child: RichText(
- text: TextSpan(
- text: "",
- children: [
- if (required ?? false)
- TextSpan(
- text: "* ",
- style: const TextStyle(color: Colors.red, fontSize: 35),
- ),
- TextSpan(
- text: title,
- style: TextStyle(
- fontSize: 26,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- fontFamilyFallback: const ["NotoSansSC"],
- ),
- ),
- ],
- ),
- ),
- ),
- Container(
- alignment: Alignment.bottomRight,
- padding: const EdgeInsets.only(
- right: 30,
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- value,
- ],
- ),
- ),
- ],
- );
- }
- }
|