dialog_table.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/components/dialog_ecg_image.dart';
  6. import 'package:vnote_device_plugin/models/exams/twelve_heart.dart';
  7. import '../pages/medical/widgets/twelve_ecg_view/widgets/conclusion_dialog.dart';
  8. import 'alert_dialog.dart';
  9. class VDialogTable extends StatelessWidget {
  10. final bool? isExistLocalData;
  11. const VDialogTable({
  12. super.key,
  13. this.title,
  14. required this.columnNames,
  15. required this.tableData,
  16. this.diagnosisTime,
  17. this.isExistLocalData = false,
  18. });
  19. final List<List<String>> tableData;
  20. final List<String> columnNames;
  21. final String? title;
  22. final String? diagnosisTime;
  23. Future<DateTime?> show<DateTime>() => VAlertDialog.showDialog<DateTime>(this);
  24. @override
  25. Widget build(BuildContext context) {
  26. return VAlertDialog(
  27. width: 800,
  28. contentPadding: const EdgeInsets.only(left: 16, right: 8),
  29. content: _buildTable(),
  30. showCancel: true,
  31. );
  32. }
  33. Widget _buildTable() {
  34. return SizedBox(
  35. height: 500,
  36. child: Column(
  37. children: [
  38. const SizedBox(
  39. height: 10,
  40. ),
  41. if (title != null)
  42. Text(
  43. title!,
  44. style: const TextStyle(
  45. fontSize: 22,
  46. ),
  47. ),
  48. const SizedBox(
  49. height: 10,
  50. ),
  51. Table(
  52. children: [
  53. TableRow(
  54. decoration: const BoxDecoration(
  55. color: Color.fromRGBO(215, 234, 255, 1),
  56. ),
  57. children: columnNames
  58. .map((columnName) => _buildHeaderCell(columnName))
  59. .toList(),
  60. ),
  61. ],
  62. ),
  63. Expanded(
  64. child: Scrollbar(
  65. thumbVisibility: true,
  66. child: SingleChildScrollView(
  67. child: Table(
  68. children: _buildRow(tableData),
  69. ),
  70. ),
  71. ),
  72. ),
  73. const SizedBox(
  74. height: 10,
  75. ),
  76. Container(
  77. alignment: Alignment.centerLeft,
  78. child: Text(
  79. "检测时间:${diagnosisTime ?? ''}",
  80. style: const TextStyle(fontSize: 18),
  81. )),
  82. const SizedBox(
  83. height: 10,
  84. ),
  85. Container(
  86. alignment: Alignment.centerLeft,
  87. child: const Text(
  88. '注:本结果仅对该检验样本负责!',
  89. style: TextStyle(fontSize: 18),
  90. ))
  91. ],
  92. ),
  93. );
  94. }
  95. List<TableRow> _buildRow(List<List<String>> tableData) {
  96. var tableRows = <TableRow>[];
  97. for (var i = 0; i < tableData.length; i++) {
  98. final rowData = tableData[i];
  99. final label = rowData[1];
  100. tableRows.add(
  101. TableRow(
  102. decoration: i % 2 == 0
  103. ? null
  104. : const BoxDecoration(
  105. color: Color.fromRGBO(233, 244, 255, 1),
  106. ),
  107. children: tableData[i].map(
  108. (cellData) {
  109. if (label == '心电测量') {
  110. return _buildImageDataCell(cellData);
  111. } else if (label == '十二导心电图') {
  112. return _buildImageDataCell(cellData);
  113. } else if (label == '十二导分析结果') {
  114. return _buildEcg12DataCell(cellData);
  115. }
  116. return _buildDataCell(cellData);
  117. },
  118. ).toList(),
  119. ),
  120. );
  121. }
  122. return tableRows;
  123. }
  124. TableCell _buildHeaderCell(String title) {
  125. return TableCell(
  126. child: Container(
  127. padding: const EdgeInsets.symmetric(horizontal: 14),
  128. alignment: Alignment.centerLeft,
  129. height: 37,
  130. child: Text(
  131. title,
  132. style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  133. ),
  134. ),
  135. );
  136. }
  137. String _replaceSemicolon(String input) {
  138. String result = input;
  139. if (result.endsWith(';')) {
  140. result = result.replaceAll(';', '');
  141. } else {
  142. result = result.replaceAll(';', '、');
  143. }
  144. return result;
  145. }
  146. TableCell _buildDataCell(String title) {
  147. if (title.contains(";")) {
  148. title = _replaceSemicolon(title);
  149. }
  150. return TableCell(
  151. child: Container(
  152. padding: const EdgeInsets.symmetric(horizontal: 14),
  153. alignment: Alignment.centerLeft,
  154. height: 37,
  155. child: Text(
  156. title,
  157. style: const TextStyle(fontSize: 14),
  158. ),
  159. ),
  160. );
  161. }
  162. TableCell _buildImageDataCell(String title) {
  163. if (title.length > 50) {
  164. Uint8List imageBytes = isExistLocalData!
  165. ? base64.decode(title)
  166. : base64.decode(
  167. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=");
  168. return TableCell(
  169. child: InkWell(
  170. onTap: () {
  171. print(title);
  172. Get.dialog(
  173. EcgImageDialog(
  174. image: isExistLocalData!
  175. ? Image.memory(
  176. imageBytes,
  177. fit: BoxFit.cover, // 根据需要设置适当的fit属性
  178. )
  179. : Image.network(title),
  180. ),
  181. );
  182. },
  183. child: Container(
  184. padding: const EdgeInsets.symmetric(horizontal: 14),
  185. alignment: Alignment.centerLeft,
  186. height: 57,
  187. child: isExistLocalData!
  188. ? Image.memory(
  189. imageBytes,
  190. )
  191. : Image.network(title),
  192. ),
  193. ),
  194. );
  195. }
  196. return TableCell(
  197. child: Container(
  198. padding: const EdgeInsets.symmetric(horizontal: 14),
  199. alignment: Alignment.centerLeft,
  200. height: 37,
  201. child: Text(
  202. title,
  203. style: const TextStyle(fontSize: 14),
  204. ),
  205. ),
  206. );
  207. }
  208. /// 12导心电的结果
  209. TableCell _buildEcg12DataCell(String value) {
  210. if (value.contains("advice")) {
  211. return TableCell(
  212. child: InkWell(
  213. onTap: () async {
  214. TwelveHeartResultEntity resultConclusion =
  215. TwelveHeartResultEntity.fromJson(jsonDecode(value));
  216. await ConclusionDialog.show(twelveHeartResult: resultConclusion);
  217. },
  218. child: Container(
  219. padding: const EdgeInsets.symmetric(horizontal: 14),
  220. alignment: Alignment.centerLeft,
  221. height: 57,
  222. child: const Text(
  223. "点击查看结果",
  224. style: TextStyle(
  225. color: Colors.blue,
  226. ),
  227. ),
  228. ),
  229. ),
  230. );
  231. }
  232. return TableCell(
  233. child: Container(
  234. padding: const EdgeInsets.symmetric(horizontal: 14),
  235. alignment: Alignment.centerLeft,
  236. height: 57,
  237. child: Text(
  238. value,
  239. style: const TextStyle(fontSize: 14),
  240. ),
  241. ),
  242. );
  243. }
  244. }