firstWhereOrDefault method

T? firstWhereOrDefault(
  1. bool test(
    1. T
    )
)

a firstWhere implementation that allows for a nullable return type when the lists elements are non-nullable

Implementation

T? firstWhereOrDefault(bool Function(T) test) {
  final list = where((element) => test(element)).toList();

  if (list.isNotEmpty) {
    return list.first;
  }

  return null;
}