在使用DropdownButton 做二级联动的时候,遇到了些问题,在此记录下
一级DropdownButton在onCange事件里需要改变本身的value还有二级DropdownButton的value,先1后2,多级联动依此类推
Container(
padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
height: 60.0,
child: DropdownButton(
isExpanded: true,
value: isCourseValue,
items: _CourseNameList.map((item){
return DropdownMenuItem(
child: Text(item),
value: item,
);
}).toList(),
onChanged: (value){
setState(() {
isCourseValue = value;//一级
isChapterValue = _ChapterNameList[isCourseValue][0]['title']; //二级
});
},
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
height: 60.0,
child: DropdownButton(
isExpanded: true,
value: isChapterValue,
items: _ChapterNameList[isCourseValue].map((item){
return DropdownMenuItem(
child: Text(item['title']),
value: item['title'],
);
}).toList(),
onChanged: (value){
},
),
),