localeResolutionCallback static method

Locale? localeResolutionCallback(
  1. Locale? preferredLocale,
  2. Iterable<Locale>? supportedLocales
)

Called by the LocalizationsDelegate. Possibly needed to resolve current Locale.

Implementation

static Locale? localeResolutionCallback(
    Locale? preferredLocale, Iterable<Locale>? supportedLocales) {
  //
  if (preferredLocale == null) {
    // Retrieve the 'first' locale in the supported locales.
    final locales = _supportedLocales;

    if (locales.isNotEmpty) {
      //
      if (supportedLocales == null) {
        // Use the first supported locale.
        preferredLocale = locales.first;
      } else {
        // Find the first supported locale
        for (final locale in supportedLocales.toList(growable: false)) {
          //
          if (locales.contains(locale)) {
            preferredLocale = locale;
          }
        }
      }
    }
  }
  return preferredLocale;
}