how to get the index of first occurence of a specific item in a list flutter code example

Example 1: flutter indexwhere examples

/// Find a person in the list using indexWhere method.
void findPersonUsingIndexWhere(List<Person> people,
    String personName) {
  // Find the index of person. If not found, index = -1
  final index = people.indexWhere((element) =>
        element.name == personName);
  if (index >= 0) {
    print('Using indexWhere: ${people[index]}');
  }
}

Example 2: flutter count list

var comments = <Comment>[...];
var count = comments.where((c) => c.product_id == someProductId).toList().length;

Tags:

Misc Example