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: 
As an improvement on the other suggestions of using Extensions, you can define your assigned values in a list or map, and the extension will be concise.

```dart
enum Numbers {
  one,
  two,
  three,
}

// Numbers.one.value == 1
// Numbers.two.value == 2
// Numbers.three.value == 3

```

example with list

```dart
extension NumbersExtensionList on Numbers {
  static const values = [1, 2, 3];
  int get value => values[this.index];
}

```

example with map

```dart
extension NumbersExtensionMap on Numbers {
  static const valueMap = const {
    Numbers.one: 1,
    Numbers.two: 2,
    Numbers.three: 3,
  };
  int get value => valueMap[this];
}

```

> 
> **Note:** This approach has the limitation that you can **not** define a *static factory method* on the Enum, e.g. `Numbers.create(1)` (as of Dart 2.9). You *can* define this method on the `NumbersExtension`, but it would need to be called like `NumbersExtension.create(1)`
> 
> 
>
You can add extra fields and methods with my package [enum\_extendable](https://pub.dev/packages/enum_extendable_generator).  

It generates extensions on enum, so you can use your enum values in the similar way to instances of a regular Dart class.  

For example, if you have `enum MathOperator { plus, minus }` the `symbol` and `calculate(...)` can be added to it.  

So, the enum can be used in such way:

```
final n1 = 1;
final n2 = 2.0;
MathOperator.values.forEach((operator) {
  print('$n1 ${operator.symbol} $n2 = ${operator.calculate(n1, n2)}');
});

```

Usage:

1. Add dependencies to pubspec.yaml:

`dependencies:`  

 `enum_extendable_annotation:`

`dev_dependencies:`  

 `build_runner:`  

 `enum_extendable_generator:`

Install these dependencies:

```
# Dart
pub get

# Flutter
flutter packages get

```

2. Add imports to your enum file:

`import 'package:enum_extendable_annotation/enum_extendable_annotation.dart';`

 `part '<your enum file name>.enum_extendable.g.dart';`
3. Create a PODO class with fields and methods you wanted.
4. Create a map with instances of this PODO class for each enum value.
5. Annotate elements:

* the enum with `@ExtendableEnum()`;
* the PODO class - `@ExtendableEnumPodo()`;
* the map of PODO instances - `@ExtendableEnumValues()`.

6. Run code generator:

* if your package depends on Flutter:

`flutter pub run build_runner build`
* if your package does not depend on Flutter:

`dart pub run build_runner build`

The file with extensions should be generated.

Example of the enum file:

```
import 'package:enum_extendable_annotation/enum_extendable_annotation.dart';

part 'math_operator.enum_extendable.g.dart';

@ExtendableEnum()
enum MathOperator { plus, minus }

@ExtendableEnumPodo()
class _MathOperatorPodo {

  final String symbol;
  final num Function(num, num) calculate;

  _MathOperatorPodo(
    this.symbol,
    this.calculate,
  );

  @ExtendableEnumValues()
  static final Map<MathOperator, _MathOperatorPodo> _values = {
  MathOperator.plus: _MathOperatorPodo(
     '+',
      (n1, n2) => n1 + n2,
    ),
  MathOperator.minus: _MathOperatorPodo(
      '-',
      (n1, n2) => n1 - n2,
    ),
  };
}

```