addLocale method Null safety

void addLocale(
  1. String localeName,
  2. Function findLocale

If we do not already have a locale for localeName then findLocale will be called and the result stored as the lookup mechanism for that locale.


void addLocale(String localeName, Function findLocale) {
  if (localeExists(localeName)) return;
  var canonical = Intl.canonicalizedLocale(localeName);
  var newLocale = findLocale(canonical);
  if (newLocale != null) {
    availableMessages[localeName] = newLocale;
    availableMessages[canonical] = newLocale;
    // If there was already a failed lookup for [newLocale], null the cache.
    if (_lastLocale == newLocale) {
      _lastLocale = null;
      _lastLookup = null;