addCommas method Null safety

String addCommas(
  1. String s
)

Implementation

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