PlaceOrderDetailsFunction method

Future PlaceOrderDetailsFunction({
  1. dynamic context,
  2. dynamic package_id,
  3. dynamic wallet_id,
})

Implementation

Future PlaceOrderDetailsFunction({context, package_id, wallet_id}) async {
  var decodedResponse;
  final ApiBody = {
    "package_id": "${package_id}",
    "wallet_id": "${wallet_id}"
  };
  var body = jsonEncode(ApiBody);

  http.Response response = await http.post(
      Uri.parse('${WELLNESS_URL}api/diagnostic/place-order-details'),
      headers: {
        "Content-Type": "application/json",
        'Authorization': currentUserToken,
      },
      body: body);
  PlaceorderDetails = await json.decode(response.body);
  //Cart Count
  CartCount.value = await PlaceorderDetails['response'].isEmpty
      ? 0
      : PlaceorderDetails['response']['cart_count'];
  //Total Payable Price
  var result = await PlaceorderDetails['response']['calculation'].firstWhere(
    (element) => element['key'] == "Total payable price",
    orElse: () => 0,
  );
  CartTotalPayable.value = result['value'];
  //Total savings
  var resultamount =
      await PlaceorderDetails['response']['calculation'].firstWhere(
    (element) => element['key'] == "Total saving",
    orElse: () => 0,
  );
  CartTotalSavings.value = resultamount['value'];

  if (PlaceorderDetails['success'] == true) {
  } else {
    Get.back();
    PlaceorderDetails['response'].isEmpty
        ? Get.off(AddMemberWithUserDeatails())
        : null;
    Validator().errorMessage(
        context: context, message: "${decodedResponse['message']}");
  }
}