getcartList method

Future getcartList()

Implementation

Future getcartList() async {
  var decodedResponse;
  try {
    final response = await http.get(
      Uri.parse('${medicine_API}api/diagnostic/cart-details'),
      headers: {'Authorization': currentUserToken},
    );
    decodedResponse = json.decode(response.body);
    CartCount.value = 0;
    CartList = await decodedResponse['response'];
    if (decodedResponse['response'].isNotEmpty) {
      //Cart Count
      CartCount.value = await decodedResponse['response']['cart_count'];
      //Total Payable Price
      var result =
          await decodedResponse['response']['calculation'].firstWhere(
        (element) => element['key'] == "Total payable price",
        orElse: () => 0,
      );
      CartTotalPayable.value = result['value'];
      //Total savings
      var resultamount =
          await decodedResponse['response']['calculation'].firstWhere(
        (element) => element['key'] == "Total saving",
        orElse: () => 0,
      );
      CartTotalSavings.value = resultamount['value'];
    }
  } catch (e) {
    ErrorListner(
        apiname: 'api/diagnostic/cart-details',
        responsed: "${decodedResponse}",
        request: "",
        app_error: '${e}');
  }
}