Generic Enum Annotation

Build Status


As of generic_enum version 0.2.2, the package generic_enum_annotation is no longer required as a dependency when building a generic enum.


This library defines annotations used to annotate classes that extend GenericEnum.

GenericEnum is a base class for creating generic classes with a fixed set of static constant instances. These classes appear to the user like a Dart enumeration. For example, generic enums can be used in switch statements, to initialize variables, or as default parameters in functions and constructors.

The annotations defined in this library are:

  • @GenerateValueMap(): Requests the generation of an unmodifiable map _$<ClassName>ValueMap containing the enum values and const static instances.
  • @GenerateFromJson(): Requests the generation of the private function _$<ClassName>FromJson and the generation of _$<ClassName>ValueMap. Note: A ToJson function is already provided by the base class generic_enum.
  • @GenerateIdentifier(): Requests the generation of the private function _$<ClassName>Identifier. The function can be use to retrieve the identifier of each defined const generic enum instance.


To use this library include generic_enum and generic_enum_annotation as dependency in your pubspec.yaml file. Include generic_enum_builder and build_runner as dev_dependencies.

A step-by-step guide on how to build a generic enumeration is provided here.


The package generic_enum_example provides a complete example on how to define and build generic enumeration classes. As a starting point users could clone this repository, add their own generic enum classes to the folder lib and build the library.

Features and bugs

Please file feature requests and bugs at the issue tracker.