enumDecode<K, V> function Null safety

K? enumDecode<K, V>(
  1. Map<K, V> enumValues,
  2. Object? source,
  3. {K? unknownValue}
)

Implementation

K? enumDecode<K, V>(
  Map<K, V> enumValues,
  Object? source, {
  K? unknownValue,
}) {
  if (source != null) {}

  final entries = enumValues.entries.where((element) {
    return element.value == source;
  }).toList();

  return entries.length > 0 ? entries.first.key : unknownValue;
}