flutter_currency_picker icon indicating copy to clipboard operation
flutter_currency_picker copied to clipboard

Give a way to return the currency related to a locale

Open rocboronat opened this issue 3 years ago • 3 comments

As this project has a lot of information about the currencies, it would be great to use it to retrieve the Currency related to a given Locale.

rocboronat avatar Mar 22 '21 09:03 rocboronat

@rocboronat The package dose not have this info. Can you provide a valid source?

Daniel-Ioannou avatar Apr 01 '21 12:04 Daniel-Ioannou

Honestly? Nope... But we could do it for the most used Locales.

For example:

  • es_ES fr_FR = Euro
  • en_US = US dollar

If we make a long enough list, it will do the job.

rocboronat avatar Jul 06 '21 08:07 rocboronat

I needed this as well and stumbled across this StackOverflow thread.

We can use the intl package to get the currency from the locale; currencyName is equivalent to Currency#code of this package. So you could do something like:

String currencyCode = NumberFormat.simpleCurrency(locale: locale).currencyName;
Currency? currency = CurrencyService().findByCode(currencyCode);

It's quite simple to just do this manually since the currency service is public. I don't think it's worth introducing a dependency just to do this, but if people think it's a good idea I'm happy to raise a PR!

yallurium avatar Mar 08 '22 21:03 yallurium