lastOrNull property
E?
get
lastOrNull
Last element or null
if the collection is empty.
final last = [1, 2, 3, 4].lastOrNull; // 4
final emptyLast = [].firstOrNull; // null
Implementation
E? get lastOrNull => isNotEmpty ? last : null;