Skip to content
Justice Tech School

Dart Switch

switch compares a value to cases. Modern Dart has switch expressions with => and pattern matching.

Example
void main() {
  var day = 3;
  var name = switch (day) { 1 => "Mon", 2 => "Tue", 3 => "Wed", _ => "Other" };
  print(name);
}

Exercise

Fallback in an expression.

switch (x) {  => 0 }

Quiz Test

What does _ mean in a switch expression?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.