The syntax of Map.isEmpty property is:
bool isEmpty
This isEmpty property of Map whether there is no key/value pair in the map.
Map.isEmpty returns value of type bool
.
In this example,
map1
containing key-value pairs.isEmpty
property of map1
to check if it's empty. Since map1
is not empty, isEmpty
returns false
.void main() {
var map1 = {1: 'one', 2: 'two', 3: 'three'};
print('Is map1 empty? ${map1.isEmpty}');
}
Is map1 empty? false
In this example,
map2
.isEmpty
property of map2
to check if it's empty. Since map2
is empty, isEmpty
returns true
.void main() {
var map2 = {};
print('Is map2 empty? ${map2.isEmpty}');
}
Is map2 empty? true
In this example,
map3
containing key-value pairs.isEmpty
property of map3
to check if it's empty. Since map3
is not empty, isEmpty
returns false
.void main() {
var map3 = {'x': 'apple', 'y': 'banana', 'z': 'cherry'};
print('Is map3 empty? ${map3.isEmpty}');
}
Is map3 empty? false
In this Dart tutorial, we learned about isEmpty property of Map: the syntax and few working examples with output and detailed explanation for each example.