dialog_table.dart 5.0 KB

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