firstWhereOrNull method

E? firstWhereOrNull(
  1. bool test(
    1. E
    )
)

firstWhereOrNull

Tries to find an element E using the given condition else it will return null.

Usage:

List<String> items = ["Hello", "World"];
String? word = items.firstWhereOrNull((String element) => element == "Hello")

Implementation

E? firstWhereOrNull(bool Function(E) test) {
  for (final E element in this) {
    if (test(element)) return element;
  }
  return null;
}