render method

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

Renders the underlying widget to the provided buffer within the area.

Implementation

@override
void render(Buffer buffer, Rect area) {
  final cb = widget as ConstrainedBox;
  final clampedWidth = area.width.clamp(
    cb.constraints.minWidth,
    cb.constraints.maxWidth,
  );
  final clampedHeight = area.height.clamp(
    cb.constraints.minHeight,
    cb.constraints.maxHeight,
  );

  if (clampedWidth <= 0 || clampedHeight <= 0) return;

  if (childElement != null &&
      childElement!.widget.runtimeType == cb.child.runtimeType) {
    childElement!.update(cb.child);
  } else {
    childElement = cb.child.createElement();
    childElement!.mount(this);
  }

  final childArea = Rect(area.x, area.y, clampedWidth, clampedHeight);
  final viewport = Viewport(buffer, childArea);
  childElement!.render(viewport, Rect(0, 0, clampedWidth, clampedHeight));
}