individual_culling_page.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import 'package:flutter/material.dart';
  2. import 'package:chicken_farm/components/vb_app_bar.dart';
  3. import 'package:chicken_farm/components/vb_dict_select.dart';
  4. import 'package:chicken_farm/core/utils/toast.dart';
  5. import 'package:chicken_farm/components/vb_rfid_field.dart';
  6. class IndividualCullingPage extends StatefulWidget {
  7. const IndividualCullingPage({super.key});
  8. @override
  9. State<IndividualCullingPage> createState() => _IndividualCullingPageState();
  10. }
  11. class _IndividualCullingPageState extends State<IndividualCullingPage> {
  12. String? _rfid;
  13. String? _cullReason;
  14. String? _disposalMethod;
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. appBar: const VberAppBar(title: '个体淘汰', showLeftButton: true),
  19. body: Padding(
  20. padding: const EdgeInsets.all(16.0),
  21. child: Column(
  22. crossAxisAlignment: CrossAxisAlignment.start,
  23. children: [
  24. // 电子编号区域
  25. _buildRfidSection(),
  26. const SizedBox(height: 20),
  27. // 淘汰原因
  28. _buildCullReasonSection(),
  29. const SizedBox(height: 20),
  30. // 处置方式
  31. _buildDisposalMethodSection(),
  32. const SizedBox(height: 30),
  33. // 提交按钮
  34. SizedBox(
  35. width: double.infinity,
  36. child: ElevatedButton(
  37. onPressed:
  38. _rfid != null &&
  39. _cullReason != null &&
  40. _disposalMethod != null
  41. ? _handleSubmit
  42. : null,
  43. style: ElevatedButton.styleFrom(
  44. backgroundColor:
  45. _rfid != null &&
  46. _cullReason != null &&
  47. _disposalMethod != null
  48. ? Colors.blue
  49. : Colors.grey,
  50. foregroundColor: Colors.white,
  51. ),
  52. child: const Text('提交'),
  53. ),
  54. ),
  55. ],
  56. ),
  57. ),
  58. );
  59. }
  60. Widget _buildRfidSection() {
  61. return VberRfidField(
  62. rfid: _rfid,
  63. onRfidScanned: (rfid) {
  64. setState(() {
  65. _rfid = rfid;
  66. });
  67. ToastUtil.success('电子编号识别成功');
  68. },
  69. label: '电子编号',
  70. placeholder: '未识别',
  71. );
  72. }
  73. Widget _buildCullReasonSection() {
  74. return Column(
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: [
  77. const Text('淘汰原因', style: TextStyle(fontWeight: FontWeight.bold)),
  78. const SizedBox(height: 10),
  79. Container(
  80. padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
  81. decoration: BoxDecoration(
  82. border: Border.all(color: Colors.grey),
  83. borderRadius: BorderRadius.circular(8),
  84. ),
  85. child: VberDictSelect(
  86. dictType: 'chicken_cull_reason',
  87. value: _cullReason,
  88. onChanged: (value) {
  89. setState(() {
  90. _cullReason = value;
  91. });
  92. },
  93. hint: '请选择淘汰原因',
  94. hideUnderline: true,
  95. ),
  96. ),
  97. ],
  98. );
  99. }
  100. Widget _buildDisposalMethodSection() {
  101. return Column(
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. children: [
  104. const Text('处置方式', style: TextStyle(fontWeight: FontWeight.bold)),
  105. const SizedBox(height: 10),
  106. Container(
  107. padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
  108. decoration: BoxDecoration(
  109. border: Border.all(color: Colors.grey),
  110. borderRadius: BorderRadius.circular(8),
  111. ),
  112. child: VberDictSelect(
  113. dictType: 'chicken_disposal_method',
  114. value: _disposalMethod,
  115. onChanged: (value) {
  116. setState(() {
  117. _disposalMethod = value;
  118. });
  119. },
  120. hint: '请选择处置方式',
  121. hideUnderline: true,
  122. ),
  123. ),
  124. ],
  125. );
  126. }
  127. // 提交数据
  128. void _handleSubmit() {
  129. // 在实际应用中,这里会发送数据到服务器
  130. ScaffoldMessenger.of(context).showSnackBar(
  131. const SnackBar(content: Text('个体淘汰提交成功'), backgroundColor: Colors.green),
  132. );
  133. // 提交后重置表单
  134. setState(() {
  135. _rfid = null;
  136. _cullReason = null;
  137. _disposalMethod = null;
  138. });
  139. }
  140. }