render method
Renders the widget onto the provided buffer within the specified area.
Implementation
@override
void render(Buffer buffer, Rect area) {
// Fill background if defined
var bgStyle = decoration.backgroundStyle;
if (bgStyle == null && decoration.backgroundColor != null) {
bgStyle = Style(background: decoration.backgroundColor);
}
if (bgStyle != null) {
for (var y = 0; y < area.height; y++) {
for (var x = 0; x < area.width; x++) {
buffer.setCell(area.x + x, area.y + y, Cell(' ', bgStyle));
}
}
}
// Draw border if defined
final border = decoration.border;
var topOffset = 0;
var bottomOffset = 0;
var leftOffset = 0;
var rightOffset = 0;
if (border != null) {
final style = bgStyle != null
? bgStyle.merge(border.style)
: border.style;
// Draw horizontal lines (excluding corners)
if (border.topChar.isNotEmpty && area.height > 0) {
topOffset = 1;
for (var x = 1; x < area.width - 1; x++) {
buffer.setCell(area.x + x, area.y, Cell(border.topChar, style));
}
}
if (border.bottomChar.isNotEmpty && area.height > 1) {
bottomOffset = 1;
for (var x = 1; x < area.width - 1; x++) {
buffer.setCell(
area.x + x,
area.y + area.height - 1,
Cell(border.bottomChar, style),
);
}
}
// Draw vertical lines (excluding corners)
if (border.leftChar.isNotEmpty && area.width > 0) {
leftOffset = 1;
for (var y = 1; y < area.height - 1; y++) {
buffer.setCell(area.x, area.y + y, Cell(border.leftChar, style));
}
}
if (border.rightChar.isNotEmpty && area.width > 1) {
rightOffset = 1;
for (var y = 1; y < area.height - 1; y++) {
buffer.setCell(
area.x + area.width - 1,
area.y + y,
Cell(border.rightChar, style),
);
}
}
// Draw corners
if (border.topLeftChar.isNotEmpty && area.width > 0 && area.height > 0) {
buffer.setCell(area.x, area.y, Cell(border.topLeftChar, style));
}
if (border.topRightChar.isNotEmpty && area.width > 1 && area.height > 0) {
buffer.setCell(
area.x + area.width - 1,
area.y,
Cell(border.topRightChar, style),
);
}
if (border.bottomLeftChar.isNotEmpty &&
area.width > 0 &&
area.height > 1) {
buffer.setCell(
area.x,
area.y + area.height - 1,
Cell(border.bottomLeftChar, style),
);
}
if (border.bottomRightChar.isNotEmpty &&
area.width > 1 &&
area.height > 1) {
buffer.setCell(
area.x + area.width - 1,
area.y + area.height - 1,
Cell(border.bottomRightChar, style),
);
}
}
// Render child in remaining area
final childX = area.x + leftOffset;
final childY = area.y + topOffset;
final childWidth = area.width - leftOffset - rightOffset;
final childHeight = area.height - topOffset - bottomOffset;
if (childWidth > 0 && childHeight > 0) {
final childArea = Rect(childX, childY, childWidth, childHeight);
final childViewport = Viewport(buffer, childArea);
child.render(childViewport, Rect(0, 0, childWidth, childHeight));
}
}