callScanApi method
Implementation
Future<void> callScanApi(String? serialNum, String? serialStartRange,
String? serialEndRange, String requestToPartnerId) async {
BuildContext context = Get.context!;
Helper.progressDialog(context, "Please wait..");
dio
.get(
selectedScanType.value == "Range"
// ? 'https://run.mocky.io/v3/a20817f2-2689-47b0-953a-9c5012ca586b'
? 'https://run.mocky.io/v3/7712e5ff-cf00-4b79-816d-e0cc774fb759' // unstock product
// : 'https://run.mocky.io/v3/d6849759-03b5-4222-8e40-95729be0a59e', // stock product
: 'https://run.mocky.io/v3/8b3976c9-0fcb-4c6c-b76e-e76836639a4d',
// unstock product
data: {
"serialNumber":
serialNum, // either serial number or range -> one of them is mandatory
"serialStartRange": serialStartRange,
"serialEndRange": serialEndRange,
"requestToPartnerId": requestToPartnerId, // distributor id
},
options: Options(
headers: {
'Authorization': 'Bearer Authorization',
'Content-Type': 'application/x-www-form-urlencoded',
},
),
)
.then((response) {
Helper.close();
if (response.data != null) {
SacnDataModel model = SacnDataModel();
ConditionalLogs().customLog(response.data);
Map<String, dynamic> productData = response.data;
if (productData['status']) {
ScanProductModel dataproductModel =
ScanProductModel.fromJson(productData['data']);
var scannedList = <ScanContentModel>[];
scannedList.addAll(dataproductModel.content!);
addScannedAsset(
scannedList,
selectedScanType.value == "Single" ? int.parse(serialNum!) : null,
selectedScanType.value == "Range"
? int.parse(serialStartRange!)
: null,
selectedScanType.value == "Range"
? int.parse(serialEndRange!)
: null);
} else {
model.errors = productData["errors"];
if (productData["errors"] != null) {
Helper.messageDialog(
Get.context!,
model.errors![0].errorCode ?? "Try again!!",
model.errors![0].errorDescription ?? "Something went wrong");
}
}
}
}).catchError((error) {
ConditionalLogs().customLog("$error");
Helper.close();
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
});
}