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

A record pattern is a declarative construct in Dart used to match, validate, and destructure Record types. It allows developers to extract positional and named fields from a record into distinct variables and perform inline type checking within pattern-matching contexts like `switch` statements, `if-case` clauses, and variable declarations.

## Syntax and Destructuring

Record patterns mirror the syntax of record expressions but operate in reverse, binding the extracted values to variables.

**Positional Fields**
Positional fields are matched strictly by their order within the record.

```dart theme={"dark"}
// Destructuring via variable declaration
var (a, b) = (10, 'Dart'); 
```

**Named Fields**
Named fields are matched by their explicit identifiers, regardless of their order. The syntax requires the field name followed by a colon and the variable to bind.

```dart theme={"dark"}
var (name: n, age: a) = (name: 'Alice', age: 30);
```

Dart provides a syntactic shorthand for named fields when the bound variable name matches the field name. Prefixing the identifier with a colon implicitly creates a variable of the same name.

```dart theme={"dark"}
var (:name, :age) = (name: 'Alice', age: 30);
// Equivalent to: var (name: name, age: age)
```

## Pattern Matching and Control Flow

When used in control flow structures, record patterns act as predicates that evaluate to a boolean while simultaneously binding variables if the match succeeds.

```dart theme={"dark"}
final record = (1, 'success');

if (record case (int code, String message)) {
  print(code);    // Binds 1 to `code`
  print(message); // Binds 'success' to `message`
}
```

## Advanced Mechanics

**Nested Subpatterns**
Record patterns can contain nested subpatterns, allowing for deep destructuring of complex, multi-layered data structures.

```dart theme={"dark"}
final complexRecord = (1, (x: 2, y: 3));

switch (complexRecord) {
  case (int id, (:var x, :var y)):
    print('$id, $x, $y');
}
```

**Wildcards**
The underscore `_` acts as a wildcard pattern to discard specific positional fields without binding them to a variable or allocating memory for them.

```dart theme={"dark"}
var (first, _, third) = (10, 20, 30);
```

**Type Checking and Casting**
Patterns can enforce type constraints on individual fields. If the runtime type of the record's field does not match the pattern's type annotation, the match fails safely without throwing an exception.

```dart theme={"dark"}
dynamic data = (1, 2.5);

switch (data) {
  case (int a, String b):
    // Match fails: Second field is double, not String
    break;
  case (int a, double b):
    // Match succeeds: Types align, variables 'a' and 'b' are bound
    break;
}
```

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