view.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/components/button.dart';
  5. import 'package:vitalapp/pages/medical/views/table_input_dialog/widgets/table_element_row.dart';
  6. import 'package:vitalapp/pages/medical/views/table_input_dialog/widgets/table_title.dart';
  7. import 'index.dart';
  8. class TableInputDialog extends GetView<TableInputDialogController> {
  9. TableInputDialog(
  10. {Key? key,
  11. required this.tableDataConfig,
  12. required this.title,
  13. this.physicalExamNumber,
  14. this.keyValue})
  15. : super(key: key);
  16. /// 列表配置项
  17. final List<TableElementConfig> tableDataConfig;
  18. // 弹窗标题
  19. final String title;
  20. String? physicalExamNumber;
  21. String? keyValue;
  22. // 主视图
  23. Widget _buildView() {
  24. const designWidth = 1280.0; // 设计尺寸宽度:1280
  25. final width = Get.width;
  26. final scale = width / designWidth; // 计算缩放比例
  27. return Container(
  28. width: Get.width * 0.9 / scale,
  29. height: 240 * 3,
  30. decoration: BoxDecoration(
  31. color: Colors.white,
  32. borderRadius: BorderRadius.circular(10),
  33. ),
  34. clipBehavior: Clip.antiAlias,
  35. child: Column(
  36. children: [
  37. _buildHead(),
  38. _buildTableTitle(),
  39. Expanded(
  40. child: _buildBody(),
  41. ),
  42. _buildBottom(),
  43. ],
  44. ),
  45. );
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return GetBuilder<TableInputDialogController>(
  50. init: TableInputDialogController(tableDataConfig: tableDataConfig),
  51. builder: (context) {
  52. return Dialog(
  53. child: _buildView(),
  54. );
  55. },
  56. );
  57. }
  58. /// 构建弹窗顶部,右侧显示关闭按钮
  59. Widget _buildHead() {
  60. return SizedBox(
  61. height: 40,
  62. child: Row(
  63. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  64. children: [
  65. Padding(
  66. padding: const EdgeInsets.symmetric(horizontal: 15),
  67. child: Text(
  68. title,
  69. style: const TextStyle(
  70. fontSize: 16,
  71. fontWeight: FontWeight.bold,
  72. ),
  73. ),
  74. ),
  75. Padding(
  76. padding: const EdgeInsets.symmetric(horizontal: 10),
  77. child: IconButton(
  78. onPressed: () => Get.back(),
  79. icon: const Icon(
  80. Icons.close,
  81. size: 30,
  82. ),
  83. ),
  84. ),
  85. ],
  86. ),
  87. );
  88. }
  89. Widget _buildTableTitle() {
  90. return Padding(
  91. padding: const EdgeInsets.symmetric(horizontal: 10),
  92. child: TableTitle(),
  93. );
  94. }
  95. Widget _buildBody() {
  96. final ScrollController scrollController = ScrollController();
  97. return RawKeyboardListener(
  98. focusNode: FocusNode(),
  99. onKey: (RawKeyEvent value) {
  100. if (value is RawKeyDownEvent) {
  101. if (value.logicalKey == LogicalKeyboardKey.arrowUp) {
  102. controller.focusPre();
  103. } else if (value.logicalKey == LogicalKeyboardKey.arrowDown ||
  104. value.logicalKey == LogicalKeyboardKey.enter) {
  105. controller.focusNext();
  106. }
  107. }
  108. },
  109. child: Scrollbar(
  110. thumbVisibility: true,
  111. thickness: 10,
  112. radius: const Radius.circular(10),
  113. controller: scrollController,
  114. child: SingleChildScrollView(
  115. controller: scrollController,
  116. padding: const EdgeInsets.only(left: 10, right: 10, bottom: 10),
  117. physics: const BouncingScrollPhysics(),
  118. child: Column(
  119. children: [
  120. for (var item in controller.tableData)
  121. TableElementRow(
  122. elementName: item.config.name,
  123. unit: item.config.unit,
  124. textController: item.textController,
  125. focusNode: item.focusNode,
  126. ),
  127. ],
  128. ),
  129. ),
  130. ),
  131. );
  132. }
  133. Widget _buildBottom() {
  134. return Container(
  135. height: 50,
  136. padding: EdgeInsets.symmetric(vertical: 5),
  137. color: Colors.grey[200],
  138. child: Row(
  139. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  140. children: [
  141. Expanded(
  142. child: Container(),
  143. ),
  144. VButton(
  145. onTap: () {
  146. controller.onConfirm(physicalExamNumber, keyValue);
  147. },
  148. child: const Text('提交'),
  149. ),
  150. Expanded(
  151. child: Align(
  152. alignment: Alignment.centerRight,
  153. child: Padding(
  154. padding: const EdgeInsets.only(right: 20),
  155. child: Text(
  156. "Enter 或 ⬆ ⬇ 键可切换项目",
  157. style: TextStyle(
  158. color: Colors.black38,
  159. fontSize: 10,
  160. ),
  161. ),
  162. ),
  163. ),
  164. ),
  165. ],
  166. ),
  167. );
  168. }
  169. }