findEnum<TEnum extends Enum> function

TEnum findEnum<TEnum extends Enum>(
  1. String value,
  2. List<TEnum> values,
  3. {bool ignoreCase = false}
)

Finds and returns the enum value which matches with the given string value.

The comparison is case sensitive by default. Be careful when using ignoreCase as dart allows different enum values with only case difference. If no value matches, a BoostException is thrown. For null instead of an exception, use tryFindEnum.

Example:

enum MyEnum { first, second, third }
...
final value = findEnum('second', MyEnum.values);

Implementation

TEnum findEnum<TEnum extends Enum>(String value, List<TEnum> values,
    {bool ignoreCase = false}) {
  return tryFindEnum(value, values, ignoreCase: ignoreCase) ??
      (throw BoostException('Enum value "$value" not found.'));
}