render method
Renders the underlying widget to the provided buffer within the area.
Implementation
@override
void render(Buffer buffer, Rect area) {
final stack = widget as Stack;
if (area.width <= 0 || area.height <= 0) return;
final newElements = <Element>[];
for (var i = 0; i < stack.children.length; i++) {
final childWidget = stack.children[i];
if (i < childElements.length &&
childElements[i].widget.runtimeType == childWidget.runtimeType) {
childElements[i].update(childWidget);
newElements.add(childElements[i]);
} else {
final newEl = childWidget.createElement();
newEl.mount(this);
newElements.add(newEl);
}
}
childElements = newElements;
for (var i = 0; i < childElements.length; i++) {
final childEl = childElements[i];
final childWidget = childEl.widget;
if (childWidget is Positioned) {
int childX = area.x;
int childY = area.y;
int childWidth = area.width;
int childHeight = area.height;
if (childWidget.left != null) {
childX = area.x + childWidget.left!;
if (childWidget.right != null) {
childWidth = area.width - childWidget.left! - childWidget.right!;
} else if (childWidget.width != null) {
childWidth = childWidget.width!;
} else {
childWidth = area.width - childWidget.left!;
}
} else if (childWidget.right != null) {
if (childWidget.width != null) {
childWidth = childWidget.width!;
childX = area.x + area.width - childWidget.right! - childWidth;
} else {
childWidth = area.width - childWidget.right!;
}
} else if (childWidget.width != null) {
childWidth = childWidget.width!;
}
if (childWidget.top != null) {
childY = area.y + childWidget.top!;
if (childWidget.bottom != null) {
childHeight = area.height - childWidget.top! - childWidget.bottom!;
} else if (childWidget.height != null) {
childHeight = childWidget.height!;
} else {
childHeight = area.height - childWidget.top!;
}
} else if (childWidget.bottom != null) {
if (childWidget.height != null) {
childHeight = childWidget.height!;
childY = area.y + area.height - childWidget.bottom! - childHeight;
} else {
childHeight = area.height - childWidget.bottom!;
}
} else if (childWidget.height != null) {
childHeight = childWidget.height!;
}
if (childWidth <= 0 || childHeight <= 0) continue;
final childArea = Rect(childX, childY, childWidth, childHeight);
final viewport = Viewport(buffer, childArea);
childEl.render(viewport, Rect(0, 0, childWidth, childHeight));
} else {
final viewport = Viewport(buffer, area);
childEl.render(viewport, Rect(0, 0, area.width, area.height));
}
}
}