findCountryCode method

String? findCountryCode({
  1. BuildContext? context,
})

Determine the current country code, either from the context, or from the system-reported default locale of the device. The default is US.

Implementation

String? findCountryCode({BuildContext? context}) {
  Locale? locale;
  if (context != null) {
    locale = Localizations.maybeLocaleOf(context);
  } else {
    // Get the system locale
    locale = ambiguate(WidgetsBinding.instance)!.window.locale;
  }
  final code = locale == null || locale.countryCode == null
      ? 'US'
      : locale.countryCode;
  return code;
}