padVisibleCenter function

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

Centers styled text within width based on visible character length.

Implementation

String padVisibleCenter(String text, int width) {
  final visible = visibleLength(text);
  if (visible >= width) return text;
  final total = width - visible;
  final left = total ~/ 2;
  final right = total - left;
  return ' ' * left + text + ' ' * right;
}