toEnum<T> method

T toEnum<T>(
  1. List<T> values, {
  2. bool throwIfInvalid = true,
})

Implementation

T toEnum<T>(List<T> values, {bool throwIfInvalid = true}) {
  return values.firstWhere(
      (e) => e.toString().toLowerCase().split(".").last == toLowerCase(),
      orElse: () => throwIfInvalid
          ? throw const FormatException("Invalid enum value")
          : values.first);
}