123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/components/dialog_ecg_image.dart';
- import 'package:vnote_device_plugin/models/exams/twelve_heart.dart';
- import '../pages/medical/widgets/twelve_ecg_view/widgets/conclusion_dialog.dart';
- import 'alert_dialog.dart';
- class VDialogTable extends StatelessWidget {
- final bool? isExistLocalData;
- const VDialogTable({
- super.key,
- this.title,
- required this.columnNames,
- required this.tableData,
- this.diagnosisTime,
- this.isExistLocalData = false,
- });
- final List<List<String>> tableData;
- final List<String> columnNames;
- final String? title;
- final String? diagnosisTime;
- Future<DateTime?> show<DateTime>() => VAlertDialog.showDialog<DateTime>(this);
- @override
- Widget build(BuildContext context) {
- return VAlertDialog(
- width: 800,
- contentPadding: const EdgeInsets.only(left: 16, right: 8),
- content: _buildTable(),
- showCancel: true,
- );
- }
- Widget _buildTable() {
- return SizedBox(
- height: 500,
- child: Column(
- children: [
- const SizedBox(
- height: 10,
- ),
- if (title != null)
- Text(
- title!,
- style: const TextStyle(
- fontSize: 22,
- ),
- ),
- const SizedBox(
- height: 10,
- ),
- Table(
- children: [
- TableRow(
- decoration: const BoxDecoration(
- color: Color.fromRGBO(215, 234, 255, 1),
- ),
- children: columnNames
- .map((columnName) => _buildHeaderCell(columnName))
- .toList(),
- ),
- ],
- ),
- Expanded(
- child: Scrollbar(
- thumbVisibility: true,
- child: SingleChildScrollView(
- child: Table(
- children: _buildRow(tableData),
- ),
- ),
- ),
- ),
- const SizedBox(
- height: 10,
- ),
- Container(
- alignment: Alignment.centerLeft,
- child: Text(
- "检测时间:${diagnosisTime ?? ''}",
- style: const TextStyle(fontSize: 18),
- )),
- const SizedBox(
- height: 10,
- ),
- Container(
- alignment: Alignment.centerLeft,
- child: const Text(
- '注:本结果仅对该检验样本负责!',
- style: TextStyle(fontSize: 18),
- ))
- ],
- ),
- );
- }
- List<TableRow> _buildRow(List<List<String>> tableData) {
- var tableRows = <TableRow>[];
- for (var i = 0; i < tableData.length; i++) {
- final rowData = tableData[i];
- final label = rowData[1];
- tableRows.add(
- TableRow(
- decoration: i % 2 == 0
- ? null
- : const BoxDecoration(
- color: Color.fromRGBO(233, 244, 255, 1),
- ),
- children: tableData[i].map(
- (cellData) {
- if (label == '心电测量') {
- return _buildImageDataCell(cellData);
- } else if (label == '十二导心电图(30秒)') {
- return _buildImageDataCell(cellData);
- } else if (label == '十二导分析结果') {
- return _buildEcg12DataCell(cellData);
- }
- return _buildDataCell(cellData);
- },
- ).toList(),
- ),
- );
- }
- return tableRows;
- }
- TableCell _buildHeaderCell(String title) {
- return TableCell(
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 37,
- child: Text(
- title,
- style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
- ),
- ),
- );
- }
- String _replaceSemicolon(String input) {
- String result = input;
- if (result.endsWith(';')) {
- result = result.replaceAll(';', '');
- } else {
- result = result.replaceAll(';', '、');
- }
- return result;
- }
- TableCell _buildDataCell(String title) {
- if (title.contains(";")) {
- title = _replaceSemicolon(title);
- }
- return TableCell(
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 37,
- child: Text(
- title,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- );
- }
- TableCell _buildImageDataCell(String title) {
- if (title.length > 50) {
- Uint8List imageBytes = isExistLocalData!
- ? base64.decode(title)
- : base64.decode(
- "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=");
- return TableCell(
- child: InkWell(
- onTap: () {
- print(title);
- Get.dialog(
- EcgImageDialog(
- image: isExistLocalData!
- ? Image.memory(
- imageBytes,
- fit: BoxFit.cover, // 根据需要设置适当的fit属性
- )
- : Image.network(title),
- ),
- );
- },
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 57,
- child: isExistLocalData!
- ? Image.memory(
- imageBytes,
- )
- : Image.network(title),
- ),
- ),
- );
- }
- return TableCell(
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 37,
- child: Text(
- title,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- );
- }
- /// 12导心电的结果
- TableCell _buildEcg12DataCell(String value) {
- if (value.contains("advice")) {
- return TableCell(
- child: InkWell(
- onTap: () async {
- TwelveHeartResultEntity resultConclusion =
- TwelveHeartResultEntity.fromJson(jsonDecode(value));
- await ConclusionDialog.show(twelveHeartResult: resultConclusion);
- },
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 57,
- child: const Text(
- "点击查看结果",
- style: TextStyle(
- color: Colors.blue,
- ),
- ),
- ),
- ),
- );
- }
- return TableCell(
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 14),
- alignment: Alignment.centerLeft,
- height: 57,
- child: Text(
- value,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- );
- }
- }
|