callCreditLimitApi method
void
callCreditLimitApi()
Implementation
void callCreditLimitApi() async {
BuildContext context = Get.context!;
WidgetsBinding.instance.addPostFrameCallback((_) {
Helper.progressDialog(context, "Please wait..");
});
dio
.get(
'https://run.mocky.io/v3/f352b067-79ed-42de-bf13-77bf0ab6ce9f',
options: Options(
headers: {
'Authorization': 'Bearer Authorization',
'Content-Type': 'application/x-www-form-urlencoded',
},
),
)
.then((response) {
Get.back();
if (response.data != null) {
if (kDebugMode) {
print(response.data);
}
Map<String, dynamic> creditData = response.data;
creditData.forEach((key, value) {
if (key == "usedCreditLimit") {
usedCreditBalance.value = creditData['usedCreditLimit'] ?? 0.0;
} else if (key == "totalCreditLimit") {
totalCreditBalance.value = creditData['totalCreditLimit'] ?? 0.0;
} else if (key == "remainingCreditLimit") {
availableCreditBalance.value =
creditData['remainingCreditLimit'] ?? 0.0;
}
});
if (totalCreditBalance.value != 0.0) {
percentageCreditBalance.value =
usedCreditBalance.value / totalCreditBalance.value;
callJCApi();
}
}
}, onError: (error) {
if (kDebugMode) {
print(error.toString());
}
Get.back();
Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
});
}