123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import 'package:fis_i18n/i18n.dart';
- import 'package:fis_measure/define.dart';
- import 'package:fis_measure/interfaces/process/items/item_metas.dart';
- import 'package:fis_measure/interfaces/process/workspace/application.dart';
- import 'package:fis_measure/process/primitives/rvsp.dart';
- import 'package:fis_measure/utils/prompt_box.dart';
- import 'package:fis_measure/view/measure/custom_item_buttons/widgets.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'normal_child.dart';
- class RapItemButton extends FStatefulWidget {
- const RapItemButton({super.key});
- @override
- FState<FStatefulWidget> createState() => _RapItemButtonState();
- }
- class _RapItemButtonState extends FState<RapItemButton> {
- static const _options = <double>[double.nan, 5, 10, 15];
- late final RxInt _activeIndex;
- double _customRapValue = 0;
- @override
- void initState() {
- _initState();
- super.initState();
- }
- @override
- FWidget build(BuildContext context) {
- return NormalChildButton(
- businessParent: const FPlaceHolderInteractiveContainer(),
- activeIndex: -1,
- index: 0,
- itemMeta: ItemMeta(
- "RAP",
- measureType: '',
- description: 'RAP',
- outputs: [],
- ),
- onClick: () {
- Get.dialog(_buildDialog());
- },
- );
- }
- void _initState() {
- final activeMeasureItem = Get.find<IApplication>().activeMeasureItem;
- if (activeMeasureItem == null) {
- _activeIndex = RxInt(0);
- return;
- }
- final rap = (activeMeasureItem as Rvsp).rap.value;
- if (rap == null) {
- _activeIndex = RxInt(0);
- return;
- }
- final index = _options.indexWhere((e) => e == rap);
- if (index > 0) {
- _activeIndex = RxInt(index);
- } else {
- _customRapValue = rap;
- _activeIndex = RxInt(0);
- }
- }
- FWidget _buildDialog() {
- return FObx(() {
- final children = <Widget>[];
- for (var i = 0; i < _options.length; i++) {
- if (i == 0) {
- children.add(_buildInputButton());
- } else {
- children.add(const CustomChildOptionDivider());
- children.add(_buildValueButton(i));
- }
- }
- return FSimpleDialog(
- title: const FText("RAP", style: TextStyle(color: Colors.white)),
- okString: i18nBook.common.confirm.t,
- cancelString: i18nBook.common.cancel.t,
- isDefault: true,
- children: children,
- onOk: () {
- _onValueConfrim();
- Get.back();
- },
- onCancel: () {
- Get.back();
- },
- onClose: () {
- Get.back();
- },
- );
- });
- }
- void _onValueConfrim() {
- final activeMeasureItem = Get.find<IApplication>().activeMeasureItem;
- if (activeMeasureItem == null) {
- return;
- }
- double rap;
- if (_activeIndex.value == 0) {
- rap = _customRapValue;
- } else {
- rap = _options[_activeIndex.value];
- }
- (activeMeasureItem as Rvsp).updateRap(rap);
- }
- Widget _buildValueButton(int index) {
- final isActive = _activeIndex.value == index;
- final value = _options[index];
- return CustomChildTextOptionWidget(
- isActive: isActive,
- text: "$value mmHg",
- onClick: () {
- _activeIndex.value = index;
- },
- );
- }
- Widget _buildInputButton() {
- const index = 0;
- final isActive = _activeIndex.value == index;
- return CustomChildInputOptionWidget(
- isActive: isActive,
- value: _customRapValue.toString(),
- suffixWidget: const Text(" mmHg"),
- onClick: () {
- _activeIndex.value = index;
- },
- onInputChanged: (String value) {
- final doubleValue = double.tryParse(value);
- if (doubleValue == null) {
- PromptBox.toast("请输入正确的RAP数值");
- } else {
- if (doubleValue < 0) {
- PromptBox.toast("RAP必须大于0");
- } else {
- _customRapValue = doubleValue;
- }
- }
- },
- );
- }
- }
|