Enum class. They are implicitly final and cannot be subclassed, implemented, or mixed in. Each value defined in an enum is a compile-time constant instance of that enum class.
Basic Declaration
The simplest enum declaration defines the type name and a comma-separated list of values.Members and Properties
Enums possess both instance properties inherited from theEnum base class and static members generated by the compiler.
Instance Properties (Inherited):
index: A zero-based integer representing the value’s ordinal position in the declaration.name: A string containing the source identifier of the value.
values: A constant list containing all enum instances in declaration order. This list is a compile-time constant and is valid for use inconstcontexts.
Enhanced Enums
Dart enums function as classes and can declare fields, methods, and constructors. Syntax Requirements:- Fields: All instance variables must be
final. - Constructors: Generative constructors must be
const. Factory constructors can be non-const. - Syntax: The list of enum values must be declared first and terminated with a semicolon (
;) if additional members follow.
Interfaces and Mixins
While enums cannot extend other classes (as they already extendEnum), they can implement interfaces and apply mixins.
Exhaustiveness Checking
Dart performs exhaustiveness checking when enums are used inswitch statements or expressions. If the switch logic does not cover every defined enum value and lacks a default case, the compiler emits an error.
Comparison
Enum values are canonical instances. Comparison is performed by identity, meaning two references to the same enum value are considered equal.Master Dart with Deep Grasping Methodology!Learn More





