The wildcard pattern (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.
_) is a non-binding pattern that successfully matches any value or type without assigning it to a variable. It acts as an explicit discard mechanism during pattern matching, destructuring, and variable declaration, signaling to the compiler that the matched data is intentionally dropped from the lexical scope.
Syntax and Mechanics
The wildcard pattern is represented by a single underscore (_). Because it does not bind to a variable, it can be used multiple times within the same pattern or scope without causing naming collisions.
Standalone Wildcard
When used on its own, the wildcard matches any value. Inswitch statements or expressions, it functions as the exhaustive catch-all (replacing the legacy default keyword).
Typed Wildcard
The wildcard can be prefixed with a type annotation. This creates a pattern that matches only if the value is of the specified type, but still discards the value itself.Destructuring Collections
In list, map, and record patterns, the wildcard is used to structurally match the shape of the collection while selectively ignoring specific positional or named elements.Technical Characteristics
- Non-Binding Nature: In pattern contexts (introduced in Dart 3.0),
_is strictly a structural placeholder. Attempting to read or reference_as a variable after it has been used in a pattern results in a compile-time error. - Multiplicity: Unlike standard variable identifiers,
_can be repeated infinitely within the same destructuring assignment or pattern match. - Logical Operators: The wildcard is frequently combined with logical-or (
|) and logical-and (&) patterns to satisfy structural requirements without polluting the local scope with unused variables.
Master Dart with Deep Grasping Methodology!Learn More





