title: How to use nested loops for fetching the data from a rest api in flutter?
body: <p>I have a order screen where the placed orders and the items that are placed for each order is displayed. I have used a for loop to fetch the orders from the api but in the order json response it also has items parameter inside which there are multiple items. I am not able to figure out how to place another loop in the code to fetch the items list. So please help me with it...
  Thank you..</p>
  
  <p>my json response</p>
  
  <pre><code>    [
      {
      "id": 1453,
      "total": "407.00",
      "line_items": [
          {
              "id": 34,
              "name": "Aloo Chaat Salad",
              "product_id": 931,
              "quantity": 1,
              "total": "90.00",
          },
          {
              "id": 35,
              "name": "Aloo Jeera",
              "product_id": 1020,
              "quantity": 1,
              "total": "140.00",
          },
          {
              "id": 36,
              "name": "Banana Shake",
              "product_id": 963,
              "quantity": 1,
              "tax_class": "",
              "total": "140.00",
          }
      ],
    }
  ] 
  </code></pre>
  
  <p>myModel.dart</p>
  
  <pre><code>class OrderListModel {
  final int id;
  final String total;
  
   Map line_items = {};
  
    OrderListModel(this.id, this.total, this.line_items);
  
   }
  </code></pre>
  
  <p>my code for fetching the data</p>
  
  <pre><code> List&lt;OrderListModel&gt; myAllDatas = [];
  
  Future getDatas() async {
  String basicAuth = 'Basic ' +
      base64.encode(
          utf8.encode('${GlobalVar.consumerKey}:${GlobalVar.secretKey}'));
  
  var response = await http
      .get("${GlobalVar.url}wp-json/wc/v2/orders?customer=6", headers: {
    'Authorization': basicAuth,
    'Accept': 'application/json',
  });
  if (response.statusCode == 200) {
    String responseBody = response.body;
    var jsonBody = json.decode(responseBody);
    for (var data in jsonBody) // loop for fetching the orders
    {
      myAllDatas.add(new OrderListModel(data['id'], data['total'], 
  data['line_items'])); // how to place a loop so that i can fetch the items 
  inside the line_items parameter too?
    }
    setState(() {});
  } else {
    print(response.statusCode);
    print(response.body);
  }
  }
  </code></pre>
  
  <p>when I fetch the items of line_items i just want to fetch their names and seperate them by commas in a row.</p>