reap_step_list_page.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/base/base_lifecycle_state.dart';
  3. import 'package:lszlgl/base/base_state.dart';
  4. import 'package:lszlgl/config/colors.dart';
  5. import 'package:lszlgl/page/reap_step/reap_step_tab_page.dart';
  6. import 'package:lszlgl/widget/button.dart';
  7. /// 扦样环节列表
  8. class ReapStepListPage extends StatefulWidget {
  9. final StepType type;
  10. final bool complete;
  11. const ReapStepListPage({
  12. super.key,
  13. required this.type,
  14. this.complete = false,
  15. });
  16. @override
  17. State<ReapStepListPage> createState() => _ReapStepListPageState();
  18. }
  19. class _ReapStepListPageState extends BaseLifecycleState<ReapStepListPage> {
  20. late List<Map<String, String>> infoList;
  21. /// 详情
  22. void startDetail() {
  23. if (!widget.complete) return;
  24. switch (widget.type) {
  25. case StepType.reap:
  26. MyRouter.startReapSampleTask(detail: true);
  27. break;
  28. case StepType.stock:
  29. break;
  30. }
  31. }
  32. /// 扦样
  33. void startSample() {
  34. switch (widget.type) {
  35. case StepType.reap:
  36. MyRouter.startReapSampleTask();
  37. break;
  38. case StepType.stock:
  39. break;
  40. }
  41. }
  42. @override
  43. void onInit() {
  44. String taskType = switch (widget.type) {
  45. StepType.reap => '收购监测',
  46. StepType.stock => '库存监测',
  47. _ => '',
  48. };
  49. if (widget.complete) {
  50. infoList = [
  51. {'采样品种': '玉米'},
  52. {'粮食品类': '粮食品类'},
  53. {'监测类别': taskType},
  54. {'扦样数量(kg)': '10'},
  55. {'扦样人员': '李飞'},
  56. {'扦样时间': '2024-01-01'},
  57. ];
  58. } else {
  59. infoList = [
  60. {'采样品种': '玉米'},
  61. {'报送截止时间': '2024-01-01'},
  62. {'监测类别': taskType},
  63. {'扦样人员': '李飞'},
  64. ];
  65. }
  66. }
  67. @override
  68. Widget build(BuildContext context) {
  69. return Container(
  70. clipBehavior: Clip.hardEdge,
  71. decoration: const BoxDecoration(
  72. color: Colors.white,
  73. borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
  74. ),
  75. alignment: Alignment.center,
  76. child: buildList(),
  77. );
  78. }
  79. Widget buildList() {
  80. return ListView.builder(
  81. physics: const BouncingScrollPhysics(),
  82. padding: EdgeInsets.zero,
  83. itemCount: 10,
  84. itemBuilder: (_, index) => buildItem(index),
  85. );
  86. }
  87. Widget buildItem(int index) {
  88. return GestureDetector(
  89. behavior: HitTestBehavior.opaque,
  90. onTap: () => startDetail(),
  91. child: Container(
  92. margin: const EdgeInsets.only(left: 12, right: 12, top: 12),
  93. decoration: const BoxDecoration(
  94. color: Color(0xFFF5FFFD),
  95. borderRadius: BorderRadius.all(Radius.circular(8)),
  96. ),
  97. child: Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: [
  100. const SizedBox(height: 15),
  101. buildTop(),
  102. buildNumber(),
  103. buildGrid(),
  104. buildBottom(),
  105. const SizedBox(height: 15),
  106. ],
  107. ),
  108. ),
  109. );
  110. }
  111. Widget buildTop() {
  112. return Row(
  113. children: [
  114. buildVLine(),
  115. const Expanded(
  116. child: Text(
  117. '扦样任务单号',
  118. style: TextStyle(color: MyColor.c_333333, fontSize: 18, fontWeight: FontWeight.w500),
  119. ),
  120. ),
  121. buildState(),
  122. ],
  123. );
  124. }
  125. Widget buildVLine() {
  126. return Container(
  127. width: 4,
  128. height: 20,
  129. margin: const EdgeInsets.only(right: 8),
  130. decoration: const BoxDecoration(
  131. color: MyColor.c_25A6EE,
  132. borderRadius: BorderRadius.all(Radius.circular(2)),
  133. ),
  134. );
  135. }
  136. Widget buildState() {
  137. String state = widget.complete ? '已扦样' : '待扦样';
  138. return Container(
  139. padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 4),
  140. decoration: BoxDecoration(
  141. color: MyColor.c_25A6EE.withOpacity(0.1),
  142. borderRadius: const BorderRadius.horizontal(left: Radius.circular(100)),
  143. ),
  144. child: Text(
  145. '状态:$state',
  146. style: const TextStyle(color: MyColor.c_1383C2, fontSize: 16),
  147. ),
  148. );
  149. }
  150. Widget buildNumber() {
  151. return const Padding(
  152. padding: EdgeInsets.only(left: 12, top: 4, bottom: 6),
  153. child: Text(
  154. '***********',
  155. style: TextStyle(color: MyColor.c_333333, fontSize: 18, fontWeight: FontWeight.w500),
  156. ),
  157. );
  158. }
  159. Widget buildGrid() {
  160. return Padding(
  161. padding: const EdgeInsets.symmetric(horizontal: 12),
  162. child: LayoutBuilder(builder: (context, constraints) {
  163. return Wrap(
  164. spacing: 4,
  165. runSpacing: 4,
  166. children: infoList.map((item) {
  167. return SizedBox(
  168. width: constraints.maxWidth / 2 - 2,
  169. child: Text(
  170. '${item.keys.first}:${item.values.first}',
  171. style: const TextStyle(fontSize: 16, color: MyColor.c_666666),
  172. ),
  173. );
  174. }).toList(),
  175. );
  176. }),
  177. );
  178. }
  179. Widget buildBottom() {
  180. if (widget.complete) return const SizedBox.shrink();
  181. return Column(
  182. children: [
  183. buildDivider(),
  184. Row(
  185. children: [
  186. const SizedBox(width: 12),
  187. const Expanded(
  188. child: Text(
  189. '[张三]创建于2024-01-01 00:00:00',
  190. style: TextStyle(fontSize: 16, color: MyColor.c_666666),
  191. ),
  192. ),
  193. const SizedBox(width: 4),
  194. MyButton(
  195. '开始扦样',
  196. onTap: () => startSample(),
  197. fountSize: 16,
  198. alignment: null,
  199. padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
  200. ),
  201. const SizedBox(width: 12),
  202. ],
  203. ),
  204. ],
  205. );
  206. }
  207. Widget buildDivider() {
  208. return Container(
  209. width: double.infinity,
  210. height: 1,
  211. color: MyColor.c_3BD2E5.withOpacity(0.15),
  212. margin: const EdgeInsets.symmetric(vertical: 10),
  213. );
  214. }
  215. }