toPriceAmount method Null safety

String? toPriceAmount(
  1. {String? currencySymbol}
)

Tries to format the current String to price amount. You can pass

you can optionally pass the currencySymbol to append a symbol to the formatted text.

Example

String price = '1234567';
String formattedPrice = foo1.toPriceAmount(currencySymbol: '€'); // returns '12.345,67 €'

Implementation

String? toPriceAmount({String? currencySymbol}) {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  try {
    var f = NumberFormat.currency(locale: 'el_GR');

    return f
        .format(double.tryParse(this!.replaceAll(',', '.')))
        .replaceAll('EUR', '')
        .trim()
        .append(currencySymbol == null ? '' : ' $currencySymbol');
  } catch (e) {
    return null;
  }
}