computePlatformResolvedLocale method

Locale? computePlatformResolvedLocale(
  1. List<Locale> supportedLocales

Computes the locale the current platform would resolve to.

This method is meant to be used as part of a WidgetsApp.localeListResolutionCallback. Since this method may return null, a Flutter/dart algorithm should still be provided as a fallback in case a native resolved locale cannot be determined or if the native resolved locale is undesirable.

This method may return a null Locale if the platform does not support native locale resolution, or if the resolution failed.

The first supportedLocale is treated as the default locale and will be returned if no better match is found.

Android and iOS are currently supported.

On Android, the algorithm described in is used to determine the resolved locale. Depending on the android version of the device, either the modern (>= API 24) or legacy (< API 24) algorithm will be used.

On iOS, the result of preferredLocalizationsFromArray method of NSBundle is returned. See: for details on the used method.

iOS treats script code as necessary for a match, so a user preferred locale of zh_Hans_CN will not resolve to a supported locale of zh_CN.

Since implementation may vary by platform and has potential to be heavy, it is recommended to cache the results of this method if the value is used multiple times.

Second-best (and n-best) matching locales should be obtained by calling this method again with the matched locale of the first call omitted from supportedLocales.


Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) {
  return platformDispatcher.computePlatformResolvedLocale(supportedLocales);