exam_blood.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:vitalapp/pages/check/models/form.dart';
  4. import 'package:vitalapp/pages/form/form_info.dart';
  5. import 'package:vnote_device_plugin/models/exams/nibp.dart';
  6. import 'exam_card.dart';
  7. import 'follow_blood_pressure.dart';
  8. class ExamBlood extends StatefulWidget {
  9. final FormObject currentFormObject;
  10. ExamBlood({required this.currentFormObject});
  11. @override
  12. State<StatefulWidget> createState() {
  13. return ExamBloodState();
  14. }
  15. }
  16. class ExamBloodState extends State<ExamBlood> {
  17. NibpExamValue? _nibpExamValue;
  18. FormObject get currentFormObject => widget.currentFormObject;
  19. @override
  20. void initState() {
  21. if (FormInfo.instance.formValue.containsKey(widget.currentFormObject.key)) {
  22. var value = FormInfo.instance.formValue[widget.currentFormObject.key];
  23. _nibpExamValue = NibpExamValue(
  24. diastolicPressure: int.parse(value[0]),
  25. pulse: 0,
  26. systolicPressure: int.parse(value[1]),
  27. );
  28. }
  29. super.initState();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return ExamCard(
  34. content: Column(
  35. mainAxisAlignment: MainAxisAlignment.start,
  36. children: [
  37. InkWell(
  38. child: SideBar(
  39. title: '血压',
  40. value: _buildResult(_nibpExamValue),
  41. unit: 'mmHg',
  42. ),
  43. onTap: _onTap,
  44. ),
  45. ],
  46. ),
  47. );
  48. }
  49. Future<void> _onTap() async {
  50. String? result = await VDialogBloodPressure(
  51. title: '血压',
  52. initialValue: [
  53. _nibpExamValue?.systolicPressure.toString() ?? '',
  54. _nibpExamValue?.diastolicPressure.toString() ?? '',
  55. ],
  56. ).show();
  57. if (result != null) {
  58. _nibpExamValue = NibpExamValue(
  59. diastolicPressure: int.parse(jsonDecode(result).last),
  60. systolicPressure: int.parse(jsonDecode(result).first),
  61. pulse: 0,
  62. );
  63. FormInfo.instance.formValue[currentFormObject.key!] = [
  64. _nibpExamValue!.diastolicPressure.toString(),
  65. _nibpExamValue!.systolicPressure.toString(),
  66. ];
  67. }
  68. setState(() {});
  69. }
  70. Widget _buildResult(NibpExamValue? nibpExamValue) {
  71. const textStyle = TextStyle(fontSize: 26, color: Colors.black);
  72. var systolicPressure = nibpExamValue?.systolicPressure.toString() ?? '';
  73. var diastolicPressure = nibpExamValue?.diastolicPressure.toString() ?? '';
  74. var span = " / ";
  75. if (systolicPressure.isEmpty && diastolicPressure.isEmpty) {
  76. span += " ";
  77. }
  78. return Row(
  79. children: [
  80. Align(
  81. alignment: Alignment.centerLeft,
  82. child: Text(
  83. systolicPressure,
  84. style: textStyle,
  85. ),
  86. ),
  87. Text(
  88. span,
  89. style: textStyle,
  90. ),
  91. Align(
  92. alignment: Alignment.centerRight,
  93. child: Text(
  94. diastolicPressure,
  95. style: textStyle,
  96. ),
  97. ),
  98. Text(
  99. " mmHg",
  100. style: textStyle,
  101. ),
  102. ],
  103. );
  104. }
  105. }