颤振如何显示列表中的列表值

时间:2020-10-28 14:11:39

标签: flutter

我有类似这样的数据,我想在文本小部件中显示ID

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

我现在像这样OrderID正在打印posts.data[position]['OrderID'],现在我想在ID中打印OrderCheckouts,但是我被困在这个:DI试图但不能知道我该怎么做。

我也这样尝试post.data [position] ['CustomerOrders'] ['Name'],但不起作用

1 个答案:

答案 0 :(得分:2)

此代码对我有用:

飞镖代码

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(),
          ],
        ),
      ),
    );
  }
}

Flutter代码

@SpringBootTest

Try it on DartPad