currency method

Formatter currency({
  1. String? code,
  2. String? leading,
  3. String? trailing,
  4. int? mantissa,
  5. int? maxLength,
  6. bool? usePadding,
  7. Separator? separator,
  8. ValueChanged<num>? onChanged,
})

Formats the value in a currency format.

If code and separator are not provided, the formatter will use Separator.commaAndDot by default.

Implementation

Formatter currency({
  String? code, // USD, BRL, etc
  String? leading,
  String? trailing,
  int? mantissa, // decimal places
  int? maxLength,
  bool? usePadding,
  Separator? separator,
  ValueChanged<num>? onChanged,
}) {
  V? get<V>(String key) {
    if (currencyConfigs[code]?[key] case V it) return it;
    return null;
  }

  return addFormatter(
    CurrencyInputFormatter(
      thousandSeparator: separator?.thousandSeparator ?? get('separator'),
      mantissaLength: mantissa ?? get('mantissa') ?? 2,
      leadingSymbol: leading ?? get('leading') ?? '',
      trailingSymbol: trailing ?? get('trailing') ?? '',
      useSymbolPadding: usePadding ?? get('padding') ?? false,
      maxTextLength: maxLength,
      onValueChange: onChanged,
    ),
  );
}