【问题标题】:Flutter function error: Column's children must not contain any null values, but a null value was found at index 1Flutter 函数错误:列的子项不得包含任何空值,但在索引 1 处找到空值
【发布时间】:2020-03-08 06:00:35
【问题描述】:

我在flutter中将下拉列表分离到单独的方法后,调试器返回以下错误:

“列的子项不得包含任何空值,但在索引 1 处找到空值”

这是我不得不单独方法_actionDropdown()的代码:

  _actionDropdown() {
DropdownButton<String>(
            value: actionValue,
            icon: Icon(Icons.arrow_downward),
            iconSize: 24,
            elevation: 16,
            style: TextStyle(
              color: Colors.deepPurple
            ),
            underline: Container(
              height: 2,
              color: Colors.deepPurpleAccent,
            ),
            onChanged: (String newValue) {
              setState(() {
                dropdownValue = newValue;
                // if(dropdownValue == 'Move to...') {
                //   return Text('add chips for folders here');
                // } else if(dropdownValue == 'Label as...') {
                //     return Text('add chips for labels here');
                // }
              });
            },
            items: <String>['Archive', 'Delete', 'Move To...', 'Label as...']
              .map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              })
              .toList(),
          );

}

DropdownButton&lt;String&gt; 的这段代码作为列子项工作,但当我将 _actionDropdown 作为子项添加分隔方法时却不行。我错过了什么?

【问题讨论】:

  • “将下拉列表分离为单独的方法”是什么意思?
  • 您可能错过了一个“return”关键字?
  • @Kahou 下拉列表是上面代码中的“dropdownButton”
  • @brendan 你会在哪里添加另一个退货声明?
  • 返回下拉按钮?

标签: flutter dart


【解决方案1】:

正如@brendan 建议的那样,您忘记添加 return 关键字。

 _actionDropdown() {
 return DropdownButton<String>( // return added here
            value: actionValue,

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2021-06-10
    • 2021-10-29
    • 2020-12-02
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 2020-03-04
    相关资源
    最近更新 更多