fromString<T> static method

T? fromString<T>(
  1. List<T> enumValues,
  2. String? value
)

Implementation

static T? fromString<T>(List<T> enumValues, String? value) {
  /// Returns the enum item from a [String] value.
  /// It receives a [List] of enum values and a [String] value as parameters.
  /// It returns the enum item.
  /// If the [value] is null, it returns null.
  if (value == null) return null;

  return enumValues.firstWhereOrNull(
    (enumItem) => [
      enumItem.toString().normalized(),
      EnumHelper.parse(enumItem)!.normalized(),
    ].contains(value.normalized()),
  );
}