Flutter Dart - get localized country name from country code

7.3k Views Asked by At

I have a list of alpha-2 country codes.

 List<String> countryCodes = ["DE", "CH", "AT"];

How to get the localized country names in Flutter/Dart?

If the device language is set to english, i want this output..

Germany, Switzerland, Austria

If the device language is set to german, i want this output..

Deutschland, Schweiz, Österreich

Is this possible without any 3rd party package in Flutter/Dart?

In Java you could do..

Locale loc = new Locale("","DE");
loc.getDisplayCountry();
3

There are 3 best solutions below

0
Nao Kreuzeder On

To get the localized country names from a country code one can use the Country Codes package from pub.dev.

Its easy to use. I recommend.

https://pub.dev/packages/country_codes

0
Mohamed Hamzaoui On

If you have any country code and wants to get corresponding country name, use country_picker package like this

Country.tryParse(countryCode)?.name
0
Nicolas - PASS2RENT On

You can use country_picker :

MaterialApp(
  supportedLocales: [
    const Locale('en'),
    const Locale('lt'),
  ],
  localizationsDelegates: [
    CountryLocalizations.delegate,
    ...
  ],
  ...)

and then get the localized country name via :

CountryLocalizations.of(context)?.countryName(countryCode: 'LT')