getAbbreviation static method

String? getAbbreviation(
  1. String country,
  2. String state
)

Implementation

static String? getAbbreviation(String country, String state) {
  final c = country.trim().toLowerCase();
  final s = state.trim().toLowerCase();

  Map<String, String>? targetMap;
  if (c == 'united states' || c == 'us' || c == 'usa' || c == 'united states of america') {
    targetMap = usStates;
  } else if (c == 'canada') {
    targetMap = canadaProvinces;
  } else if (c == 'australia') {
    targetMap = australiaStates;
  }

  if (targetMap != null) {
    for (final entry in targetMap.entries) {
      if (entry.key.toLowerCase() == s || entry.value.toLowerCase() == s) {
        return entry.value;
      }
    }
  }
  return null;
}