0Pricing
Dart Academy · Lesson

Declaring and Using Plain Enums

Represent a fixed set of values.

Declaring and Using Plain Enums is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

A Fixed Set of Choices

Some values only ever come from a short, known list, like the days of the week. An enum names that fixed set of choices for you.

Declaring an Enum

You write enum, a name, then the allowed values inside braces. Each value is one constant member of that type.

enum Direction { north, south, east, west }

Why Not Just Use Strings

Plain text like "north" can be misspelled and Dart will not warn you. An enum makes typos impossible by limiting the values.

Reading an Enum Value

Access a member with the enum name, a dot, then the value. The result is a real typed value, not just a label.

var heading = Direction.north;

Enums Have Their Own Type

The variable heading above has the type Direction. Dart will reject any value that is not one of the four members.

Direction d = Direction.east;

Comparing Enum Values

You compare enum members with the usual equality operator. It is true only when both sides are the exact same member.

print(Direction.north == Direction.north); // true

Enums in Conditions

Because comparison is clean, enums read naturally inside an if. Your intent is obvious to anyone scanning the code.

if (d == Direction.east) print("Turning east");

Printing an Enum

Printing a member shows the type and value together, like Direction.north. It is a readable label, handy while debugging. 🧭

print(Direction.north); // Direction.north

A Real-World Example

Enums shine for status: an order might be pending, shipped, or delivered. The type makes every possible state explicit.

enum Status { pending, shipped, delivered }

Convention: lowerCamelCase Members

By Dart style, enum members use lowerCamelCase, like inProgress. This keeps your enums consistent with the wider ecosystem.

enum Phase { notStarted, inProgress, done }

When an Enum Fits

Reach for an enum whenever a value is one of a small, fixed group. It is clearer and safer than loose strings or numbers.

Quick Check

Why prefer an enum over a plain String for a status value?

Recap: Plain Enums

You learned an enum names a fixed set of typed choices, read with dot syntax and compared with equality. It beats loose strings. 🎉

Frequently asked questions

Is the “Declaring and Using Plain Enums” lesson free?

Yes — the full text of “Declaring and Using Plain Enums” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.

What will I learn in “Declaring and Using Plain Enums”?

Represent a fixed set of values. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Dart Academy?

No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Declaring and Using Plain Enums” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Dart Academy lesson?

Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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