Skip to content

Instantly share code, notes, and snippets.

@aryzhov
Created April 4, 2019 16:42
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 aryzhov/0302e718f18e7639f1a0a3a2ea142e5e to your computer and use it in GitHub Desktop.
Save aryzhov/0302e718f18e7639f1a0a3a2ea142e5e to your computer and use it in GitHub Desktop.
// Converts an enumeration value to its string representation without the type name
enumStr(dynamic enumValue) {
return enumValue?.toString()?.split('.')?.last;
}
// Converts a string to an enum value. Works as the inverse of [enumStr()].
parseEnum(List<dynamic> values, String value) {
return value == null ? null : values.firstWhere((v) => enumStr(v) == value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment