view.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/database/entities/defines.dart';
  4. import 'package:vitalapp/database/entities/patient.dart';
  5. import 'controller.dart';
  6. final _tableColumnWidths = <int, TableColumnWidth>{
  7. 0: const FixedColumnWidth(180),
  8. 1: const FlexColumnWidth(),
  9. 2: const FlexColumnWidth(),
  10. 3: const FixedColumnWidth(220),
  11. 4: const FixedColumnWidth(220),
  12. };
  13. class PatientSyncPage extends GetView<PatientSyncController> {
  14. const PatientSyncPage({super.key});
  15. @override
  16. Widget build(BuildContext context) {
  17. return Column(
  18. children: [
  19. _TableHeader(),
  20. SingleChildScrollView(
  21. child: _buildDataTable(),
  22. ),
  23. ],
  24. );
  25. }
  26. Widget _buildDataTable() {
  27. return Obx(
  28. () {
  29. final children = <TableRow>[];
  30. for (var i = 0; i < controller.state.dataList.length; i++) {
  31. final entity = controller.state.dataList[i];
  32. children.add(_buildDataRow(entity, i));
  33. }
  34. return Table(
  35. children: children,
  36. defaultVerticalAlignment: TableCellVerticalAlignment.middle,
  37. columnWidths: _tableColumnWidths,
  38. );
  39. },
  40. );
  41. }
  42. TableRow _buildDataRow(PatientEntity entity, int index) {
  43. return TableRow(
  44. decoration: index % 2 == 0
  45. ? null
  46. : const BoxDecoration(
  47. color: Color.fromRGBO(233, 244, 255, 1),
  48. ),
  49. children: [
  50. _buildDataCell(entity.id.toString()),
  51. _buildDataCell(entity.name),
  52. _buildDataCell(entity.syncType.getDescription()),
  53. _buildDataCell(entity.syncState.getDescription()),
  54. _buildDataCell(""),
  55. ],
  56. );
  57. }
  58. TableCell _buildDataCell(String title) {
  59. return TableCell(
  60. child: Container(
  61. alignment: Alignment.center,
  62. height: 37,
  63. child: Text(
  64. title,
  65. style: const TextStyle(fontSize: 14),
  66. ),
  67. ),
  68. );
  69. }
  70. }
  71. class _TableHeader extends StatelessWidget {
  72. @override
  73. Widget build(BuildContext context) {
  74. return Table(
  75. children: [
  76. TableRow(
  77. decoration: const BoxDecoration(
  78. color: Color.fromRGBO(215, 234, 255, 1),
  79. ),
  80. children: [
  81. _buildHeaderCell("ID"),
  82. _buildHeaderCell("姓名"),
  83. _buildHeaderCell("类型"),
  84. _buildHeaderCell("状态"),
  85. _buildHeaderCell("操作"),
  86. ],
  87. ),
  88. ],
  89. defaultVerticalAlignment: TableCellVerticalAlignment.middle,
  90. columnWidths: _tableColumnWidths,
  91. );
  92. }
  93. TableCell _buildHeaderCell(String title) {
  94. return TableCell(
  95. child: Container(
  96. alignment: Alignment.center,
  97. height: 37,
  98. child: Text(
  99. title,
  100. style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
  101. ),
  102. ),
  103. );
  104. }
  105. }