getMedicineCartDetails method

Future getMedicineCartDetails({
  1. dynamic package_id,
  2. dynamic wallet_id,
})

Implementation

Future getMedicineCartDetails({package_id, wallet_id}) async {
  var decodedResponse;
  try {
    var url =
        '${medicine_API}api/medicine/medicine-cart-details?pincode=${enteredPincode.value}';

    if (package_id != null) {
      url += '&package_id=$package_id';
    }
    if (wallet_id != null) {
      url += '&wallet_id=$wallet_id';
    }

    final response = await http.get(
      Uri.parse(url),
      headers: {'Authorization': currentUserToken},
    );
    decodedResponse = json.decode(response.body);

    MedicineCartDetails = decodedResponse;

    totalCartItems.value = decodedResponse['total_items'];
    double payableAmount = decodedResponse['payable_amount'] is int
        ? (decodedResponse['payable_amount'] as int).toDouble()
        : decodedResponse['payable_amount'] as double;

    cartTotalAmount.value = payableAmount;
  } catch (e) {
    ErrorListner(
      apiname:
          'api/medicine/medicine-cart-details?pincode=${enteredPincode.value}',
      responsed: "${decodedResponse}",
      request: "",
      app_error: '${e}',
    );
  }
}