flutter_currency_picker
flutter_currency_picker copied to clipboard
Give a way to return the currency related to a locale
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 The package dose not have this info. Can you provide a valid source?
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.
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!