firstWhereOrNull method

T? firstWhereOrNull(
  1. bool test(
    1. T item
    )
)

Returns the first element for which the return value of test is true.

Null is returned if either Null itself or there is no element for which the return value of test is true.

testの返り値がtrueになる場合の最初の要素を返します。

自身がNullの場合かtestの返り値がtrueになる要素がない場合はNullが返されます。

Implementation

T? firstWhereOrNull(bool Function(T item) test) {
  if (this == null || isEmpty) {
    return null;
  }
  for (final element in this!) {
    if (test(element)) {
      return element;
    }
  }
  return null;
}