dialog_table.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:get/get.dart';
  5. import 'alert_dialog.dart';
  6. class VDialogTable extends StatelessWidget {
  7. final bool? isExistLocalData;
  8. const VDialogTable({
  9. super.key,
  10. this.title,
  11. required this.columnNames,
  12. required this.tableData,
  13. this.diagnosisTime,
  14. this.isExistLocalData = false,
  15. });
  16. final List<List<String>> tableData;
  17. final List<String> columnNames;
  18. final String? title;
  19. final String? diagnosisTime;
  20. Future<DateTime?> show<DateTime>() => VAlertDialog.showDialog<DateTime>(this);
  21. @override
  22. Widget build(BuildContext context) {
  23. return VAlertDialog(
  24. width: 800,
  25. contentPadding: const EdgeInsets.only(left: 16, right: 8),
  26. content: _buildTable(),
  27. showCancel: true,
  28. );
  29. }
  30. Widget _buildTable() {
  31. return SizedBox(
  32. height: 500,
  33. child: Column(
  34. children: [
  35. const SizedBox(
  36. height: 10,
  37. ),
  38. if (title != null)
  39. Text(
  40. title!,
  41. style: const TextStyle(
  42. fontSize: 22,
  43. ),
  44. ),
  45. const SizedBox(
  46. height: 10,
  47. ),
  48. Table(
  49. children: [
  50. TableRow(
  51. decoration: const BoxDecoration(
  52. color: Color.fromRGBO(215, 234, 255, 1),
  53. ),
  54. children: columnNames
  55. .map((columnName) => _buildHeaderCell(columnName))
  56. .toList(),
  57. ),
  58. ],
  59. ),
  60. Expanded(
  61. child: Scrollbar(
  62. thumbVisibility: true,
  63. child: SingleChildScrollView(
  64. child: Table(
  65. children: _buildRow(tableData),
  66. ),
  67. ),
  68. ),
  69. ),
  70. const SizedBox(
  71. height: 10,
  72. ),
  73. Container(
  74. alignment: Alignment.centerLeft,
  75. child: Text(
  76. "检测时间:${diagnosisTime ?? ''}",
  77. style: const TextStyle(fontSize: 18),
  78. )),
  79. const SizedBox(
  80. height: 10,
  81. ),
  82. Container(
  83. alignment: Alignment.centerLeft,
  84. child: const Text(
  85. '注:本结果仅对该检验样本负责!',
  86. style: TextStyle(fontSize: 18),
  87. ))
  88. ],
  89. ),
  90. );
  91. }
  92. List<TableRow> _buildRow(List<List<String>> tableData) {
  93. var tableRows = <TableRow>[];
  94. for (var i = 0; i < tableData.length; i++) {
  95. tableRows.add(
  96. TableRow(
  97. decoration: i % 2 == 0
  98. ? null
  99. : const BoxDecoration(
  100. color: Color.fromRGBO(233, 244, 255, 1),
  101. ),
  102. children: tableData[i].map(
  103. (cellData) {
  104. if (tableData[i][1] == '心电测量') {
  105. return _buildImageDataCell(cellData);
  106. }
  107. if (tableData[i][1] == '十二导心电图') {
  108. return _buildImageDataCell(cellData);
  109. }
  110. return _buildDataCell(cellData);
  111. },
  112. ).toList(),
  113. ),
  114. );
  115. }
  116. return tableRows;
  117. }
  118. TableCell _buildHeaderCell(String title) {
  119. return TableCell(
  120. child: Container(
  121. padding: const EdgeInsets.symmetric(horizontal: 14),
  122. alignment: Alignment.centerLeft,
  123. height: 37,
  124. child: Text(
  125. title,
  126. style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  127. ),
  128. ),
  129. );
  130. }
  131. TableCell _buildDataCell(String title) {
  132. return TableCell(
  133. child: Container(
  134. padding: const EdgeInsets.symmetric(horizontal: 14),
  135. alignment: Alignment.centerLeft,
  136. height: 37,
  137. child: Text(
  138. title,
  139. style: const TextStyle(fontSize: 14),
  140. ),
  141. ),
  142. );
  143. }
  144. TableCell _buildImageDataCell(String title) {
  145. if (title.length > 50) {
  146. Uint8List imageBytes = isExistLocalData!
  147. ? base64.decode(title)
  148. : base64.decode(
  149. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=");
  150. return TableCell(
  151. child: InkWell(
  152. onTap: () {
  153. print(title);
  154. Get.dialog(
  155. ImagePreviewDialog(
  156. image: isExistLocalData!
  157. ? Image.memory(
  158. imageBytes,
  159. )
  160. : Image.network(title),
  161. ),
  162. );
  163. },
  164. child: Container(
  165. padding: const EdgeInsets.symmetric(horizontal: 14),
  166. alignment: Alignment.centerLeft,
  167. height: 57,
  168. child: isExistLocalData!
  169. ? Image.memory(
  170. imageBytes,
  171. )
  172. : Image.network(title),
  173. ),
  174. ),
  175. );
  176. }
  177. return TableCell(
  178. child: Container(
  179. padding: const EdgeInsets.symmetric(horizontal: 14),
  180. alignment: Alignment.centerLeft,
  181. height: 37,
  182. child: Text(
  183. title,
  184. style: const TextStyle(fontSize: 14),
  185. ),
  186. ),
  187. );
  188. }
  189. }
  190. class ImagePreviewDialog extends StatelessWidget {
  191. final Image image;
  192. const ImagePreviewDialog({super.key, required this.image});
  193. @override
  194. Widget build(BuildContext context) {
  195. return Dialog(
  196. child: SizedBox(
  197. width: 800,
  198. height: 500,
  199. child: SizedBox(
  200. width: double.maxFinite,
  201. child: ListView(
  202. scrollDirection: Axis.horizontal,
  203. children: [
  204. image,
  205. // 添加更多的图片
  206. ],
  207. ),
  208. ),
  209. ),
  210. );
  211. }
  212. }