fetchBalance method
Implementation
Future<void> fetchBalance(BuildContext context, String? merchantID) async {
try {
isLoading(true);
var request = {
'merchant_id': merchantID ?? Storage.getValue(Constants.merchantID),
'api_key': await Constants.apiKey()
};
var response = await DioClient().request(
context: context,
api: '/merchant/get-info',
method: Method.POST,
params: request);
GetSingleMerchantResponse merchantResponse =
GetSingleMerchantResponse.fromJson(response);
if (merchantResponse.status == Strings.success) {
merchantData = merchantResponse.data!.obs;
//get wallet balance
walletBalanceWhole =
merchantData.value.walletAmount.toString().split(".")[0];
walletBalanceDecimal =
merchantData.value.walletAmount.toString().split(".")[1];
//get
pendingBalanceWhole =
merchantData.value.walletAmountPending.toString().split(".")[0];
pendingBalanceDecimal =
merchantData.value.walletAmountPending.toString().split(".")[1];
} else {
return Utils.showSnackbar(context, Strings.error,
response['message'].toString().toTitleCase(), AppColors.red);
}
} catch (e) {
return Utils.showSnackbar(
context, Strings.error, e.toString().toTitleCase(), AppColors.red);
} finally {
isLoading(false);
}
update();
}