callConvertCurrencyApi method

Future<double> callConvertCurrencyApi(
  1. String from,
  2. String to,
  3. String amount,
  4. String type,
)

Implementation

Future<double> callConvertCurrencyApi(
    String from, String to, String amount, String type) async {
  BuildContext context = Get.context!;
  double priceKHR = 0.0;
  var body = {
    "from": from, //
    "to": to,
    "amount": amount, //
  };
  try {
    await ApiClient(baseUrl: ApiConstant.posBaseUrl)
        .getConvertCurrency(
      body: body,
    )
        .then((response) async {
      ConvertCurrencyModel model = response;
      if (model.data!.price!.amount != null) {
        if (type == "total") {
          totalAmountKHR.value =
              double.parse(model.data!.price!.amount.toString() ?? "0.0");
        } else if (type == "remaining") {
          remainingAmountKHR.value =
              double.parse(model.data!.price!.amount.toString() ?? "0.0");
        } else {
          priceKHR =
              double.parse(model.data!.price!.amount.toString() ?? "0.0");
        }
        return priceKHR;
      }
    }).catchError((onError) {
      Helper.messageDialog(context, 'tryAgain'.tr, onError.toString());
      return priceKHR;
    }).catchError((onError) {
      Helper.messageDialog(context, 'tryAgain'.tr, onError.toString());
      return priceKHR;
    });
  } catch (e, st) {
    print(st);
    return priceKHR;
  }
  return priceKHR;
}