import 'package:flutter/material.dart'; import 'package:chicken_farm/components/vb_app_bar.dart'; import 'package:chicken_farm/components/vb_dict_select.dart'; import 'package:chicken_farm/core/utils/toast.dart'; class IndividualCullingPage extends StatefulWidget { const IndividualCullingPage({super.key}); @override State createState() => _IndividualCullingPageState(); } class _IndividualCullingPageState extends State { String? _rfid; String? _cullReason; String? _disposalMethod; bool _isScanningRfid = false; @override Widget build(BuildContext context) { return Scaffold( appBar: const VberAppBar(title: '个体淘汰', showLeftButton: true), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 电子编号区域 _buildRfidSection(), const SizedBox(height: 20), // 淘汰原因 _buildCullReasonSection(), const SizedBox(height: 20), // 处置方式 _buildDisposalMethodSection(), const SizedBox(height: 30), // 提交按钮 SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _rfid != null && _cullReason != null && _disposalMethod != null ? _handleSubmit : null, style: ElevatedButton.styleFrom( backgroundColor: _rfid != null && _cullReason != null && _disposalMethod != null ? Colors.blue : Colors.grey, foregroundColor: Colors.white, ), child: const Text('提交'), ), ), ], ), ), ); } Widget _buildRfidSection() { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('电子编号', style: TextStyle(fontWeight: FontWeight.bold)), const SizedBox(height: 10), Container( padding: const EdgeInsets.fromLTRB(16, 2, 16, 2), decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(8), ), child: Row( children: [ Expanded( child: Text( _rfid ?? '未扫描', style: TextStyle( color: _rfid != null ? Colors.black : Colors.grey, fontSize: 16, ), ), ), IconButton( icon: _isScanningRfid ? const SizedBox( width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2), ) : const Icon(Icons.qr_code_scanner, size: 20), onPressed: _simulateScanRfid, ), ], ), ), ], ); } Widget _buildCullReasonSection() { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('淘汰原因', style: TextStyle(fontWeight: FontWeight.bold)), const SizedBox(height: 10), Container( padding: const EdgeInsets.fromLTRB(16, 2, 16, 2), decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(8), ), child: VberDictSelect( dictType: 'chicken_cull_reason', value: _cullReason, onChanged: (value) { setState(() { _cullReason = value; }); }, hint: '请选择淘汰原因', hideUnderline: true, ), ), ], ); } Widget _buildDisposalMethodSection() { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('处置方式', style: TextStyle(fontWeight: FontWeight.bold)), const SizedBox(height: 10), Container( padding: const EdgeInsets.fromLTRB(16, 2, 16, 2), decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(8), ), child: VberDictSelect( dictType: 'chicken_disposal_method', value: _disposalMethod, onChanged: (value) { setState(() { _disposalMethod = value; }); }, hint: '请选择处置方式', hideUnderline: true, ), ), ], ); } // 模拟扫描电子编号 void _simulateScanRfid() { if (_isScanningRfid) return; setState(() { _isScanningRfid = true; }); // 模拟扫描过程 Future.delayed(const Duration(seconds: 1), () { if (mounted) { setState(() { _rfid = 'RFID-${DateTime.now().millisecondsSinceEpoch}'; _isScanningRfid = false; }); ToastUtil.success('电子编号扫描成功'); } }); } // 提交数据 void _handleSubmit() { // 在实际应用中,这里会发送数据到服务器 ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('个体淘汰提交成功'), backgroundColor: Colors.green), ); // 提交后重置表单 setState(() { _rfid = null; _cullReason = null; _disposalMethod = null; }); } }