用Map而不是List的Flutter ListView [英] Flutter listview with Map instead of List
问题描述
我试图在 ListView.builder
小部件中显示 HashMap
值的内容。有没有办法做到这一点?使用 List
,我可以简单地使用索引,但是如何使用 HashMap
而不使用列出
吗?
地图的键是字符串,值是要显示数据的地图。
I'm trying to display the contents of my HashMap
values in a ListView.builder
widget. Is there a way to do this? With a List
I could simply use the index, but how would that work with a HashMap
without making a List
out of it?
The keys of the map are strings and the values are maps with the data to display.
推荐答案
有点晚了,但您也可以尝试一下。
地图值= snapshot.data;
Its a little late but You could also try this. Map values = snapshot.data;
return new ListView.builder(
itemCount: values.length,
itemBuilder: (BuildContext context, int index) {
String key = values.keys.elementAt(index);
return new Column(
children: <Widget>[
new ListTile(
title: new Text("$key"),
subtitle: new Text("${values[key]}"),
),
new Divider(
height: 2.0,
),
],
);
},
);
有关详细示例,请查看此
https://kodestat.gitbook.io/flutter/39-flutter-listviewbuilder-using-dart-maps
for a more detailed example check this out https://kodestat.gitbook.io/flutter/39-flutter-listviewbuilder-using-dart-maps
这篇关于用Map而不是List的Flutter ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!