exam_table.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:flutter/material.dart';
  2. import 'package:vitalapp/architecture/types/index.dart';
  3. import 'package:vitalapp/components/button.dart';
  4. import 'package:vitalapp/components/no_data_view.dart';
  5. import 'package:vitalapp/pages/check/models/form.dart';
  6. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_radio_and_select.dart';
  7. class ExamTable extends StatelessWidget {
  8. const ExamTable({
  9. super.key,
  10. required this.tableThList,
  11. required this.currentFormObject,
  12. this.currentValue,
  13. this.addTableData,
  14. this.editTableData,
  15. });
  16. final List<String> tableThList;
  17. final FormObject currentFormObject;
  18. final List<dynamic>? currentValue;
  19. final Function? addTableData;
  20. final ValueCallback? editTableData;
  21. @override
  22. Widget build(BuildContext context) {
  23. return Stack(
  24. children: [
  25. ExamCardRadioSelect(
  26. title: currentFormObject.label ?? '',
  27. clickCard: null,
  28. content: Container(
  29. alignment: Alignment.center,
  30. padding: const EdgeInsets.only(
  31. // bottom: 20,
  32. right: 20,
  33. left: 20,
  34. ),
  35. child: SingleChildScrollView(
  36. scrollDirection: Axis.horizontal,
  37. child: Column(
  38. children: [
  39. DataTable(
  40. columnSpacing: 80,
  41. headingRowColor: MaterialStateProperty.all<Color?>(
  42. Theme.of(context).primaryColor),
  43. dataRowHeight: 60,
  44. headingTextStyle: const TextStyle(
  45. fontSize: 24,
  46. color: Colors.white,
  47. ),
  48. dataTextStyle: TextStyle(
  49. fontSize: 22,
  50. color: Colors.black.withOpacity(0.9),
  51. ),
  52. columns: tableThList
  53. .map(
  54. (e) => DataColumn(
  55. numeric: false,
  56. label: Text(
  57. e,
  58. ),
  59. ),
  60. )
  61. .toList(),
  62. rows: currentValue!.map((c) {
  63. List<DataCell> cells = (c as Map)
  64. .entries
  65. .map(
  66. (a) => DataCell(
  67. Container(
  68. constraints: const BoxConstraints(
  69. maxWidth: 150,
  70. ),
  71. child: Text(
  72. a.value ?? '',
  73. overflow: TextOverflow.ellipsis,
  74. ),
  75. ),
  76. ),
  77. )
  78. .toList();
  79. cells.add(
  80. DataCell(
  81. Text(
  82. '编辑',
  83. style: TextStyle(
  84. fontSize: 22,
  85. color: Theme.of(context).primaryColor,
  86. ),
  87. ),
  88. onTap: () {
  89. editTableData!.call(
  90. EditTableValue(
  91. id: int.parse(c['id']),
  92. value: currentValue![int.parse(c['id']) - 1],
  93. ),
  94. );
  95. },
  96. ),
  97. );
  98. return DataRow(
  99. cells: cells,
  100. );
  101. }).toList(),
  102. ),
  103. if (currentValue?.isEmpty ?? true)
  104. Container(
  105. margin: EdgeInsets.symmetric(vertical: 50),
  106. width: 300,
  107. height: 300,
  108. child: FittedBox(
  109. child: VNoDataView(),
  110. ),
  111. )
  112. ],
  113. )),
  114. ),
  115. ),
  116. Positioned(
  117. right: 16,
  118. top: 8,
  119. child: SizedBox(
  120. width: 130,
  121. height: 54,
  122. child: VButton(
  123. // label: '新增',
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.center,
  126. children: const [
  127. Icon(Icons.add, size: 24),
  128. SizedBox(
  129. width: 8,
  130. ),
  131. Text("新增", style: TextStyle(fontSize: 20)),
  132. ],
  133. ),
  134. onTap: () {
  135. addTableData!();
  136. },
  137. ),
  138. ),
  139. ),
  140. ],
  141. );
  142. }
  143. }