in new dart 2.12 with sound null safety, the best way is:
List<int?> a = [null,2,null];
final List<int> b = a.whereType<int>().toList();
in new dart 2.12 with sound null safety, the best way is:
List<int?> a = [null,2,null];
final List<int> b = a.whereType<int>().toList();