What is the map.isEmpty method in Dart?

The map.isEmpty function in Dart is used to check if a map is empty or not.

map.isEmpty returns true if the map is empty, i.e., no key-value pairs exist. Otherwise, it returns false.

The illustration below shows a visual representation of the map.isEmpty function:

Visual representation map.isEmpty function

Syntax

bool map_name.isEmpty

map_name is the name of the map.

Parameter

The map.isEmpty function does not require any parameters.

Return value

If the map is empty, the map.isEmpty function returns true.

Otherwise, it returns false.

Code

The following code shows how to use map.isEmpty function in Dart:

import 'dart:convert';
void main() {
var map_1 = new Map();
map_1 [1] = 'Tom';
map_1 [2] = 'Alsvin';
map_1 [3] = 'Eddie';
//map containg key value pairs
print("map_1 is empty: ${map_1.isEmpty}");
//map empty
var map_2 = new Map();
print("map_2 is empty: ${map_2.isEmpty}");
}