繁体   English   中英

错误使用 ParentDataWidget | Flutter | 下拉按钮

[英]Incorrect use of ParentDataWidget | Flutter | DropDown Button

尝试在行小部件中添加 DropdownButton 时出现错误使用父数据小部件不正确

在这里,我在 Row Widget 中添加了两个元素,Text Widget 和 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

这是 DropDownList Function 返回一个 DropdownButton

  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(),
    );
  }


这是确切错误消息的屏幕截图:

[Error Message][1]
[Actual Representation of widget][2]


  [1]: https://i.stack.imgur.com/w9QsX.png

  [2]: https://i.stack.imgur.com/ALAOT.png

您应该定义您的列表类型。

 items: sourceNameList.map((String value) {
                          return new DropdownMenuItem(
                            value: value,
                            child: new Text(
                              value.name,
                            )
                          );
                        }).toList(),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM