dialog_gxy_medication.dart 4.4 KB

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