I have a list like List<String?> list1 = ['a', 'b', null, 'c']
How do i get it List<String> list2 = ['a', 'b', 'c']
In Swift I can use compactMap and in Flutter is there any way like compactMap?
I have a list like List<String?> list1 = ['a', 'b', null, 'c']
How do i get it List<String> list2 = ['a', 'b', 'c']
In Swift I can use compactMap and in Flutter is there any way like compactMap?
4
Answers
or
You can try this short way:
Yes, there is an equivalent method in Flutter called
whereType()
which can be used to filter out null values from a list.You can try like :