I have a List
of optional DateTimes
. So the List can actually have null
values inside. But now I need to remove all these null
-values, to get a List<DateTime
, instead of a List<DateTime?>
. How is that possible?
I tried it like this:
List<DateTime> timesOfDayNotNull = timesOfDay.where((time) => time != null).toList();
But this is giving me:
A value of type 'List<DateTime?>' can't be assigned to a variable of type 'List'.
What am I missing here? Any help is appreciated!