【问题标题】:The argument type 'Iterable>' can't be assigned to the parameter type 'List'参数类型“Iterable>”不能分配给参数类型“List”
【发布时间】:2020-05-28 23:54:36
【问题描述】:

我尝试按以下代码对列表进行分组

var b = groupBy(value[index],(ABC item) => item.id);
dropDownMenuItem = buildDropDownMenuItems(b.values);

b 现在是Map<String, List<ABC>>

buildDropDownMenuItems,我想通过List<ABC>

List<DropdownMenuItem<ABC>> buildDropDownMenuItems(List<ABC> asset) {
  ......
  }

错误

参数类型“Iterable>”不能分配给 参数类型“列表”。

【问题讨论】:

  • 你也可以添加完整的控制台日志吗?
  • @CrazyLazyCat 没有登录控制台,只是buildDropDownMenuItems(b.values);下的一条红线。
  • 好的,改成buildDropDownMenuItems(b.values.toList());
  • @CrazyLazyCat The argument type 'List&lt;List&lt;ABC&gt;&gt;' can't be assigned to the parameter type 'List&lt;ABC&gt;'.dart(argument_type_not_assignable)
  • 您对Map&lt;key, value&gt;().values 感到困惑。我觉得你必须做这样的事情buildDropDownMenuItems(b["Group Name"]);

标签: list flutter dart group-by


【解决方案1】:

在您的values 上尝试expand 功能

var b = groupBy(value[index],(ABC item) => item.id);
dropDownMenuItem = buildDropDownMenuItems(b.values.expand((item) => item).toList());

但显然它在group by 函数之前为您提供了相同的未分组列表。可能您想将其用作b["your key"]

var b = groupBy(value[index],(ABC item) => item.id);
dropDownMenuItem = buildDropDownMenuItems(b["your key"]);

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 2021-11-13
    • 2021-12-24
    • 2021-07-25
    • 2021-07-10
    • 2019-10-05
    • 2021-11-23
    • 2021-07-04
    • 2021-12-10
    相关资源
    最近更新 更多