callScanApi method
Implementation
Future<void> callScanApi(String? serialNum, String? serialStartRange,
String? serialEndRange, String requestToPartnerId) async {
BuildContext context = Get.context!;
WidgetsBinding.instance.addPostFrameCallback((_) {
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/459053f9-d2f0-4906-83db-fef44cb2e9a7' // unstock product
// : 'https://run.mocky.io/v3/d6849759-03b5-4222-8e40-95729be0a59e', // stock product
: 'https://run.mocky.io/v3/0174d96c-f4c2-4b93-a999-2a2e14c5291d', // 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) {
Get.back();
if (response.data != null) {
SacnDataModel model = SacnDataModel();
if (kDebugMode) {
print(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");
}
}
}
}, onError: (error) {
if (kDebugMode) {
print(error.toString());
}
Get.back();
Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
});
}