areSameImmutableCollection function

bool areSameImmutableCollection(
  1. ImmutableCollection? c1,
  2. ImmutableCollection? c2
)

While identical(collection1, collection2) will compare the collections by identity, areSameImmutableCollection(collection1, collection2) will compare them by type, and then by their internal state. Note this is practically as fast as identical, but will give less false negatives. So it is almost always recommended to use areSameImmutableCollection instead of identical.

Implementation

bool areSameImmutableCollection(ImmutableCollection? c1, ImmutableCollection? c2) {
  if (identical(c1, c2)) return true;
  if (c1 == null || c2 == null) return false;

  if (c1.runtimeType == c2.runtimeType) {
    return c1.same(c2);
  } else
    return false;
}