repeat method

String repeat(
  1. int n, {
  2. String separator = '',
})

Repeats the string n times, optionally with a separator.

Implementation

String repeat(int n, {String separator = ''}) {
  if (n < 0) throw ArgumentError('n must be a positive value greater than 0');
  return List.generate(
    n,
    (i) => (i > 0 ? separator : '') + validate(),
  ).join();
}