Dart 3's if (value case Pattern) checks a value against a pattern and, when it matches, destructures the parts into fresh local variables for the then branch. A record pattern (int id, String name) matches a 2-record whose first field is an int and second is a String, binding id and name to the field values. If the pattern does not match, control falls through to the else branch and no bindings are introduced.

Program

Play the program to match an Object against a typed record pattern, destructure id and name, and print a labeled summary.

if_case.dart
void main() {
  Object data = (42, 'Ada');
  String label;
  if (data case (int id, String name)) {
    label = 'id=$id name=$name';
  } else {
    label = 'unknown';
  }
  print(label);
}
if-case `if (value case Pattern) { ... }` runs the `then` branch when `value` matches `Pattern` and skips to `else` otherwise. The pattern's bindings exist only inside the matched branch.
record pattern `(int id, String name)` matches a 2-record with field types `int` and `String`, then binds the field values to fresh locals `id` and `name`.
else branch When the pattern does not match, the `else` arm runs and the pattern's `id`/`name` are never bound. Both arms still assign `label`, so the variable is definitely initialized before `print`.