Question: In Java when you are defining an enum, you can do something similar to the following, i.e. add members to an `enum`. Is this possible in Dart?

```dart
enum Foo {
  one(1), two(2);
  final num value;
  Foo(this.value);
}

```

Answer: 
Dart Enhanced Enum Classes
==========================

Starting with Dart 2.17, the [Enhanced Enum Classes](https://github.com/dart-lang/language/blob/d16704ae6c9a5fd8f30b7ba9d33a5ab650c7447d/accepted/future-releases/enhanced-enums/feature-specification.md) feature has been introduced. With that, the example from the question would look like this:

```dart
enum Foo {
  one(1),
  two(2);

  const Foo(this.value);
  final num value;
}

```

Now, you can just use the enum class like this:

```dart
void main() {
  const foo = Foo.one;
  print(foo.value); // 1
}

```

Note that you need to update your SDK constraint as the feature requires Dart 2.17:

```yaml
environment:
  sdk: '>=2.17.0-0 <3.0.0'

```

Adding members
--------------

With enhanced enums, you can add **any** member to your enum as long as the **constructor is `const`**.

This also means that you can add getters or methods to existing enums, for example:

```dart
enum Cake {
  cherry,
  apple,
  strawberry;

  String get description => '$name cake';
}

```

Generics
--------

Enhanced enum classes also enable you to use generics for you enums. If you combine this with members, you can do the following:

```dart
enum Bar<T extends Object> {
  number<int>(42),
  name<String>('creativecreatorormaybenot'),
  baz(true); // Note that type inference also works.

  const Bar(this.value);
  final T value;
}

```

Mixins and interfaces
---------------------

In addition to declaring members, you can also mixin mixins and implement interfaces with enhanced enums and override any missing implementations.

```dart
mixin Foo {
  int get n;
}

abstract class Bar {
  void printNumber();
}

enum Baz with Foo implements Bar {
  one(1),
  two(2);

  const Baz(this.n);

  @override
  final int n;

  @override
  void printNumber() => print(n);
}

```

Multiple arguments
------------------

Finally note that even if I did not make use of it in any of the examples above, it is possible to have an arbitrary number of arguments (and an initializer list):

```dart
enum Foo {
  bar(42, description: 'The answer to life, the universe, and everything.'),
  baz(0, enabled: false, description: 'noop');

  const Foo(
    int number, {
    this.enabled = true,
    required this.description,
  }) : n = number;
  final int n;
  final bool enabled;
  final String description;
}

```
There's an upcoming feature in Dart known as enhanced enums, and it allows for enum declarations with many of the features known from classes. For example:

```dart
enum Blah {
  one(1), two(2);
  final num value;
  const Blah(this.value);
}

```

The feature is not yet released (and note that several things are not yet working), but experiments with it can be performed with a suitably fresh version of the tools by passing `--enable-experiment=enhanced-enums`.

The outcome is that `Blah` is an enum declaration with two values `Blah.one` and `Blah.two`, and we have `Blah.one.value == 1` and `Blah.two.value == 2`. The current bleeding edge handles this example in the common front end (so `dart` and `dart2js` will handle it), but it is not yet handled by the analyzer.