invertAttributes function

Attributes invertAttributes(
  1. Attributes? from,
  2. Attributes? to
)

Implementation

Attributes invertAttributes(Attributes? from, Attributes? to) {
  from ??= {};
  to ??= {};
  final attributes = Attributes.from({});

  // key in from but not in to, or value is different
  for (final entry in from.entries) {
    if ((!to.containsKey(entry.key) && entry.value != null) ||
        to[entry.key] != entry.value) {
      attributes[entry.key] = entry.value;
    }
  }

  // key in to but not in from, or value is different
  for (final entry in to.entries) {
    if (!from.containsKey(entry.key) && entry.value != null) {
      attributes[entry.key] = null;
    }
  }

  return attributes;
}