I was wondering if there is a way to access the first element of a list in dart if an element exists at all, and otherwise return null.
First, I thought this would do the job:
final firstElement = myList?.first;
This works if myList is null or myList.length > 0, but would give me an error if myList is an empty List.
I guess I could do something like this:
final firstElement = (myList?.length ?? 0) > 0 ? myList.first : null;
But I was wondering if there is a simpler way of doing what I'm trying to do out there.