firstWhereOrNull<T> static method

T? firstWhereOrNull<T>(
  1. Iterable<T> values,
  2. bool test(
    1. T item
    )
)

After Dart 2.12, firstWhere can be a non-nullable return value. Instead of an extension, a predictable static method is used instead.

From https://github.com/dart-lang/collection/blob/master/lib/src/iterable_extensions.dart to avoid importing a package for a single function.

Implementation

static T? firstWhereOrNull<T>(Iterable<T> values, bool Function(T item) test) {
  for (var item in values) {
    if (test(item)) return item;
  }
  return null;
}