【发布时间】:2021-06-05 00:11:38
【问题描述】:
这个函数
List<int> _calculateTrips() {
List<int> trips = [];
trips = List.generate(
30,
(index) {
var counter = 0;
var aDay = DateTime.now().subtract(Duration(days: index));
for (var aWalk in walks) {
if ((aDay.month == aWalk.month) && (aDay.day == aWalk.day)) {
counter++;
}
}
trips.add(counter);
},
);
return trips;
}
创建错误The body might complete normally, causing null to be returned, but the return type is a potentially non-nullable type.Try adding either a return or a throw statement at the end. 我有点难以理解该消息,因为(a)我认为我在函数开头初始化了列表,并且(b)我认为我最后有一个 return 语句。
【问题讨论】: