init static method

Future<bool> init(
  1. [Locale? appLocale]

Inits the underlying plugin channel and fetch current's device locale to be ready to use synchronously when required.

If you never plan to provide a locale directly, you must call and await this by calling await CountryCodes.init(); before accessing any other method.

Optionally, you may want to provide your appLocale to access localized country name (eg. if your app is in English, display Italy instead of Italia).



This will default to device's language if none is provided.


static Future<bool> init([Locale? appLocale]) async {
  final List<dynamic>? locale = List<dynamic>.from(
      await (_channel.invokeMethod('getLocale', appLocale?.toLanguageTag())));
  if (locale != null) {
    _deviceLocale = Locale(locale[0], locale[1]);
    _localizedCountryNames = Map.from(locale[2]);
  return _deviceLocale != null;