An enum value in Dart is a compile-time constant instance of an enumerated type (Documentation 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). Each value represents a distinct, named, and immutable singleton object within the closed set defined by the enum declaration. Because they are singletons, enum values are compared by identity, and the Dart compiler explicitly prohibits overriding their == operator or hashCode.
Every enum type automatically extends the Enum class. Consequently, each enum value possesses two default properties:
index: A zero-based integer representing the value’s position in the declaration order.name: A string representation of the value’s exact identifier.
Enhanced Enum Values
As of Dart 2.17, enum values can encapsulate custom state and behavior. In an enhanced enum, each value declaration acts as an invocation of a constant constructor. When defining enhanced enum values, the following technical constraints apply:- All instance variables must be declared
final. - All generative constructors must be
const. - The list of enum values must be terminated with a semicolon (
;) before declaring fields, constructors, or methods. - The enum type cannot be subclassed, implemented, or explicitly instantiated anywhere using
neworconst. The only valid instances are the explicitly declared enum values themselves.
The values Constant
The Dart compiler automatically generates a static values property for every enum type. This property returns an unmodifiable List containing all the enum values in the exact order they were declared.
Value Resolution by Name
You can resolve a specific enum value from a string using the.byName() method provided by the enum’s values iterable (e.g., <EnumName>.values.byName()). This method performs an exact string match against the name property of the enum values.
If the provided string does not exactly match any enum value’s name, the method throws an ArgumentError.
Master Dart with Deep Grasping Methodology!Learn More





