firstOrNull property

E? firstOrNull

First element or null if the collection is empty.

final first = [1, 2, 3, 4].firstOrNull; // 1
final emptyFirst = [].firstOrNull; // null

Implementation

E? get firstOrNull => isNotEmpty ? first : null;