import 'dart:convert'; import 'package:bruno/bruno.dart'; import 'package:flutter/material.dart'; import '/common/colorCom.dart'; import 'package:wms_app/utils/DialogUtils.dart'; import 'package:wms_app/apiclient/WmsApiClient.dart'; class StockInEmpty extends StatefulWidget { const StockInEmpty({super.key}); @override State createState() => _StockInEmptyPageState(); } /// 空托入库界面 class _StockInEmptyPageState extends State { final _vehicleTextController = TextEditingController(); // 载具号输入框 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( iconTheme: const IconThemeData( color: Colors.white ), leading: IconButton(onPressed: () { Navigator.of(context).pop(); }, icon: const Icon(Icons.arrow_back)), centerTitle: true, backgroundColor: ColorCommon.colorScheme, title: const Text( "空载具入库", style: TextStyle( color: Colors.white ), ), ), body: Center( child: Padding(padding: const EdgeInsets.only( top: 5, left: 10, right: 10, ), child: ListView( children: [ BrnTextInputFormItem( controller: _vehicleTextController, title: "载具号:", hint: "请扫描或输入" ), Padding(padding: const EdgeInsets.only( top: 5 ), child: ElevatedButton( onPressed: emptyIn, style: ButtonStyle( backgroundColor: WidgetStateProperty.all(ColorCommon.colorScheme), ), child: const Text( "空载具入库", style: TextStyle( color: Colors.white )) )) ], )), ), ); } /// 空托入库方法 void emptyIn() { String vehicleNo = _vehicleTextController.text.trim(); if(vehicleNo == "" ) { DialogUtils.showWarningMessage(context, "请先填写载具号", "", btnLabel: "返回填写"); return; } BrnLoadingDialog.show(context, content: "正在请求", barrierDismissible: false); WmsApiClient.emptyVehicleIn(vehicleNo).then((response) { if(response["code"] != 200) { var thisContext = context; if(thisContext.mounted) { DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败", btnLabel: "我知道了"); } return; } final data = Map.from(jsonDecode(response["data"])); if(data["code"] == 200) { // 请求成功 var thisContext = context; if(thisContext.mounted) { DialogUtils.showSuccessMessage(thisContext, "成功", "", btnLabel: "我知道了"); _vehicleTextController.text = ""; } return; } var thisContext = context; if(thisContext.mounted) { DialogUtils.showWarningMessage(thisContext, "警告", "服务器返回失败:${data["message"]}", btnLabel: "我知道了"); } return; }).catchError((err){ var thisContext = context; if(thisContext.mounted) { DialogUtils.showErrorMessage(thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}", btnLabel: "我知道了"); } return; }).whenComplete((){ var thisContext = context; if(thisContext.mounted) { BrnLoadingDialog.dismiss(thisContext); } }); } }