NumberTextFormatter<T extends num?> constructor

NumberTextFormatter<T extends num?>({
  1. int fraction = 0,
  2. String? locale,
})

Create number formatter used for TextInput

Implementation

NumberTextFormatter({this.fraction = 0, this.locale}) {
  if ((_type == 'int' || _type == 'int?') && fraction > 0) {
    throw Exception("Integer don't accept fraction number");
  }
  //format decimal number
  var s = '#,##0';
  if (fraction > 0) {
    s += '.'.padRight(fraction + 1, '#');
  }
  numberFormat = NumberFormat(s, locale);
  _decimal = numberFormat.symbols.DECIMAL_SEP;
  _thousand = numberFormat.symbols.GROUP_SEP;
  if (fraction > 0) {
    _regex = RegExp('^\\d+(?:\\.\\d{0,$fraction})?\$');
  } else {
    _regex = RegExp(r'^\d+$');
  }
}