> ## 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 Relational Pattern

A relational pattern compares a matched value against a given constant using standard relational operators. It evaluates to `true` if the boolean result of applying the operator between the matched value and the constant expression is `true`.

## Syntax

```dart theme={"dark"}
<relational_operator> <constant_expression>
```

The `<relational_operator>` can be any of the following: `==`, `!=`, `<`, `>`, `<=`, or `>=`.

The `<constant_expression>` must evaluate to a compile-time constant.

## Mechanics and Behavior

1. **Constant Requirement:** The operand on the right side of the relational operator must be a compile-time constant. Variables evaluated at runtime are not permitted.
2. **Static Type Safety:** The Dart analyzer statically verifies that the relational operator is defined for the static type of the matched value. If the matched value is of a type that does not implement the specified operator, a compile-time error occurs.
3. **Evaluation Order:** When matching a value `v` against a relational pattern `op c`, the expression evaluates exactly as `v op c`.
4. **Exhaustiveness Checking:** Dart's exhaustiveness checker does not reason about the mathematical completeness of relational patterns. Even if a set of relational patterns logically covers all possible values (e.g., `< 0`, `== 0`, `> 0`), the compiler cannot deduce this. A default case (such as `_`) is strictly required in switch expressions utilizing relational patterns to prevent a `non_exhaustive_switch_expression` compile-time error.

## Code Examples

**In a Switch Expression:**

```dart theme={"dark"}
String evaluateMagnitude(int value) => switch (value) {
  < 0  => 'Negative',
  == 0 => 'Zero',
  > 0  => 'Positive',
  _    => 'Unreachable', // Required because the compiler does not evaluate relational logic for exhaustiveness
};
```

**Combined with Logical Patterns:**
Relational patterns are frequently combined with logical AND (`&&`) or logical OR (`||`) patterns to define bounded ranges.

```dart theme={"dark"}
bool isValidPercentage(int value) {
  return switch (value) {
    >= 0 && <= 100 => true,
    _ => false,
  };
}
```

**In an `if-case` Statement:**

```dart theme={"dark"}
void checkThreshold(double temperature) {
  if (temperature case >= 100.0) {
    print('Threshold met.');
  }
}
```

## Operator Overloading

Relational patterns respect custom operator overloading. If a user-defined class overrides a relational operator (such as `operator >`), a relational pattern can be applied to instances of that class, provided the right-hand operand is a valid constant of the expected type.

```dart theme={"dark"}
class Measurement {
  final int value;
  const Measurement(this.value);

  bool operator >(Measurement other) => this.value > other.value;
}

void compareMeasurements(Measurement m) {
  // The right-hand side must be a const instantiation
  if (m case > const Measurement(50)) {
    print('Exceeds threshold');
  }
}
```

<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>
