obscure method

String? obscure({
  1. int start = 0,
  2. int end = 0,
  3. String obscureWith = '*',
})

Implementation

String? obscure({int start = 0, int end = 0, String obscureWith = '*'}) {
  if (this == null) return null;
  if (this!.isEmpty) return this;
  if (start < 0) start = 0;
  if (end < 0) end = 0;
  if (start + end > this!.length) {
    start = 0;
    end = 0;
  }
  var obscured = this!.substring(0, start);
  for (var i = 0; i < this!.length - start - end; i++) {
    obscured += obscureWith;
  }
  obscured += this!.substring(this!.length - end);
  return obscured;
}