Flutter在Row中添加DropdownButton时出现Incorrect use of ParentDataWidget错误如何解决
问题场景
在Row组件内部添加DropdownButton时,触发Incorrect use of ParentDataWidget错误。
当前Row组件内共放置两个子元素:Text组件、DropdownButton相关实现逻辑,具体布局代码如下:
Row( children: <Widget>[ Expanded(flex: 1, child: Text(' Source :')), Expanded( flex: 4, child: FutureBuilder<SourceData>( future: sourceData, builder: (context, snapshot) { return sourceDropDownList(snapshot.data.sources); return CircularProgressIndicator(); }) ) // FutureBuilder ], ), // Row
返回DropdownButton的sourceDropDownList函数具体实现代码如下:
Widget sourceDropDownList(List<Sources> sources) { var sourceNameList = List<String>(); for (var i = 0; i < sources.length; i++) { sourceNameList.add(sources[i].name); } return DropdownButton<String>( value: dropdownValue, onChanged: (String newValue) { setState(() { dropdownValue = newValue; }); }, items: sourceNameList.map((value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), ); }
问题相关材料
- 包含两类异常佐证内容:运行时报错信息截图、组件实际渲染异常的展示效果截图
内容的提问来源于stack exchange,提问作者Aman Pandey
相关产品推荐
相关产品推荐

