Flutter:如何从货币代码中获取货币符号

1hdlvixo  于 2023-01-09  发布在  Flutter
关注(0)|答案(3)|浏览(118)

从语言代码很容易:

var format = NumberFormat.simpleCurrency(locale: "es");
print(format.currencySymbol);

但我只有EUR代表欧元,所以货币代码

pgx2nnw8

pgx2nnw81#

var format = NumberFormat.simpleCurrency(locale: _language); <-- doesn't really what matter what language you pass
print(format.simpleCurrencySymbol("EUR"));
zqdjd7g9

zqdjd7g92#

intl软件包可以解决这个问题

import 'package:intl/intl.dart';

void currency() {
    Locale locale = Localizations.localeOf(context);
    var format = NumberFormat.simpleCurrency(locale: locale.toString());
    print("CURRENCY SYMBOL ${format.currencySymbol}"); // $
    print("CURRENCY NAME ${format.currencyName}"); // USD
}

相关问题