An enumerated type (enum) in Dart is a special class representing a fixed, predefined set of constant values. All enums automatically extend the coreDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Enum class. They are closed types, meaning they cannot be subclassed, implemented by other classes, or explicitly instantiated at runtime.
Basic Syntax
A simple enum is declared using theenum keyword followed by a comma-separated list of identifiers.
Intrinsic Properties
Every enum declaration implicitly generates several properties and methods:index: A zero-based integer representing the value’s position in the declaration.name: A string containing the exact identifier name of the enum value.values: A constantListcontaining all instances of the enum in declaration order.
Enhanced Enums
As of Dart 2.17, enums support class-like features. They can declare state, constructors, methods, and getters. To define an enhanced enum, the following technical constraints apply:- Instance variables must be
final. - All generative constructors must be
const. - Factory constructors can only return one of the predefined, fixed enum instances.
- The list of enum instances must be declared first, and if the enum contains members, the list must terminate with a semicolon (
;).
Mixins and Interfaces
While enums cannot extend other classes (as they already extendEnum), they can use mixins (with) and implement interfaces (implements).
Technical Constraints
When working with Dart enums, the compiler enforces strict limitations to guarantee their constant, finite nature:- You cannot use the
neworconstkeywords to instantiate an enum outside of its internal declaration. - You cannot override the
index,hashCode, or the equality operator (==). - The
valuesproperty is reserved; you cannot declare a member namedvalueswithin an enum.
Master Dart with Deep Grasping Methodology!Learn More





