> ## 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 If-Case Statement

The `if-case` statement in Dart is a control flow construct introduced in Dart 3.0 that integrates pattern matching directly into conditional logic. It evaluates whether a given expression conforms to a specific pattern, conditionally executing the associated block and optionally destructuring the expression to bind extracted values to local variables within that block's lexical scope.

## Syntax

```dart theme={"dark"}
if (expression case pattern when condition) {
  // Executed if the expression matches the pattern AND the condition evaluates to true
} else if (expression case pattern) {
  // Chained pattern matching
} else {
  // Executed if no patterns match
}
```

## Core Mechanics

**1. Expression Evaluation and Matching**
The statement begins by evaluating the target `expression`. The result is then tested against the `pattern` following the `case` keyword. If the structure, type, or value of the expression satisfies the pattern's rules, the match is considered successful.

**2. Variable Binding and Destructuring**
Patterns can extract data from the matched expression. When a pattern includes variable declarations (using `var`, `final`, or explicit types), a successful match binds the corresponding sub-components of the expression to those variables.

```dart theme={"dark"}
final dynamic record = ('Dart', 3.0);

// Destructures the record and binds 'name' and 'version'
if (record case (String name, double version)) {
  print(name);    // Scope of 'name' is restricted to this block
  print(version); // Scope of 'version' is restricted to this block
}
```

**3. Guard Clauses (`when`)**
An `if-case` statement can include an optional `when` clause to evaluate an arbitrary boolean condition alongside the pattern match. The `when` condition is evaluated only if the initial pattern match succeeds, and it can reference variables bound during the destructuring phase. If the `when` condition evaluates to `false`, the entire `if-case` branch fails.

```dart theme={"dark"}
if (record case (String name, double version) when version >= 3.0) {
  // Executed only if the pattern matches AND the version is >= 3.0
}
```

## Supported Pattern Types in If-Case

The `pattern` in an `if-case` statement supports Dart's full pattern matching specification, including:

* **Constant Patterns:** Matches exact values.

```dart theme={"dark"}
if (value case 42) { ... }
```

* **Relational Patterns:** Uses operators (`<`, `>`, `<=`, `>=`, `==`, `!=`) to match against a value.

```dart theme={"dark"}
if (value case >= 10) { ... }
```

* **Logical Patterns:** Combines patterns using `&&` (AND) or `||` (OR).

```dart theme={"dark"}
if (value case >= 0 && <= 100) { ... }
```

* **Variable Patterns:** Matches a value and binds it to a new variable, optionally enforcing a type check.

```dart theme={"dark"}
if (value case String s) { ... } // Matches if value is a String, binds to 's'
```

* **Collection Patterns:** Matches the structure and elements of Lists or Maps.

```dart theme={"dark"}
if (json case {'status': 200, 'data': var payload}) { ... }
```

* **Object Patterns:** Matches against the properties of a class instance using getters.

```dart theme={"dark"}
if (exception case FormatException(message: var msg)) { ... }
```

* **Wildcard Patterns:** Matches a type or value without binding it to a variable, using the `_` identifier.

```dart theme={"dark"}
if (value case int _) { ... } // Matches any integer
```

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