Flutter List.map()时获取索引值index

list =

List songListByUser = [
  {“score”: “A-“, “歌名”: “童年”, ‘id’: 1},
  {“score”: “C+”, “歌名”: “之乎者也”, ‘id’: 2},
  {“score”: “B+”, “歌名”: “野百合春天”, ‘id’: 3},
  {“score”: “D+”, “歌名”: “恋曲1990”, ‘id’: 4},
  {“score”: “D+”, “歌名”: “恋曲”, ‘id’: 5},
  {“score”: “B-“, “歌名”: “歌”, ‘id’: 6},
];
    return list
        .asMap()
        .keys
        .map((value) => ListTile(
              leading: Icon(
                Icons.music_note,
                color: Colors.green,
              ),
              trailing: Icon(Icons.keyboard_arrow_right),
              title: Text(list[value][‘歌名’].toString()),
              onTap: () {
                var mapstr = json.encode(list[value]).toString();
              },
            ))
        .toList();

发表评论