我有一个列表(userData),它具有json解析的值;我想遍历列表,并剥离单个键/值对,以将列表减少为一组通用值。
userData列表具有json分析的数据,包括国家和大洲。我想生成一个唯一大洲的精简列表(并使用此精简列表创建一个动态列表 View )。请参阅下面的我的边/抽屉代码:
drawer: Drawer(
// Add a ListView to the drawer with unique continents
child: ListView.builder(
itemCount: userData == null ? 0 : userData.length,
itemBuilder: (BuildContext context, int index) {
for (var item in userData) {
continents.add(userData[item]['continent']);
}
continents.toSet().toList();
return Container(
width: 130,
alignment: Alignment.center,
child: Text(
"${continents[index]}", //unique continent should be here
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
),
));
},
),
),
在此先感谢您的协助!
最佳答案
将大洲分配回continents.toSet().toList();
喜欢
continents = continents.toSet().toList();
关于list - 从现有的json列表中提取唯一值以创建唯一的listview构建器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61612014/