To check if a list is not empty in Dart, you can use the isNotEmpty
property of the List
class.
In this example,
myList
with some elements.myList
is not empty by using the isNotEmpty
property.void main() {
List<int> myList = [1, 2, 3];
if (myList.isNotEmpty) {
print('The list is not empty');
} else {
print('The list is empty');
}
}
The list is not empty
In this example,
emptyList
without any elements.emptyList
is not empty by using the isNotEmpty
property.void main() {
List<int> emptyList = [];
if (emptyList.isNotEmpty) {
print('The list is not empty');
} else {
print('The list is empty');
}
}
The list is empty
In this tutorial, we learned How to check if a List is Not Empty in Dart language with well detailed examples.