repeat method Null safety

String? repeat(
  1. int count
)

Repeats a string count times.

Example

String foo = 'foo'
String fooRepeated = foo.repeat(5) // 'foofoofoofoofoo';

Implementation

String? repeat(int count) {
  if (this == null) {
    return null;
  }

  if (this!.isEmpty || count <= 0) {
    return this;
  }
  var repeated = this!;
  for (var i = 0; i < count - 1; i++) {
    repeated += this!;
  }
  return repeated;
}