【问题标题】:Flutter error: The argument type 'Color Function(String)' can't be assigned to the parameter type 'dynamic Function(dynamic)'颤振错误:参数类型“颜色函数(字符串)”不能分配给参数类型“动态函数(动态)”
【发布时间】:2021-12-05 20:23:53
【问题描述】:

我在这一行遇到错误The argument type 'Color Function(String)' can't be assigned to the parameter type 'dynamic Function(dynamic)'

final colors = data.map(getColorFromCode);

这里是data

late final data = [
    widget.result,
    widget.result2,
    widget.result3,
  ];

这里是函数getColorFromCode

Color getColorFromCode(String code) {
  if (code.contains('A') && code.contains('P')) return Colors.brown;
  if (code.contains('A') && code.contains('pp')) return Colors.black;
  if (code.contains('aa')) return Colors.white;
  return Colors.black;
}

如何解决这个错误?如果您需要任何其他详细信息,请随时询问。

【问题讨论】:

  • 能否分享一下widget.result、widget.result2和widget.result3的数据类型是什么

标签: android flutter dart mobile


【解决方案1】:

尝试将数据类型提供给您data 列表

喜欢这个

final List<String> data = [widget.result,
widget.result2,
widget.result3,];

【讨论】:

    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2021-12-24
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多