|
|
@@ -18,43 +18,17 @@ class CageChangePage extends StatefulWidget {
|
|
|
class _CageChangePageState extends State<CageChangePage> {
|
|
|
final List<String> _electronicIds = [];
|
|
|
|
|
|
- // 添加TextEditingControllers用于控制输入框
|
|
|
- // final TextEditingController _sourceCageController = TextEditingController();
|
|
|
- // final TextEditingController _targetCageController = TextEditingController();
|
|
|
final TextEditingController _cageController = TextEditingController();
|
|
|
|
|
|
- // 添加FocusNode用于控制焦点
|
|
|
- // final FocusNode _sourceCageFocusNode = FocusNode();
|
|
|
- // final FocusNode _targetCageFocusNode = FocusNode();
|
|
|
-
|
|
|
- // 扫描状态
|
|
|
- // bool _isScanningSource = false;
|
|
|
- // bool _isScanningTarget = false;
|
|
|
- // int _scanTag = 1;
|
|
|
bool _isScanningCode = false;
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
|
|
|
- // _sourceCageController.clear();
|
|
|
- // _targetCageController.clear();
|
|
|
- // 监听焦点变化以更新_scanTag值
|
|
|
- // _sourceCageFocusNode.addListener(() {
|
|
|
- // if (_sourceCageFocusNode.hasFocus) {
|
|
|
- // _scanTag = 1;
|
|
|
- // }
|
|
|
- // });
|
|
|
-
|
|
|
- // _targetCageFocusNode.addListener(() {
|
|
|
- // if (_targetCageFocusNode.hasFocus) {
|
|
|
- // _scanTag = 2;
|
|
|
- // }
|
|
|
- // });
|
|
|
_isScanningCode = false;
|
|
|
_cageController.clear();
|
|
|
|
|
|
- // 延迟到下一帧执行,确保页面构建完成后再打开扫描头
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
ScanChannel.openScanHead().then((success) {
|
|
|
if (success) {
|
|
|
@@ -123,8 +97,6 @@ class _CageChangePageState extends State<CageChangePage> {
|
|
|
},
|
|
|
);
|
|
|
});
|
|
|
-
|
|
|
- // _scanTag = 1;
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -270,94 +242,6 @@ class _CageChangePageState extends State<CageChangePage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- // Widget _buildCageSection(int tag) {
|
|
|
- // String title = '源笼号';
|
|
|
- // TextEditingController controller = _sourceCageController;
|
|
|
- // FocusNode focusNode = _sourceCageFocusNode;
|
|
|
- // bool isScanning = _isScanningSource;
|
|
|
- // if (tag != 1) {
|
|
|
- // tag = 2;
|
|
|
- // title = '目标笼号';
|
|
|
- // controller = _targetCageController;
|
|
|
- // focusNode = _targetCageFocusNode;
|
|
|
- // isScanning = _isScanningTarget;
|
|
|
- // }
|
|
|
- // // 确保光标在文本末尾
|
|
|
- // if (controller.text.isNotEmpty) {
|
|
|
- // controller.selection = TextSelection.fromPosition(
|
|
|
- // TextPosition(offset: controller.text.length),
|
|
|
- // );
|
|
|
- // }
|
|
|
- // return Column(
|
|
|
- // crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
- // children: [
|
|
|
- // Text(title, style: const 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(
|
|
|
- // // 将Text替换为TextField
|
|
|
- // child: TextField(
|
|
|
- // focusNode: focusNode,
|
|
|
- // controller: controller,
|
|
|
- // enabled: controller.text.isEmpty,
|
|
|
- // decoration: InputDecoration(
|
|
|
- // border: InputBorder.none,
|
|
|
- // hintText: controller.text.isNotEmpty ? null : '未扫描',
|
|
|
- // hintStyle: TextStyle(
|
|
|
- // color: controller.text.isNotEmpty
|
|
|
- // ? Colors.black
|
|
|
- // : Colors.grey,
|
|
|
- // fontSize: 16,
|
|
|
- // ),
|
|
|
- // ),
|
|
|
- // style: TextStyle(
|
|
|
- // color: controller.text.isNotEmpty
|
|
|
- // ? Colors.black
|
|
|
- // : Colors.grey,
|
|
|
- // fontSize: 16,
|
|
|
- // ),
|
|
|
- // onChanged: (text) {
|
|
|
- // setState(() {
|
|
|
- // // 文本更改由controller自动处理
|
|
|
- // });
|
|
|
- // },
|
|
|
- // ),
|
|
|
- // ),
|
|
|
- // if (controller.text.isNotEmpty) ...[
|
|
|
- // IconButton(
|
|
|
- // icon: const Icon(Icons.refresh, size: 20),
|
|
|
- // onPressed: () {
|
|
|
- // _handleChangeCageCode(tag);
|
|
|
- // },
|
|
|
- // ),
|
|
|
- // ] else ...[
|
|
|
- // IconButton(
|
|
|
- // icon: isScanning
|
|
|
- // ? const SizedBox(
|
|
|
- // width: 20,
|
|
|
- // height: 20,
|
|
|
- // child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
- // )
|
|
|
- // : const Icon(Icons.qr_code_scanner, size: 20),
|
|
|
- // onPressed: () {
|
|
|
- // _handleScanCageCode(tag);
|
|
|
- // },
|
|
|
- // ),
|
|
|
- // ],
|
|
|
- // ],
|
|
|
- // ),
|
|
|
- // ),
|
|
|
- // ],
|
|
|
- // );
|
|
|
- // }
|
|
|
-
|
|
|
Widget _buildCageSection() {
|
|
|
// 确保光标在文本末尾
|
|
|
if (_cageController.text.isNotEmpty) {
|
|
|
@@ -469,45 +353,6 @@ class _CageChangePageState extends State<CageChangePage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- // void _dealyScanCode(int scanTag, {int? dealy}) async {
|
|
|
- // dealy ??= 800;
|
|
|
- // _scanTag = scanTag;
|
|
|
- // logger.d("开始扫码: $_scanTag");
|
|
|
- // await Future.delayed(Duration(milliseconds: dealy));
|
|
|
- // bool success = await ScanChannel.startScan();
|
|
|
- // if (!success) {
|
|
|
- // ToastUtil.error("扫码失败");
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // void _handleScanCageCode(int tag) async {
|
|
|
- // if (_isScanningTarget || _isScanningSource) return;
|
|
|
- // setState(() {
|
|
|
- // if (tag == 1) {
|
|
|
- // _isScanningSource = true;
|
|
|
- // } else if (tag == 2) {
|
|
|
- // _isScanningTarget = true;
|
|
|
- // }
|
|
|
- // });
|
|
|
- // _scanTag = tag;
|
|
|
- // logger.d("开始扫码: $_scanTag");
|
|
|
- // bool success = await ScanChannel.startScan();
|
|
|
- // if (!success) {
|
|
|
- // ToastUtil.error("扫码失败");
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // void _handleChangeCageCode(int tag) {
|
|
|
- // setState(() {
|
|
|
- // if (tag == 1) {
|
|
|
- // _sourceCageController.clear();
|
|
|
- // } else {
|
|
|
- // _targetCageController.clear();
|
|
|
- // }
|
|
|
- // });
|
|
|
- // _dealyScanCode(tag);
|
|
|
- // }
|
|
|
-
|
|
|
void _handleScanCageCode() async {
|
|
|
if (_isScanningCode) return;
|
|
|
setState(() {
|
|
|
@@ -568,31 +413,16 @@ class _CageChangePageState extends State<CageChangePage> {
|
|
|
apis.breeding.submitApi.cageChange(data).then((res) {
|
|
|
if (res.success) {
|
|
|
if (res.message.isNotEmpty) {
|
|
|
- ToastUtil.success(res.message);
|
|
|
+ ToastUtil.success(res.message.isEmpty ? '换笼成功' : res.message);
|
|
|
}
|
|
|
if (mounted) {
|
|
|
- ScaffoldMessenger.of(context).showSnackBar(
|
|
|
- const SnackBar(
|
|
|
- content: Text('换笼提交成功'),
|
|
|
- backgroundColor: Colors.green,
|
|
|
- ),
|
|
|
- );
|
|
|
// 提交后重置表单
|
|
|
setState(() {
|
|
|
- // _sourceCageController.clear();
|
|
|
- // _targetCageController.clear();
|
|
|
- _cageController.clear();
|
|
|
_electronicIds.clear();
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
- ToastUtil.error('换笼提交失败');
|
|
|
- if (mounted && res.message.isNotEmpty) {
|
|
|
- logger.e(res.message);
|
|
|
- ScaffoldMessenger.of(context).showSnackBar(
|
|
|
- SnackBar(content: Text(res.message), backgroundColor: Colors.red),
|
|
|
- );
|
|
|
- }
|
|
|
+ ToastUtil.errorAlert(res.message.isEmpty ? '换笼提交失败' : res.message);
|
|
|
}
|
|
|
});
|
|
|
}
|