how can i show the value of a list in a list?

This code worked for me:

Dart Code

final json = {
  "Orders": [
    {
      "OrderID": 208,
      "Remarks": null,
      "OrderCheckouts": {
        "OrderCheckoutID": 207,
        "ID": 208,
      },
    }
  ]
};

void main() {
  json['Orders'].forEach((e) {
    print((e['OrderCheckouts'] as Map<String, dynamic>)['OrderCheckoutID']);
    print((e['OrderCheckouts'] as Map<String, dynamic>)['ID']);
  });
}

Flutter Code

final json = {
  "Orders": [
    {
      "OrderID": 208,
      "Remarks": null,
      "OrderCheckouts": {
        "OrderCheckoutID": 207,
        "ID": 208,
      },
    }
  ]
};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final dataList = json['Orders'];

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: ListView(
          children: <Widget>[
            ...dataList
                .map<Widget>((e) => ListTile(
                    title: Text(
                        (e['OrderCheckouts'] as Map<String, dynamic>)['ID']
                            .toString())))
                .toList(),
          ],
        ),
      ),
    );
  }
}

Try it on DartPad

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top