2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-08-04 11:41:30 +00:00

Adds support for currency display (#277)

* Adds a helper function for rendering currency data

* Update helper functions for StockItem model

* Render purchasePrice correctly for stockitem

* Use currency_formatter library instead of money_formatter

* Add total price display for purchase order

* icon fix
This commit is contained in:
Oliver
2023-03-08 23:42:26 +11:00
committed by GitHub
parent 221920cbbe
commit 347e80d8e2
9 changed files with 311 additions and 236 deletions

View File

@@ -8,6 +8,7 @@
*/
import "dart:io";
import "package:currency_formatter/currency_formatter.dart";
import "package:audioplayers/audioplayers.dart";
import "package:one_context/one_context.dart";
@@ -77,3 +78,23 @@ Future<void> playAudioFile(String path) async {
final player = AudioPlayer();
player.play(AssetSource(path));
}
/*
* Helper function for rendering a money / currency object as a String
*/
String renderCurrency(double? amount, String currency, {int decimals = 2}) {
if (amount == null) return "-";
if (amount.isInfinite || amount.isNaN) return "-";
CurrencyFormatterSettings backupSettings = CurrencyFormatterSettings(
symbol: "\$",
symbolSide: SymbolSide.left,
);
return CurrencyFormatter.format(
amount,
CurrencyFormatter.majors[currency.toLowerCase()] ?? backupSettings
);
}