mapEquals function
Checks if two maps are equal by comparing their keys and values.
Returns true
if map1
and map2
are equal, or false
otherwise.
If both map1
and map2
are null
, they are considered equal.
If either map1
or map2
is null
, they are considered unequal.
If the lengths of map1
and map2
are different, they are considered unequal.
For each key in map1
, if map2
does not contain the key or the values
associated with the key are different, they are considered unequal.
Implementation
bool mapEquals(Map<dynamic, dynamic>? map1, Map<dynamic, dynamic>? map2) {
if (map1 == map2) return true;
if (map1 == null || map2 == null) return false;
if (map1.length != map2.length) return false;
for (final key in map1.keys) {
if (!map2.containsKey(key) || map1[key] != map2[key]) {
return false;
}
}
return true;
}