我实际上正在努力理解这种类型错误。
任何人都有一个想法如何纠正代码?感谢
CheckIn checkin1 = new CheckIn(location1, dt);
CheckInMonths checkInMonths = new CheckInMonths();
错误发生在此行, checkin1错误:
checkInMonths.months.putIfAbsent(month,checkin1);
其他代码:
class CheckIn {
Location location;
DateTime dateTime;
CheckIn(this.location, this.dateTime);
}
class CheckInMonths {
Map<Month, CheckIn> months = new Map();
}
答案 0 :(得分:2)
putIfAbsent
的第二个参数必须是返回CheckIn值的函数(https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:core.Map#id_putIfAbsent)
checkInMonths.months.putIfAbsent(month, () => checkin1);