isDifferent static method

bool isDifferent(
  1. dynamic oldValue,
  2. dynamic newValue
)

Checks if two values are different, handling nested maps and lists

Implementation

static bool isDifferent(dynamic oldValue, dynamic newValue) {
  // Different types
  if (oldValue.runtimeType != newValue.runtimeType) {
    return true;
  }

  // Handle nested maps
  if (oldValue is Map && newValue is Map) {
    // Different lengths
    if (oldValue.length != newValue.length) {
      return true;
    }

    // Check each key-value pair
    for (final key in oldValue.keys) {
      if (!newValue.containsKey(key) ||
          isDifferent(oldValue[key], newValue[key])) {
        return true;
      }
    }

    // Check if newMap has keys not in oldMap
    for (final key in newValue.keys) {
      if (!oldValue.containsKey(key)) {
        return true;
      }
    }

    return false;
  }

  // Handle lists
  if (oldValue is List && newValue is List) {
    if (oldValue.length != newValue.length) {
      return true;
    }

    for (var i = 0; i < oldValue.length; i++) {
      if (isDifferent(oldValue[i], newValue[i])) {
        return true;
      }
    }

    return false;
  }

  // Simple value comparison
  return oldValue != newValue;
}