dialog_medication.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/components/cell.dart';
  4. import 'package:vitalapp/components/dialog_input.dart';
  5. import 'package:vitalapp/components/dialog_number.dart';
  6. import 'package:vitalapp/components/dialog_select.dart';
  7. import 'package:vitalapp/pages/check/models/form.dart';
  8. import 'alert_dialog.dart';
  9. class VDialogMedication extends StatefulWidget {
  10. final String? title;
  11. final String? description;
  12. final String? placeholder;
  13. final int? maxLines;
  14. final double? inputHeight;
  15. final bool Function(String)? onConfirmVerification;
  16. final bool showCancel;
  17. final MedicationModel? medicationModel;
  18. const VDialogMedication({
  19. Key? key,
  20. this.title,
  21. this.description,
  22. this.placeholder,
  23. this.maxLines = 1,
  24. this.inputHeight = 56,
  25. this.onConfirmVerification,
  26. this.showCancel = false,
  27. this.medicationModel,
  28. }) : super(key: key);
  29. Future<MedicationModel?> show<MedicationModel>() =>
  30. VAlertDialog.showDialog<MedicationModel>(this);
  31. @override
  32. _VDialogMedicationState createState() => _VDialogMedicationState();
  33. }
  34. class _VDialogMedicationState extends State<VDialogMedication> {
  35. MedicationModel medicationModel = MedicationModel();
  36. @override
  37. void initState() {
  38. super.initState();
  39. if (widget.medicationModel != null) {
  40. medicationModel = widget.medicationModel!;
  41. }
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. return VAlertDialog(
  46. title: "主要用药情况填写",
  47. width: 600,
  48. content: Container(
  49. height: 280,
  50. padding: const EdgeInsets.symmetric(horizontal: 24),
  51. alignment: Alignment.center,
  52. child: VListFormCellGroup(
  53. children: [
  54. _buildFormCell(
  55. label: '药物名称',
  56. content: medicationModel.name,
  57. onTap: () async {
  58. final result = await _showInputDialog(
  59. title: '药物名称',
  60. initialValue: medicationModel.name ?? '',
  61. );
  62. setState(() {
  63. medicationModel.name = result;
  64. });
  65. },
  66. ),
  67. _buildFormCell(
  68. label: '频率:每日(月)',
  69. content: medicationModel.monthOrDay,
  70. onTap: () async {
  71. String? result = await VDialogSelect<String, String>(
  72. source: [
  73. "每月",
  74. "每日",
  75. ],
  76. labelGetter: (data) => data,
  77. valueGetter: (data) => data,
  78. ).show();
  79. setState(() {
  80. medicationModel.monthOrDay = result;
  81. });
  82. },
  83. ),
  84. _buildFormCell(
  85. label: '用法(次)',
  86. content: medicationModel.usage,
  87. onTap: () async {
  88. final result = await _showNumberDialog(
  89. title: '用法(次)',
  90. initialValue: medicationModel.usage ?? '',
  91. );
  92. setState(() {
  93. medicationModel.usage = result;
  94. });
  95. },
  96. ),
  97. _buildFormCell(
  98. label: '每次剂量(mg)',
  99. content: medicationModel.dosages,
  100. onTap: () async {
  101. final result = await _showNumberDialog(
  102. title: '每次剂量(mg)',
  103. initialValue: medicationModel.dosages ?? '',
  104. );
  105. setState(() {
  106. medicationModel.dosages = result;
  107. });
  108. },
  109. ),
  110. ],
  111. ),
  112. ),
  113. onConfirm: () {
  114. Get.back(result: medicationModel);
  115. },
  116. );
  117. }
  118. Future<String?> _showInputDialog({
  119. required String title,
  120. required String initialValue,
  121. }) async {
  122. final result = await VDialogInput(
  123. title: title,
  124. initialValue: initialValue,
  125. ).show();
  126. return result;
  127. }
  128. Future<String?> _showNumberDialog({
  129. required String title,
  130. required String initialValue,
  131. }) async {
  132. final result = await VDialogNumber(
  133. title: title,
  134. initialValue: initialValue,
  135. ).show();
  136. return result;
  137. }
  138. Widget _buildFormCell({
  139. required String label,
  140. String? content,
  141. required VoidCallback onTap,
  142. }) {
  143. return VListFormCell(
  144. label: label,
  145. content: content ?? '',
  146. onTap: onTap,
  147. );
  148. }
  149. }