bestMatch property

Locale bestMatch

Exact Locale for regular locales, and guess for systemLocale.

Unlike locale properties, it try to find matching locale in supportedLocales.

Implementation

Locale get bestMatch {
  // exact
  if (name != systemLocale &&
      name != showOtherLocales &&
      LocaleStore.supportedLocaleNames.names.contains(name)) {
    return LocaleSwitcher.current.locale!;
  }
  // guess
  switch (name) {
    case showOtherLocales:
      if (LocaleStore.supportedLocaleNames.length > 2) {
        return LocaleStore.supportedLocaleNames[1].locale ??
            const Locale('en');
      } else {
        return const Locale('en');
      }
    case systemLocale:
      return LocaleMatcher.tryFindLocale(locale!.toString())?.locale ??
          const Locale('en');
    default:
      return locale ?? const Locale('en');
  }
}