我有这个代码有效。它循环遍历一个对象列表,并获取对象的一个属性存在于另一个对象列表中的所有对象。
List<WatchedGame> watching = List<WatchedGame>();
for (WatchedGame watchedGame in watchedGames.list) {
if (week.games.contains(watchedGame))
watching.add(watchedGame);
}
好像我可以简化这个代码。
List<WatchedGame> watching = watchedGames.list.where((watchedGame) {
week.games.contains(watchedGame.game);
});
但是我得到了这个例外。
type 'WhereIterable<WatchedGame>' is not a subtype of type 'List<WatchedGame>'
在最后投掷toList
电话:
List<T> newList = list.where(condition).toList();