isEquivalentMap function

bool isEquivalentMap(
  1. Map? m1,
  2. Map? m2, {
  3. bool deep = false,
})

Returns true if m1 and m2 are equals.

deep IF true checks deeply collections values.

Implementation

bool isEquivalentMap(Map? m1, Map? m2, {bool deep = false}) {
  if (m1 == m2) return true;

  if (m1 == null) return false;
  if (m2 == null) return false;

  if (m1.length != m2.length) return false;

  var k1 = List.from(m1.keys);
  var k2 = List.from(m2.keys);

  if (!isEquivalentList(k1, k2, sort: true)) return false;

  for (var k in k1) {
    var v1 = m1[k];
    var v2 = m2[k];

    if (!isEquals(v1, v2, deep)) return false;
  }

  return true;
}