callUpdateCartApi method
Implementation
Future<void> callUpdateCartApi(String? serialNum, String? serialStartRange,
String? serialEndRange, String? productCode) async {
BuildContext context = Get.context!;
Helper.progressDialog(context, "Please wait..");
AddToCartRequest body = prepareCartRequest(
checkValue(serialNum),
checkValue(serialStartRange),
checkValue(serialEndRange),
productCode,
);
try {
String requestTime = "";
String responseTime = "";
cart.CartModel model = await ApiClient(
baseUrl: ApiConstant.posBL,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: "productsBottomsheet",
).updateCart(
body: body,
cartId: cartId,
xRoles: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
xUserId: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
);
if (model.status == "POS200") {
cartId = model.data!.cartId!;
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: "${Api.addToCart}/$cartId",
responseDate: responseTime,
screenName: "productsBottomsheet",
requestDate: requestTime,
transactionId: cartId,
);
discountList.value = model.data!.cartDiscountsList!;
Helper.close();
Helper.showAssetSnackbar(
"Asset added successfully",
"Product ID: ${serialNum ?? serialStartRange}",
);
// await Helper.assetSuccessDialog(
// Get.context!,
// "Asset added successfully",
// "Product ID: ${serialNum ?? serialStartRange}",
// const AssetImage(
// "assets/images/success.png",
// package: Constants.packageName,
// ));
if (currentScan == ScanType.spotSellThru) {
await updateSpotSellThruOrder(model);
} else if (currentScan == ScanType.sellThru) {
await updateSellThruOrder(model);
} else if (currentScan == ScanType.collectStock) {
totalRetailPrice = model.data!.totalRetailPrice as double;
await updateCollectStock(
model,
serialNum,
serialStartRange,
serialEndRange,
productCode,
);
}
isScanning.value = false;
} else {
Helper.close();
if (model.errors != null) {
Helper.messageDialog(
Get.context!,
model.errors![0].code ?? "Try again!!",
model.errors![0].localeMessage ?? "Something went wrong",
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
}
}
} catch (err, stacktrace) {
Helper.close();
ConditionalLogs().customLog("$err");
ConditionalLogs().customLog("$stacktrace");
Helper.messageDialog(
Get.context!,
localization.translate("tryAgain"),
localization.translate("technicalErrorMsg"),
isDismissible: false,
onTap: () {
isScanning.value = false;
Helper.close();
},
);
}
}