dialog_medication.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. const VDialogMedication({
  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. }) : super(key: key);
  27. Future<MedicationModel?> show<MedicationModel>() =>
  28. VAlertDialog.showDialog<MedicationModel>(this);
  29. @override
  30. _VDialogMedicationState createState() => _VDialogMedicationState();
  31. }
  32. class _VDialogMedicationState extends State<VDialogMedication> {
  33. MedicationModel medicationModel = MedicationModel();
  34. @override
  35. void initState() {
  36. super.initState();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return VAlertDialog(
  41. title: "主要用药情况填写",
  42. width: 600,
  43. content: Container(
  44. height: 280,
  45. padding: const EdgeInsets.symmetric(horizontal: 24),
  46. alignment: Alignment.center,
  47. child: VListFormCellGroup(
  48. children: [
  49. _buildFormCell(
  50. label: '药物名称',
  51. content: medicationModel.name,
  52. onTap: () async {
  53. final result = await _showInputDialog(
  54. title: '药物名称',
  55. initialValue: medicationModel.name ?? '',
  56. );
  57. setState(() {
  58. medicationModel.name = result;
  59. });
  60. },
  61. ),
  62. _buildFormCell(
  63. label: '频率:每日(月)',
  64. content: medicationModel.monthOrDay,
  65. onTap: () async {
  66. String? result = await VDialogSelect<String, String>(
  67. source: [
  68. "每月",
  69. "每日",
  70. ],
  71. labelGetter: (data) => data,
  72. valueGetter: (data) => data,
  73. ).show();
  74. setState(() {
  75. medicationModel.monthOrDay = result;
  76. });
  77. },
  78. ),
  79. _buildFormCell(
  80. label: '用法(次)',
  81. content: medicationModel.usage,
  82. onTap: () async {
  83. final result = await _showNumberDialog(
  84. title: '用法(次)',
  85. initialValue: medicationModel.usage ?? '',
  86. );
  87. setState(() {
  88. medicationModel.usage = result;
  89. });
  90. },
  91. ),
  92. _buildFormCell(
  93. label: '每次剂量(mg)',
  94. content: medicationModel.dosages,
  95. onTap: () async {
  96. final result = await _showNumberDialog(
  97. title: '每次剂量(mg)',
  98. initialValue: medicationModel.dosages ?? '',
  99. );
  100. setState(() {
  101. medicationModel.dosages = result;
  102. });
  103. },
  104. ),
  105. ],
  106. ),
  107. ),
  108. onConfirm: () {
  109. Get.back(result: medicationModel);
  110. },
  111. );
  112. }
  113. Future<String?> _showInputDialog({
  114. required String title,
  115. required String initialValue,
  116. }) async {
  117. final result = await VDialogInput(
  118. title: title,
  119. initialValue: initialValue,
  120. ).show();
  121. return result;
  122. }
  123. Future<String?> _showNumberDialog({
  124. required String title,
  125. required String initialValue,
  126. }) async {
  127. final result = await VDialogNumber(
  128. title: title,
  129. initialValue: initialValue,
  130. ).show();
  131. return result;
  132. }
  133. Widget _buildFormCell({
  134. required String label,
  135. String? content,
  136. required VoidCallback onTap,
  137. }) {
  138. return VListFormCell(
  139. label: label,
  140. content: content ?? '',
  141. onTap: onTap,
  142. );
  143. }
  144. }