我已经下拉了体育列表,每当用户从下拉列表中选择体育项目时,所选的体育项目将存储在Map中,并将在ListView中更新,以便用户能够看到所选的体育项目。我能够在地图中添加体育,同时从下拉菜单中选择并得到所选运动的正确长度,但我必须在ListView中显示,当我试图在索引处获得体育名称时,它显示为空值。如何在列表查看项中从地图中显示选定的体育项目
Map<String,Sports> _selectedSports = new Map<String,Sports>();
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _selectedSports!=null?_selectedSports.length:0, itemBuilder:
(BuildContext ctxt, int index) {return new Text('Sports
${_selectedSports[index].names}');})// showing null here
${_selectedSports['1'].names}// but it is returning value by key我正在从下拉列表的onChanged中成功地在地图中添加项目
void changedDropDownSportsItems(Sports selectedSports) {
print("Selected Sport ${selectedSports.names}");
_selectedSports[selectedSports.id.toString()] = selectedSports;
setState(() {
_currentSportsBar = selectedSports;
_selectedSports;
print("Selected Sports size ${_selectedSports.length}");
});
}当我试图按键获得值时,它返回名称,但从索引中返回null。
发布于 2019-06-03 10:21:39
更新尝试如下
Column(
children: _selectedSports.values
.toList()
.map((value) => Text('Sports ${value.names}'))
.toList())https://stackoverflow.com/questions/56424257
复制相似问题