enumValueFromName<T> static method

T? enumValueFromName<T>(
  1. Iterable<T> enumValues,
  2. String enumName
)

Returns an enum value based on its string name. For example, given 'POST', and the enum enum Methods { GET, POST, DELETE }, Methods.POST is returned.

Implementation

static T? enumValueFromName<T>(Iterable<T> enumValues, String enumName) {
  return firstWhereOrNull(enumValues, (e) => e.toString().split('.').last == enumName);
}