繁体   English   中英

Flutter 错误:无法将参数类型“Color Function(String)”分配给参数类型“dynamic Function(dynamic)”

[英]Flutter error: The argument type 'Color Function(String)' can't be assigned to the parameter type 'dynamic Function(dynamic)'

我有错误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;
}

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

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

像这样

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM