数据清单如下:
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},
];
返回为List<Widget>
List<Widget> _listViewByUser() {
return songListByUser
.map((f) => ListTile(
leading: Icon(
Icons.music_note,
color: Colors.green,
),
trailing: Icon(Icons.keyboard_arrow_right),
title: Text(f[‘歌名’].toString() + ‘(‘ + f[‘score’].toString() + ‘)’),
onTap: () => print(f[‘id’].toString()),
))
.toList();
}
在需要使用的地方
children: _listViewByUser(),