rvsp.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import 'package:fis_i18n/i18n.dart';
  2. import 'package:fis_measure/define.dart';
  3. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  4. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  5. import 'package:fis_measure/process/primitives/rvsp.dart';
  6. import 'package:fis_measure/utils/prompt_box.dart';
  7. import 'package:fis_measure/view/measure/custom_item_buttons/widgets.dart';
  8. import 'package:fis_ui/index.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:get/get.dart';
  11. import 'normal_child.dart';
  12. class RapItemButton extends FStatefulWidget {
  13. const RapItemButton({super.key});
  14. @override
  15. FState<FStatefulWidget> createState() => _RapItemButtonState();
  16. }
  17. class _RapItemButtonState extends FState<RapItemButton> {
  18. static const _options = <double>[double.nan, 5, 10, 15];
  19. late final RxInt _activeIndex;
  20. double _customRapValue = 0;
  21. @override
  22. void initState() {
  23. _initState();
  24. super.initState();
  25. }
  26. @override
  27. FWidget build(BuildContext context) {
  28. return NormalChildButton(
  29. businessParent: const FPlaceHolderInteractiveContainer(),
  30. activeIndex: -1,
  31. index: 0,
  32. itemMeta: ItemMeta(
  33. "RAP",
  34. measureType: '',
  35. description: 'RAP',
  36. outputs: [],
  37. ),
  38. onClick: () {
  39. Get.dialog(_buildDialog());
  40. },
  41. );
  42. }
  43. void _initState() {
  44. final activeMeasureItem = Get.find<IApplication>().activeMeasureItem;
  45. if (activeMeasureItem == null) {
  46. _activeIndex = RxInt(0);
  47. return;
  48. }
  49. final rap = (activeMeasureItem as Rvsp).rap.value;
  50. if (rap == null) {
  51. _activeIndex = RxInt(0);
  52. return;
  53. }
  54. final index = _options.indexWhere((e) => e == rap);
  55. if (index > 0) {
  56. _activeIndex = RxInt(index);
  57. } else {
  58. _customRapValue = rap;
  59. _activeIndex = RxInt(0);
  60. }
  61. }
  62. FWidget _buildDialog() {
  63. return FObx(() {
  64. final children = <Widget>[];
  65. for (var i = 0; i < _options.length; i++) {
  66. if (i == 0) {
  67. children.add(_buildInputButton());
  68. } else {
  69. children.add(const CustomChildOptionDivider());
  70. children.add(_buildValueButton(i));
  71. }
  72. }
  73. return FSimpleDialog(
  74. title: const FText("RAP", style: TextStyle(color: Colors.white)),
  75. okString: i18nBook.common.confirm.t,
  76. cancelString: i18nBook.common.cancel.t,
  77. isDefault: true,
  78. children: children,
  79. onOk: () {
  80. _onValueConfrim();
  81. Get.back();
  82. },
  83. onCancel: () {
  84. Get.back();
  85. },
  86. onClose: () {
  87. Get.back();
  88. },
  89. );
  90. });
  91. }
  92. void _onValueConfrim() {
  93. final activeMeasureItem = Get.find<IApplication>().activeMeasureItem;
  94. if (activeMeasureItem == null) {
  95. return;
  96. }
  97. double rap;
  98. if (_activeIndex.value == 0) {
  99. rap = _customRapValue;
  100. } else {
  101. rap = _options[_activeIndex.value];
  102. }
  103. (activeMeasureItem as Rvsp).updateRap(rap);
  104. }
  105. Widget _buildValueButton(int index) {
  106. final isActive = _activeIndex.value == index;
  107. final value = _options[index];
  108. return CustomChildTextOptionWidget(
  109. isActive: isActive,
  110. text: "$value mmHg",
  111. onClick: () {
  112. _activeIndex.value = index;
  113. },
  114. );
  115. }
  116. Widget _buildInputButton() {
  117. const index = 0;
  118. final isActive = _activeIndex.value == index;
  119. return CustomChildInputOptionWidget(
  120. isActive: isActive,
  121. value: _customRapValue.toString(),
  122. suffixWidget: const Text(" mmHg"),
  123. onClick: () {
  124. _activeIndex.value = index;
  125. },
  126. onInputChanged: (String value) {
  127. final doubleValue = double.tryParse(value);
  128. if (doubleValue == null) {
  129. PromptBox.toast("请输入正确的RAP数值");
  130. } else {
  131. if (doubleValue < 0) {
  132. PromptBox.toast("RAP必须大于0");
  133. } else {
  134. _customRapValue = doubleValue;
  135. }
  136. }
  137. },
  138. );
  139. }
  140. }