locale static method

String? locale(
  1. Locale? locale
)

Returns a Locale from the specified string.

The string is split on hyphens ("-").

If the string is null, returns null.

If there is no hyphen in the list, uses the one-argument form of Locale, passing the whole string.

If there is one hyphen in the list, uses the two-argument form of Locale, passing the parts before and after the hyphen respectively.

If there are two or more hyphens, uses the Locale.fromSubtags constructor.

Implementation

static String? locale(Locale? locale) {
  if (locale == null) return null;
  List<String?> list = [
    locale.languageCode,
    locale.scriptCode,
    locale.countryCode
  ]..removeWhere((element) => element != null);
  return list.join('-');
}