I was working on a project and wanted to check if a list element was null. Example
List<int> i = [1, 2, 3];
print(i[1]); // this prints 2
But what if I want to print out a list element and if it does not exist print out a default number using dart null-aware. Example
List<int> i = [1, 2, 3];
print(i[10] ?? 15);
// Also tried
print(i?.elementAt(10) ?? 15);
I want it to print out 15 since the element at index 10 does not exist. Unfortunately, the above code gives me an error.
How can I check if a list element does not exist and return a default value