We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would be nice, if the an enum would have by default a method like getValue(String key) that returns the corresponding enum value to that key.
getValue(String key)
key
Currently it's necessary to iterate through the values and match them manually.
values
enum MyEnum { a, b, c, d }
String key = 'c'; for(final MyEnum myEnum in MyEnum.values) { if(myEnum.toString() == key) return myEnum); } // optional fallback value return MyEnum.a;
String key = 'c'; MyEnum myEnum = MyEnum.getValue(key, fallback: MyEnum.a);
The text was updated successfully, but these errors were encountered:
Currently not possible. Dart doesn't allow to define static extensions or factory constructors as extensions dart-lang/language#723
Sorry, something went wrong.
No branches or pull requests
Get an enum value by String
Would be nice, if the an enum would have by default a method like
getValue(String key)
that returns the corresponding enum value to thatkey
.Current situation
Currently it's necessary to iterate through the
values
and match them manually.Better solution
The text was updated successfully, but these errors were encountered: