0

I've successfully used rest api of woocommerce in my flutter app but I'm stuck at one point which is adding line_items in json file through woocommerce rest API.

List<CartPdt>linecartitems=[];
linecartitems.map((i)=>{
  'product_id':int.parse(i.id),
  'quantity':i.quantity
}).toList();

var lc=json.encode(linecartitems);

var createOrderUrl = await http.post(
    'url',
    body: json.encode({
      'billing': {
        'first_name': fname,
        'last_name': lname,
        'email': email,
        'address': address,
        'city': city,
        'phone': phone
      },
      'line_items':lc,
    }),
    headers: {"Content-Type": "application/json"},
  );
Maida Farooqi
  • 41
  • 2
  • 9

1 Answers1

0

You need to convert your list model to JSON. I assume that you have not got toJson method in your model. Add this:

Map<String, dynamic> toJson(){
  return {
    "product_id": this. product_id,
    "quantity": this. quantity
  };
}

Akif
  • 7,098
  • 7
  • 27
  • 53