The syntax of Map.isNotEmpty property is:
bool isNotEmpty
This isNotEmpty property of Map whether there is at least one key/value pair in the map.
Map.isNotEmpty returns value of type bool
.
In this example,
map1
with key/value pairs {'apple': 1, 'banana': 2, 'cherry': 3}.isNotEmpty
property.void main() {
Map<String, int> map1 = {'apple': 1, 'banana': 2, 'cherry': 3};
bool notEmpty = map1.isNotEmpty;
print('Map is not empty: $notEmpty');
}
Map is not empty: true
In this example,
map2
.isNotEmpty
property.void main() {
Map<int, String> map2 = {};
bool notEmpty = map2.isNotEmpty;
print('Map is not empty: $notEmpty');
}
Map is not empty: false
In this example,
map3
with a single key/value pair {'name': 'John'}.isNotEmpty
property.void main() {
Map<String, String> map3 = {'name': 'John'};
bool notEmpty = map3.isNotEmpty;
print('Map is not empty: $notEmpty');
}
Map is not empty: true
In this Dart tutorial, we learned about isNotEmpty property of Map: the syntax and few working examples with output and detailed explanation for each example.