Created
September 6, 2020 18:37
-
-
Save rodydavis/f1466ea0df5745927c55b76f8639e2bd 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