performPaint method
Hook for subclasses to implement actual painting.
Implementation
@override
void performPaint(Buffer buffer, Offset offset) {
final viewport = Viewport(
buffer,
Rect(offset.dx, offset.dy, size.width, size.height),
);
final display = widget as SevenSegmentDisplay;
if (size.width <= 0 || size.height < 5) return;
final activeSt = Style(foreground: display.activeColor);
final inactiveSt = Style(foreground: display.inactiveColor);
int offsetX = 0;
for (int i = 0; i < display.value.length; i++) {
final char = display.value[i];
final matrix =
SevenSegmentDisplay._digits[char] ?? SevenSegmentDisplay._digits[' '];
if (matrix != null) {
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (offsetX + x < size.width && y < size.height) {
final active = matrix[y][x] == 1;
viewport.writeString(
offsetX + x,
y,
'█',
active ? activeSt : inactiveSt,
);
}
}
}
offsetX += 6; // 5 width + 1 spacing
}
}
}