从flutter中的第二个索引数据中检索数据

ccgok5k5  于 2023-01-09  发布在  Flutter
关注(0)|答案(1)|浏览(83)

enter image description here这是列表图像
我想从其中访问内容密钥。
enter image description here已尝试上面的代码

tf7tbtn2

tf7tbtn21#

请尝试此代码:

class MyPage extends StatelessWidget {
  MyPage({super.key});
  final coumputerData = [
    {
      "maintopic": "Computer Software",
      "subtopic": [
        {
          "topic": "introduction",
          "content": "owhrfiuwbef iosevibskvsuibvisnesd nisudvusvc",
        }
      ]
    },
    {
      "maintopic": "Computer",
      "subtopic": [
        {
          "topic": "introduction",
          "content": "owhrfic",
        }
      ]
    }
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        shrinkWrap: true,
        physics: const ClampingScrollPhysics(),
        itemCount: coumputerData.length,
        itemBuilder: ((context, index) {
          final List<Map> arrSubTopic =
              coumputerData[index]['subtopic'] as List<Map>;
          return Column(
            children: [
              Container(
                height: 40,
                color: Colors.red,
                child: Row(
                  children: [
                    Expanded(
                      child: Center(
                        child:
                            Text(coumputerData[index]['maintopic'] as String),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                color: Colors.amber,
                child: ListView.builder(
                  shrinkWrap: true,
                  physics: const ClampingScrollPhysics(),
                  itemCount: arrSubTopic.length,
                  itemBuilder: ((context, inx) {
                    return Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(arrSubTopic[inx]['topic'] as String),
                          Text(arrSubTopic[inx]['content'] as String)
                        ],
                      ),
                    );
                  }),
                ),
              )
            ],
          );
        }),
      ),
    );
  }
}

您也可以使用模型类访问您的数据。要生成模型类,您可以使用此website

相关问题