0Pricing
Dart Academy · Lesson

switch Over Enums Exhaustively

Handle every case the compiler checks.

switch Loves Enums

When a value is one of a few choices, switch handles each case cleanly. Enums and switch are a natural pair.

A Basic switch

List one case per enum member and the code to run for it. Dart matches the value to its case and runs that branch.

switch (status) {
  case Status.pending: print("Waiting");
}

All lessons in this course

  1. Declaring and Using Plain Enums
  2. Enum Values, index, and name
  3. Enhanced Enums With Fields and Methods
  4. switch Over Enums Exhaustively
← Back to Dart Academy