How can I read a JSON with an array of objects?

Database & APIs

I have a JSON that comes from an API call similar to this one and I would like to display it in a ListView with expandable datatypes for the items. How can I do this?

{
  "name": "JSON Example",
  "description": "This is an example of a JSON file with fields and an array of objects.",
  "creation_date": "2024-07-12",
  "status": "active",
  "items": [
    {
      "id": 1,
      "name": "Item 1",
      "quantity": 10,
      "price": 29.99
    },
    {
      "id": 2,
      "name": "Item 2",
      "quantity": 5,
      "price": 19.99
    },
    {
      "id": 3,
      "name": "Item 3",
      "quantity": 20,
      "price": 39.99
    }
  ]
}
What have you tried so far?

I tried to create a datatype with another datatype internally, then create a custom action to iterate over the datatype, but the data doesn't appear. The API call returns the data, but it is not applied to the page state. The datatype was created based on the JSON


Future<List<ProdutosVendidosSubStruct>> vendasCarrinhos(
    List<dynamic>? jsonArray) async {
  // convert json array into list of objects

  List<ProdutosVendidosSubStruct> listOfStruct = [];
  if (jsonArray != null) {
    for (var item in jsonArray) {
      listOfStruct.add(ProdutosVendidosSubStruct.fromMap(item));
    }
  }
  return listOfStruct;

Did you check FlutterFlow's Documentation for this topic?
Yes
1 reply