代码之家  ›  专栏  ›  技术社区  ›  fermoga

类型“List<void>”不是类型“List<DropdownMenuItem<Client>”的子类型

  •  0
  • fermoga  · 技术社区  · 6 年前

    我在打印一个文件中的内容时遇到了问题 DropdownButton 通过循环获取以下内容的API请求的结果:

    [{id: 1, nome: foo}, ...]
    

    这是它的代码。

    return _response.data.map<Client>((i) => Client.fromJson(i)).toList(); 
    

    [Instance of 'Client', ...]

    DropdownButton<Client>(
      onChanged: (client) => print(client),
      items: _controller.clients
          .map(
            (i) => print(i),
          )
          .toList(),
    

    但是 type 'List<void>' is not a subtype of type 'List<DropdownMenuItem<Client>>'

    1 回复  |  直到 6 年前
        1
  •  3
  •   Richard Heap    6 年前

    你在哪里印刷 i ,则需要返回 DropDownMenuItem

    例如:

      items: _controller.clients.map((e) => DropDownMenuItem(value: e, child: Text(e.nome))).toList(),