Opposite of Flutter's describeEnum function

Viewed 777

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.

1 Answers

You can do that using the firstWhere function on the values of your enum:

MyEnum myEnum = MyEnum.values.firstWhere((e) => describeEnum(e) == str);

Related