getCart method
Implementation
Future<void> getCart({required String cartId}) async {
BuildContext context = Get.context!;
Helper.progressDialog(context, "message");
String userID = SingletonSotrage.secureStorageInterface.readSecureData(
SecureStorageService.xUserId,
) ??
"";
try {
await ApiClient(baseUrl: ApiConstant.posBaseUrl)
.getCart(
xUserId: userID.toString(),
xRoles: "Dealer",
cartId: cartId,
)
.then((response) async {
Helper.close();
isLoadingGetCartApi.value = false;
CartModel model = response;
if (model.status == "POS200") {
isSuccessCartAPI.value = true;
grandTotal.value = model.data?.grandTotal ?? "0.0";
grandTotalInLocalCurrency.value =
model.data?.grandTotalInLocalCurrency?.price?.amount ?? "0.0";
localCurrency.value =
model.data?.grandTotalInLocalCurrency?.price?.currency ?? "";
currency.value = model.data?.currency ?? "";
sellingPrice.value =
(model.data?.products?.elementAtOrNull(0)?.sellingPrice ?? "0.0")
.toString();
sellingUnitPrice.value =
(model.data?.products?.elementAtOrNull(0)?.sellingUnitPrice ??
"0.0")
.toString();
for (var info in model.data?.taxes ?? []) {
if (info.name == "WHT") {
wht.value = info.totalPrice ?? "";
whtPercentage.value = info.percentage ?? 0.0;
} else if (info.name == "Commission") {
commission.value = info.totalPrice ?? "";
} else if (info.name == "Net Commission") {
netCommission.value = info.totalPrice ?? "";
}
}
} else {
isSuccessCartAPI.value = false;
Helper.messageDialog(
Get.context!,
model.errors?.elementAtOrNull(0)?.code ?? 'tryAgain'.tr,
model.errors?.elementAtOrNull(0)?.localeMessage ??
'technicalErrorMsg'.tr,
);
}
}).catchError((onError) {
isLoadingGetCartApi.value = false;
isSuccessCartAPI.value = false;
Helper.close();
Helper.messageDialog(context, 'tryAgain'.tr, 'tryAgain'.tr);
});
} catch (e, st) {
isLoadingGetCartApi.value = false;
isSuccessCartAPI.value = false;
Helper.close();
if (kDebugMode) {
print(st);
}
}
}