selectLogic method

dynamic selectLogic (Object choice, Map<Object, dynamic> cases)

Internal: Implements the logic for select - use select for normal messages.

Implementation

static selectLogic(Object choice, Map<Object, dynamic> cases) {
  // This will work if choice is a string, or if it's e.g. an
  // enum and the map uses the enum values as choices.
  var exact = cases[choice];
  if (exact != null) return exact;
  // If it didn't match exactly, take the toString and
  // take the part after the period. We need to do this
  // because enums print as 'EnumType.enumName' and periods
  // aren't acceptable in ICU select choices.
  var stringChoice = "$choice".split('.').last;
  var stringMatch = cases[stringChoice];
  if (stringMatch != null) return stringMatch;
  var other = cases["other"];
  if (other == null)
    throw new ArgumentError("The 'other' case must be specified");
  return other;
}