Opposite of Flutter's describeEnum function
638
You can do that using the firstWhere
function on the values of your enum:
MyEnum myEnum = MyEnum.values.firstWhere((e) => describeEnum(e) == str);
Comments
-
Michal Karbownik over 1 year
Flutter's foundation library has a describeEnum function that returns a short description based on an enum value.
Is there a function that would do the opposite, i.e., return enum value based on the received description?
I know about the enum_to_string, but I'm interested in vanilla Dart or Flutter standard library solution.
-
Michal Karbownik over 3 years@F Perroch A great idea, thanks! I'll wait a bit to get more answers, but if nothing better comes, I'll definitely accept yours!