CurrencyInputFormatter class

A custom TextInputFormatter for formatting currency input dynamically.

This formatter takes raw numerical input and formats it as currency in real time. It supports locale-based formatting and a customizable currency symbol.

Parameters:

  • locale: The locale to use for formatting (e.g., 'en_US', 'fr_FR').
  • currencySymbol: The symbol to use for the currency (e.g., '$', '€').

Behavior:

  • Removes all non-numeric characters from the input.
  • Divides the number by 100 to represent a monetary value.
  • Formats the resulting value as currency based on the locale and symbol.

Examples:

final formatter = CurrencyInputFormatter(locale: 'en_US', currencySymbol: '\$');// Input: "12345" // Output: "$123.45"

final frenchFormatter = CurrencyInputFormatter(locale: 'fr_FR', currencySymbol: '€');// Input: "12345" // Output: "123,45 €"

Inheritance

Constructors

CurrencyInputFormatter({required String locale, required String currencySymbol})
Creates a CurrencyInputFormatter with the specified locale and currencySymbol.

Properties

currencySymbol String
final
hashCode int
The hash code for this object.
no setterinherited
locale String
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) TextEditingValue
Called when text is being typed or cut/copy/pasted in the EditableText.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited