> ## 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.

# Dart Enum

An enumerated type (enum) in Dart is a special class representing a fixed, predefined set of constant values. All enums automatically extend the core `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 the `enum` keyword followed by a comma-separated list of identifiers.

```dart theme={"dark"}
enum ConnectionState {
  disconnected,
  connecting,
  connected,
  disconnecting
}
```

## 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 constant `List` containing all instances of the enum in declaration order.

```dart theme={"dark"}
int position = ConnectionState.connecting.index; // 1
String identifier = ConnectionState.connecting.name; // "connecting"
List<ConnectionState> states = ConnectionState.values;
```

## 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:

1. Instance variables must be `final`.
2. All generative constructors must be `const`.
3. Factory constructors can only return one of the predefined, fixed enum instances.
4. The list of enum instances must be declared first, and if the enum contains members, the list must terminate with a semicolon (`;`).

```dart theme={"dark"}
enum HttpStatusCode {
  ok(200, 'Success'),
  badRequest(400, 'Bad Request'),
  internalServerError(500, 'Server Error');

  // Final instance variables
  final int code;
  final String description;

  // Constant generative constructor
  const HttpStatusCode(this.code, this.description);

  // Getter
  bool get isError => code >= 400;

  // Method
  void printStatus() => print('$code: $description');
}
```

## Mixins and Interfaces

While enums cannot extend other classes (as they already extend `Enum`), they can use mixins (`with`) and implement interfaces (`implements`).

```dart theme={"dark"}
mixin Loggable {
  void log() => print('Logging: $hashCode');
}

abstract interface class Serializable {
  String serialize();
}

enum Role with Loggable implements Serializable {
  admin,
  guest;

  @override
  String serialize() => '{"role": "$name"}';
}
```

## Technical Constraints

When working with Dart enums, the compiler enforces strict limitations to guarantee their constant, finite nature:

* You cannot use the `new` or `const` keywords to instantiate an enum outside of its internal declaration.
* You cannot override the `index`, `hashCode`, or the equality operator (`==`).
* The `values` property is reserved; you cannot declare a member named `values` within an enum.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
