-
-
Save samuelematias/fb416729fa2afffb9264ddfc43d8471f to your computer and use it in GitHub Desktop.
Add Descriptions to Enums in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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