Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/fb416729fa2afffb9264ddfc43d8471f to your computer and use it in GitHub Desktop.
Save samuelematias/fb416729fa2afffb9264ddfc43d8471f to your computer and use it in GitHub Desktop.
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