operator == method

  1. @override
bool operator ==(
  1. Object other
)
override

Determines whether this field is equal to another object.

Two fields are considered equal if:

Parameters:

  • other: The object to compare with this field.

Returns: true if the objects are equal according to the criteria above, false otherwise.

Example:

final field1 = JsonString('name')..value = 'John';
final field2 = JsonString('name')..value = 'John';
print(field1 == field2); // true

print(field1 == 'John'); // true (compares with rawValue)

Implementation

@override
bool operator ==(Object other) {
  if (identical(this, other)) return true;
  if (other is T) {
    return other == rawValue;
  }
  return other is JsonField<T> &&
      other.fieldName == fieldName &&
      other.rawValue == rawValue;
}