exam_table.dart 4.2 KB

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