exam_toxic_substance.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import 'package:flutter/material.dart';
  2. import 'package:vitalapp/components/dialog_input.dart';
  3. import 'package:vitalapp/pages/check/models/form.dart';
  4. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
  5. class ExamToxicSubstance extends StatelessWidget {
  6. const ExamToxicSubstance({
  7. Key? key,
  8. required this.currentFormObject,
  9. required this.options,
  10. required this.selectRadioChange,
  11. this.currentSelectedToxicSubstance,
  12. required this.selectValueChange,
  13. required this.currentValue,
  14. }) : super(key: key);
  15. final FormObject currentFormObject;
  16. final List<Option> options;
  17. final Function selectRadioChange;
  18. final Map? currentSelectedToxicSubstance;
  19. final Function selectValueChange;
  20. final String currentValue;
  21. @override
  22. Widget build(BuildContext context) {
  23. return ExamCard(
  24. title: currentFormObject.label ?? '',
  25. content: Column(
  26. children: [
  27. _buildTextField(),
  28. _buildProtectionMeasuresText(),
  29. _buildOptionsRow(),
  30. ],
  31. ),
  32. );
  33. }
  34. Widget _buildTextField() {
  35. return Container(
  36. padding: const EdgeInsets.all(32).copyWith(top: 0),
  37. child: TextField(
  38. readOnly: true,
  39. controller: TextEditingController(text: currentValue),
  40. style: const TextStyle(fontSize: 30),
  41. onTap: () async {
  42. final result = await _showInputDialog(
  43. title: currentFormObject.label ?? '',
  44. initialValue: currentValue,
  45. );
  46. selectValueChange.call(result);
  47. },
  48. ),
  49. );
  50. }
  51. Widget _buildProtectionMeasuresText() {
  52. return Container(
  53. alignment: Alignment.centerLeft,
  54. padding: const EdgeInsets.only(left: 32, bottom: 12),
  55. child: const Text(
  56. '防护措施:',
  57. style: TextStyle(fontSize: 25),
  58. ),
  59. );
  60. }
  61. Widget _buildOptionsRow() {
  62. final selectedValue = currentSelectedToxicSubstance?['value']?['value'];
  63. return Container(
  64. padding: const EdgeInsets.symmetric(horizontal: 16),
  65. width: double.infinity,
  66. child: Row(
  67. children: [
  68. Wrap(
  69. children: options
  70. .map(
  71. (e) => Container(
  72. padding: const EdgeInsets.all(8),
  73. child: InkWell(
  74. onTap: () {
  75. final toxicSubstance = ToxicSubstance(
  76. value: e.toJson(),
  77. );
  78. selectRadioChange(toxicSubstance.toJson());
  79. },
  80. borderRadius: BorderRadius.circular(50),
  81. child: Ink(
  82. decoration: BoxDecoration(
  83. border: Border.all(
  84. color: selectedValue == e.value
  85. ? Colors.blue
  86. : Colors.black26,
  87. ),
  88. borderRadius: const BorderRadius.all(
  89. Radius.circular(50),
  90. ),
  91. color: selectedValue == e.value
  92. ? Colors.blue
  93. : Colors.transparent,
  94. ),
  95. child: Container(
  96. padding: const EdgeInsets.all(15),
  97. alignment: Alignment.center,
  98. width: 250,
  99. child: FittedBox(
  100. child: Text(
  101. e.label ?? '',
  102. style: TextStyle(
  103. fontSize: 20,
  104. color: selectedValue == e.value
  105. ? Colors.white
  106. : Colors.black54,
  107. ),
  108. ),
  109. ),
  110. ),
  111. ),
  112. ),
  113. ),
  114. )
  115. .toList(),
  116. ),
  117. if (selectedValue == '2') _buildProtectionMeasureTextField(),
  118. ],
  119. ),
  120. );
  121. }
  122. Widget _buildProtectionMeasureTextField() {
  123. return Container(
  124. child: Row(
  125. children: [
  126. const SizedBox(width: 16),
  127. SizedBox(
  128. width: 200,
  129. child: TextField(
  130. readOnly: true,
  131. controller: TextEditingController(
  132. text: currentSelectedToxicSubstance?['label'],
  133. ),
  134. style: const TextStyle(fontSize: 30),
  135. onTap: () async {
  136. final result = await _showInputDialog(
  137. title: '防护措施',
  138. initialValue: currentSelectedToxicSubstance?['label'] ?? '',
  139. );
  140. final toxicSubstance = ToxicSubstance(
  141. value: Option(label: '有', value: '2').toJson(),
  142. label: result,
  143. );
  144. selectRadioChange(toxicSubstance.toJson());
  145. },
  146. ),
  147. )
  148. ],
  149. ),
  150. );
  151. }
  152. Future<String?> _showInputDialog({
  153. required String title,
  154. required String initialValue,
  155. }) async {
  156. return await VDialogInput(
  157. title: title,
  158. initialValue: initialValue,
  159. ).show();
  160. }
  161. }