Skip to main content
An enum constructor in Dart allows enumerated types to declare internal state and associate specific values with each enum constant. Because enum instances are inherently compile-time constants, all generative enum constructors must be declared as const, and all instance variables must be final.

Syntax and Structure

To define a constructor within an enum, the enum constants must be declared first, followed by a mandatory semicolon (;). The fields, constructors, and methods are declared after this semicolon.

Technical Constraints

  1. Instantiation: Enum constructors cannot be invoked externally. You cannot use new or const to create new instances of an enum outside of its internal declaration block.
  2. Immutability: All instance variables declared within the enum must be final.
  3. Const Requirement: All generative constructors must be prefixed with the const keyword.
  4. Ordering: The list of enum values must be the very first declaration inside the enum body.

Named and Factory Constructors

Dart enums support named constructors, initializer lists, and factory constructors, provided they adhere to the strict immutability and instantiation rules of the enum type.

Mixins and Interfaces

Enum constructors can initialize state required by implemented interfaces or applied mixins. When an enum implements an interface, the enum constructor is responsible for populating the final fields that satisfy the interface contract.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More