padRight function

String padRight(
  1. String text,
  2. int width
)

Pads text to width with trailing spaces.

If text is already at or longer than width, returns text unchanged.

Example:

padRight('Hi', 5); // 'Hi   '
padRight('Hello', 3); // 'Hello'

Implementation

String padRight(String text, int width) {
  if (text.length >= width) return text;
  return text + ' ' * (width - text.length);
}