The Problem with Default Canvas Rendering
When building interactive whiteboard applications in Flutter for large touch panels and tablets, standard widget rebuilds and naive CustomPainter implementations often introduce noticeable input latency (50β70ms+). When hundreds of stylus points are captured per second alongside real-time WebSocket synchronization, calling setState() on every pointer move triggers unnecessary widget tree rebuilds and frame drops.
Decoupling Input Capture from Widget Tree Rebuilds
Instead of calling setState() on every onPanUpdate or onPointerMove event, high-frequency stylus points should be buffered and passed directly to the canvas repaint listener using a ChangeNotifier:
import 'package:flutter/material.dart';
class StrokeController extends ChangeNotifier {
final List _points = [];
List get points => List.unmodifiable(_points);
void addPoint(Offset point) {
_points.add(point);
notifyListeners(); // Marks only RenderCustomPaint as dirty
}
void clear()β¦