Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

dart - Flutter listview with Map instead of List

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

for a more detailed example check this out https://kodestat.gitbook.io/flutter/39-flutter-listviewbuilder-using-dart-maps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...