'I want to add a new value in my list in response body

product_sp.add(newItemPrice);

http.Response response = await client.patch(url,

    body: jsonEncode(<String, dynamic>{
       "records": [
{
      "id": orderId,
  "fields": {
  "product_sp": product_sp,
  }
    }
       ]
    },
    ));

 if (response.statusCode == 200) {
  var data = jsonDecode(response.body);
  print(data);
} else {
  throw Exception();
}

I am trying to add a new item in the product_sp and patching it but it results into an exception.

This is the response body of product_sp right now- product_sp: [L, test]

response.body generatig error:

I/flutter ( 6545): {error: Invalid payload, details: Error: body.records[0] is not a Record; body.records[0].fields.product_sp is not a CellValue; body.records[0].fields.product_sp is none of number, string, boolean, null, 1 more; body.records[0].fields.product_sp[0] is not a GristObjCode; body.records[0].fields.product_sp[0] is not a valid enum value}



Solution 1:[1]

you can use List.generate like

"fields": {
    "list_one": List<int>.generate(array.length, (index)=>index),
  }

For generating random int array with random length which generates int between 1-100 with the length of upto 100 (change max length) . here is the code

"fields": {
    "list_one": List<int>.generate(Random().nextInt(100), (index) => Random().nextInt(100)),
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1