var or final) must be applied to the entire pattern at the top level. Individual elements within the declaration cannot have their own var, final, or explicit type annotations.
switch cases or if-case statements), variable patterns can be defined individually on specific elements using var, final, or an explicit type annotation.
- Irrefutable (
var/final): Patterns declared without an explicit type are irrefutable. They unconditionally match any value passed to them. - Refutable (Explicitly Typed): When an explicit type is provided (e.g.,
String s), the variable pattern implicitly functions as a type test pattern. It becomes refutable and will only match if the runtime type of the evaluated value is a subtype of the specified type. If the type test fails, the pattern rejects the value, and the variable is not bound.
- Pattern variable declarations: The variable is available in the surrounding block scope.
- Switch cases and
if-casestatements: The variable is available within the optionalwhenguard clause and the corresponding case body. It is not available in subsequent cases.
||), Dart enforces strict binding rules. The variable must be declared in all branches of the OR pattern, and it must possess the exact same identifier and static type in every branch. This ensures the variable is safely initialized regardless of which branch succeeds.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





