lastOrNull property

E? get lastOrNull

Last element or null if the collection is empty.

var last = [1, 2, 3, 4].lastOrNull; // 4
var emptyLast = [].firstOrNull; // null

Implementation

E? get lastOrNull => isNotEmpty ? last : null;