From b2d4522fb2d851e3406eb8fbf28ec4000443920f Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 15 Mar 2023 07:56:27 +1100 Subject: [PATCH] Add currency suffix if currency cannot be determined (#282) --- lib/helpers.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/helpers.dart b/lib/helpers.dart index ae1150cd..3cb905e7 100644 --- a/lib/helpers.dart +++ b/lib/helpers.dart @@ -88,13 +88,24 @@ String renderCurrency(double? amount, String currency, {int decimals = 2}) { if (amount == null) return "-"; if (amount.isInfinite || amount.isNaN) return "-"; + currency = currency.trim(); + + if (currency.isEmpty) return "-"; + CurrencyFormatterSettings backupSettings = CurrencyFormatterSettings( symbol: "\$", symbolSide: SymbolSide.left, ); - return CurrencyFormatter.format( + String value = CurrencyFormatter.format( amount, CurrencyFormatter.majors[currency.toLowerCase()] ?? backupSettings ); + + // If we were not able to determine the currency + if (!CurrencyFormatter.majors.containsKey(currency.toLowerCase())) { + value += " ${currency}"; + } + + return value; } \ No newline at end of file