Search code examples
androidflutterdartflutter-getx

flutter - Unable to parse JSON message: The document is empty


I am working on a cart system. I am trying to sum of the product price added into the list. When I update the product quantity it gives me following error.

I am using getx for this. But I don't think it is a getx error.

Unable to parse JSON message: The document is empty.

  countTotalPrice() async {
    totalPrice = 0.0;
    for (var i = 0; i < cartProducts.length; i++) {
      totalPrice += cartProducts[i]['total'] as double;
    }
    update();
  }

  addToCart(int index) async {
    Map data = {
      "product_name": productsList[index]['english_name'],
      "price": productsList[index]['sale_price'],
      "qty": 1,
      "total": productsList[index]['sale_price'],
    };
    cartProducts.add(data);
    countTotalPrice();
    update();
  }

updateQuantity(index, count) {
    Map data = cartProducts[index];
    data['qty'] = count;
    data['total'] = double.parse(data['price']) * data['qty'];
    countTotalPrice();
    update();
  }

Solution

  • try this

    data['total'] = double.parse(data['price'].toString()) * double.parse(data['qty'].toString())).toString();