2

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();
Nao Kreuzeder
  • 223
  • 6
  • 18
  • Does this answer your question? [How to get language's full name from languageCode? (e.g: from 'en' to 'English')](https://stackoverflow.com/questions/53999971/how-to-get-languages-full-name-from-languagecode-e-g-from-en-to-english) https://stackoverflow.com/a/65838283/4593315 – Tirth Patel Jul 03 '22 at 17:59
  • No, this is not what i was looking for. I need the "Country Name" from the Country Code (eg. 'DE', 'RU', 'US', 'HU' etc.), not the "Language Code". – Nao Kreuzeder Jul 03 '22 at 18:39
  • There is nothing in the Dart or Flutter SDK that will do that, so I imagine your answer to "Is this possible" is simply... NO. But if you still need it done, perhaps something in "pub" will suffice. – Randal Schwartz Jul 03 '22 at 19:58

2 Answers2

1

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

Nao Kreuzeder
  • 223
  • 6
  • 18
1

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

Country.tryParse(countryCode)?.name
Mohamed Hamzaoui
  • 325
  • 4
  • 15