performPaint method
Hook for subclasses to implement actual painting.
Implementation
@override
void performPaint(Buffer buffer, Offset offset) {
final w = size.width;
final h = size.height;
if (w <= 0 || h <= 0) return;
final widget = this.widget as SubpixelRippleWidget;
final manager = widget.manager;
final now = DateTime.now().millisecondsSinceEpoch;
manager.updateRipples(now);
if (!manager.hasActiveRipples) return;
final canvas = Canvas(w, h, onlyDrawOnSpaces: true);
var hasPainted = false;
for (final ripple in manager.ripples) {
final elapsed = now - ripple.startTime;
if (elapsed < 0) continue;
final progress = (elapsed / ripple.durationMs).clamp(0.0, 1.0);
final radius = (progress * 16).round();
if (radius > 0) {
final Color(:r, :g, :b) = ripple.color;
final fade = (255 * (1.0 - progress)).round().clamp(0, 255);
final style = Style(
foreground: Color(
(r * fade) ~/ 255,
(g * fade) ~/ 255,
(b * fade) ~/ 255,
),
);
canvas.drawCircle(
(ripple.center.x - 1) * 2 + 1,
(ripple.center.y - 1) * 4 + 2,
radius,
cellStyle: style,
);
hasPainted = true;
}
}
if (hasPainted) {
final canvasEl = canvas.createElement();
canvasEl.layout(BoxConstraints.tight(Size(w, h)));
canvasEl.paint(buffer, offset);
canvasEl.unmount();
}
}