Locale constructor Null safety

const Locale(
  1. String _languageCode,
  2. [String? _countryCode]
)

Creates a new Locale object. The first argument is the primary language subtag, the second is the region (also referred to as 'country') subtag.

For example:

const Locale swissFrench = Locale('fr', 'CH');
const Locale canadianFrench = Locale('fr', 'CA');

The primary language subtag must not be null. The region subtag is optional. When there is no region/country subtag, the parameter should be omitted or passed null instead of an empty-string.

The subtag values are case sensitive and must be one of the valid subtags according to CLDR supplemental data: language, region. The primary language subtag must be at least two and at most eight lowercase letters, but not four letters. The region region subtag must be two uppercase letters or three digits. See the Unicode Language Identifier specification.

Validity is not checked by default, but some methods may throw away invalid data.

See also:

Implementation

const Locale(
  this._languageCode, [
  this._countryCode,
]) : assert(_languageCode != null),
     assert(_languageCode != ''),
     scriptCode = null;