Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在颤振中将列表加载到下拉列表时出错 我有一个Api响应,比如_Flutter - Fatal编程技术网

Flutter 在颤振中将列表加载到下拉列表时出错 我有一个Api响应,比如

Flutter 在颤振中将列表加载到下拉列表时出错 我有一个Api响应,比如,flutter,Flutter,[{食品名称:value1},{食品名称:value2},{食品名称:value3},{食品名称:value4},{食品名称:value5}] 我在一个列表名称中得到了响应,但是当我尝试在下拉列表中显示此列表时,显示了一个错误,因为类型列表不是列表的子类型>,可能是我用错了方法。有人能帮忙吗?我建议您使用:PopupMenuButton Widget _typeTeachPopup() => PopupMenuButton<Food>( onSelected: _sel

[{食品名称:value1},{食品名称:value2},{食品名称:value3},{食品名称:value4},{食品名称:value5}]


我在一个列表名称中得到了响应,但是当我尝试在下拉列表中显示此列表时,显示了一个错误,因为类型列表不是列表的子类型>,可能是我用错了方法。有人能帮忙吗?

我建议您使用:PopupMenuButton

Widget _typeTeachPopup() => PopupMenuButton<Food>(
    onSelected: _selectFood,
    child: ListTile(
      title: Padding(
        padding: const EdgeInsets.only(top: 0, left: 0, right: 0),
        child: Card(
          elevation: 5,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8)),
        ),
      ),
    ),
    itemBuilder: (BuildContext context) {
      return _listFoods.map((Food choice) {
        return PopupMenuItem<TypeTeach>(
          value: choice,
          child: Text(choice.food_name),
        );
      }).toList();
    },
  );
结果如下:


列表不能直接提供给项目

物品接受

List<DropdownMenuItem<T>> items
你所拥有的是

List<Map<String,String>>

你能分享你用来显示dropdownchild:DropdownButton isExpanded:true,items:Food\u NameValue,value:field.value,onChanged:value的代码吗{field.didChangevalue;},我不能使用popup,因为它是另一个组件。我需要下拉按钮这正在工作,上面的错误是因为我将List变量放在了setstate中
var jsonList = [
    {"Food_name": "value1"},
    {"Food_name": "value2"},
    {"Food_name": "value3"},
    {"Food_name": "value4"},
    {"Food_name": "value5"}
  ];

......
......



child: DropdownButton(
            onChanged: (value){

            },
            items: jsonList.map((Map<String, String> value) {
              return new DropdownMenuItem(
                value: value["Food_name"],
                child: Text(value["Food_name"]),
              );
            }).toList(),
          ),
        ),