fromString static method

Rarity fromString(
  1. String rarity
)

Convert a String to a Rarity. If the String does not match a valid Rarity, an ArgumentError is thrown.

Implementation

static Rarity fromString(String rarity) {
  return switch (rarity.toLowerCase()) {
    'common' => common,
    'uncommon' => uncommon,
    'rare' => rare,
    'mythic' => mythic,
    'special' => special,
    'bonus' => bonus,
    _ => throw ArgumentError.value(rarity, 'rarity', 'Unexpected rarity'),
  };
}