render method

  1. @override
void render(
  1. Buffer buffer,
  2. Rect area
)
override

Renders the widget onto the provided buffer within the specified area.

Implementation

@override
void render(Buffer buffer, Rect area) {
  if (area.width <= 0 || area.height <= 0) return;
  for (final child in children) {
    if (child is Positioned) {
      int childX = area.x;
      int childY = area.y;
      int childWidth = area.width;
      int childHeight = area.height;

      if (child.left != null) {
        childX = area.x + child.left!;
        if (child.right != null) {
          childWidth = area.width - child.left! - child.right!;
        } else if (child.width != null) {
          childWidth = child.width!;
        } else {
          childWidth = area.width - child.left!;
        }
      } else if (child.right != null) {
        if (child.width != null) {
          childWidth = child.width!;
          childX = area.x + area.width - child.right! - childWidth;
        } else {
          childWidth = area.width - child.right!;
        }
      } else if (child.width != null) {
        childWidth = child.width!;
      }

      if (child.top != null) {
        childY = area.y + child.top!;
        if (child.bottom != null) {
          childHeight = area.height - child.top! - child.bottom!;
        } else if (child.height != null) {
          childHeight = child.height!;
        } else {
          childHeight = area.height - child.top!;
        }
      } else if (child.bottom != null) {
        if (child.height != null) {
          childHeight = child.height!;
          childY = area.y + area.height - child.bottom! - childHeight;
        } else {
          childHeight = area.height - child.bottom!;
        }
      } else if (child.height != null) {
        childHeight = child.height!;
      }

      if (childWidth <= 0 || childHeight <= 0) continue;

      final childArea = Rect(childX, childY, childWidth, childHeight);
      final viewport = Viewport(buffer, childArea);
      child.child.render(viewport, Rect(0, 0, childWidth, childHeight));
    } else {
      final viewport = Viewport(buffer, area);
      child.render(viewport, Rect(0, 0, area.width, area.height));
    }
  }
}