paint method

  1. @override
String paint()
override

Implementation

@override
String paint() {
  if (children.isEmpty) return '';

  // Use cached content lines if available; otherwise paint all children
  // and cache the result.
  final lines = _cachedChildPaintLines ?? _paintAndCacheChildren();
  if (lines.isEmpty) return '';

  final viewportHeight = size.height.round();
  final scrollOffset = controller.offset.clamp(0, controller.maxOffset);

  if (scrollOffset >= lines.length) return '';
  final endLine = math.min(lines.length, scrollOffset + viewportHeight);
  final visible = lines.sublist(scrollOffset, endLine);

  while (visible.length < viewportHeight) {
    visible.add('');
  }

  return visible.join('\n');
}