enumFromString<T> method
Returns an enum type from its String representation value
.
values
must be the list of enum types defined by T
.
It is legal that value
be specfied with or without T
:
Implementation
static T enumFromString<T>(Iterable<T> values, String value) {
String val = value;
if (!value.contains(".")) {
String enumType = values.first.toString().split(".").first;
val = "$enumType.$value";
}
return values.firstWhere((type) => type.toString() == val,
orElse: () => null);
}