Dart Map isEmpty
Syntax & Examples
Syntax of Map.isEmpty
The syntax of Map.isEmpty property is:
 bool isEmpty This isEmpty property of Map whether there is no key/value pair in the map.
Return Type
Map.isEmpty returns value of type  bool.
✐ Examples
1 Check if a non-empty map is empty
In this example,
- We create a map named map1containing key-value pairs.
- We use the isEmptyproperty ofmap1to check if it's empty. Sincemap1is not empty,isEmptyreturnsfalse.
- We print the result to standard output.
Dart Program
void main() {
  var map1 = {1: 'one', 2: 'two', 3: 'three'};
  print('Is map1 empty? ${map1.isEmpty}');
}Output
Is map1 empty? false
2 Check if an empty map is empty
In this example,
- We create an empty map named map2.
- We use the isEmptyproperty ofmap2to check if it's empty. Sincemap2is empty,isEmptyreturnstrue.
- We print the result to standard output.
Dart Program
void main() {
  var map2 = {};
  print('Is map2 empty? ${map2.isEmpty}');
}Output
Is map2 empty? true
3 Check if another non-empty map is empty
In this example,
- We create a map named map3containing key-value pairs.
- We use the isEmptyproperty ofmap3to check if it's empty. Sincemap3is not empty,isEmptyreturnsfalse.
- We print the result to standard output.
Dart Program
void main() {
  var map3 = {'x': 'apple', 'y': 'banana', 'z': 'cherry'};
  print('Is map3 empty? ${map3.isEmpty}');
}Output
Is map3 empty? false
Summary
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.
