Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created September 6, 2020 18:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rodydavis/f1466ea0df5745927c55b76f8639e2bd to your computer and use it in GitHub Desktop.
Save rodydavis/f1466ea0df5745927c55b76f8639e2bd 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