Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Descriptions to Enums in Dart
enum MyEnum {
simple,
special,
complex,
}
extension MyEnumUtils on MyEnum {
String get description {
switch (this) {
case MyEnum.simple:
return 'Just a simple type';
case MyEnum.special:
return 'A special type of thing';
case MyEnum.complex:
return 'There is more than meets the eye';
}
return describeEnum(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment