You need to enable JavaScript to run this app. Flutter在Row中添加DropdownButton时出现Incorrect use of ParentDataWidget错误如何解决
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.07 21:45:04