whenOrElse<R> method

R whenOrElse<R>(
  1. Map<Enum, R Function()> map, {
  2. required R orElse(),
})

Like when, but returns orElse if this enum value is not in map.

final label = status.whenOrElse(
  {Status.active: () => 'Active'},
  orElse: () => 'Unknown',
);

Implementation

R whenOrElse<R>(
  Map<Enum, R Function()> map, {
  required R Function() orElse,
}) =>
    map.containsKey(this) ? map[this]!() : orElse();