> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Equality

The `==` operator in Dart is an equality relational operator used to evaluate whether two object references represent the same logical value. Unlike languages where `==` is strictly a primitive operation, in Dart, `==` is an instance method defined on the base `Object` class, allowing custom types to define their own structural equality semantics.

When the Dart runtime evaluates the expression `a == b`, it does not immediately invoke the method. Instead, it executes a predefined sequence to safely handle null references:

1. If `a` and `b` are both `null`, it returns `true`.
2. If only one of `a` or `b` is `null`, it returns `false`.
3. Otherwise, it invokes the method `a.==(b)` and returns the resulting boolean.

## Default Behavior

By default, all classes inherit the `==` implementation from `Object`. This default implementation evaluates strictly for *referential equality* (identity). It returns `true` only if both operands point to the exact same instance in memory, making it functionally equivalent to the top-level `identical(a, b)` function.

## Syntax and Signature

The operator is defined as a method with the following signature:

```dart theme={"dark"}
bool operator ==(Object other);
```

Because the parameter is of type `Object`, any implementation must perform type checking before accessing properties specific to the subclass.

## Overriding the Operator

To implement *value equality* (where two distinct instances are considered equal if their internal states match), a class must override the `==` operator.

When overriding `==`, the Dart language contract strictly dictates that the `hashCode` getter must also be overridden. If two objects evaluate to `true` via the `==` operator, they must produce the exact same integer when their `hashCode` is accessed. Failure to maintain this contract results in unpredictable behavior when the objects are used in hash-based collections like `Set` or `Map`.

```dart theme={"dark"}
class Entity {
  final int id;
  final String value;

  Entity(this.id, this.value);

  @override
  bool operator ==(Object other) {
    // 1. Check for referential equality (performance optimization)
    if (identical(this, other)) return true;

    // 2. Type check and cast
    // 3. Compare internal state
    return other is Entity &&
           other.id == id &&
           other.value == value;
  }

  @override
  int get hashCode => Object.hash(id, value);
}
```

## Key Characteristics

* **Symmetry:** `a == b` should always yield the same result as `b == a`.
* **Transitivity:** If `a == b` and `b == c`, then `a == c`.
* **Reflexivity:** `a == a` must always return `true`.
* **Non-nullable parameter:** The `other` parameter in the override signature is `Object`, not `Object?`, because Dart's implicit null-checking sequence guarantees that `null` will never be passed to the method.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
