padBoth static method

String padBoth(
  1. String value,
  2. int length, [
  3. String pad = ' '
])

Pads both sides of value with pad until length is reached.

Implementation

static String padBoth(String value, int length, [String pad = ' ']) {
  if (value.length >= length || pad.isEmpty) return value;
  final short = length - value.length;
  final leftLen = (short / 2).floor();
  final rightLen = short - leftLen;
  return '${_repeatToLen(pad, leftLen)}$value${_repeatToLen(pad, rightLen)}';
}