addCommas method Null safety

String addCommas(
  1. String s,
  2. bool intToo
)

Implementation

String addCommas(String s, bool intToo) {
  String r = '';
  final int dp = s.indexOf('.');
  if (dp > -1) {
    r = s.substring(dp);
    s = s.substring(0, dp);
  }
  final String sign;
  if (s.startsWith('-')) {
    sign = '-';
    s = s.substring(1);
  } else {
    sign = '';
  }
  while (s.trim().length > commaDistance) {
    r = ',${s.substring(s.length - commaDistance)}$r';
    s = s.substring(0, s.length - commaDistance);
  }
  return sign + s + r;
}