flutter list where all code example

Example 1: find common elements in two flutter

void main() {
  List l1 = [1, 2, 3, 55, 7, 99, 21];
  List l2 = [1, 4, 7, 65, 99, 20, 21];
  List l3 = [0, 2, 6, 7, 21, 99, 26];

  l1.removeWhere((item) => !l2.contains(item));
  l1.removeWhere((item) => !l3.contains(item));

  print(l1);
}

Example 2: get single element from list in dart

var firstList = [1,2,3,4,5,6]; print(firstList.firstWhere((i) => i < 4)); // 1  var sList = ['one', 'two', 'three', 'four']; print(sList.firstWhere((i) => i.length > 3)); // three

Tags:

Dart Example