static Location fetchById(int id) {
List<Location> locations = Location.fetchAll();
for (var i = 0; i < locations.length; i++) {
if (locations[i].id == id) {
return locations[i];
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
// 如果条件不成立,则返回 null 当我尝试返回 null 或 false 时,它会给出错误“无法从方法 'fetchById' 返回类型为 'Null' 的值,因为它的返回类型为 '地点'。