Flutter › Flutter Gestures & Touch Handling

What performance considerations become genuinely important when handling a very high frequency of continuous gesture events, such as a genuinely fast, continuous freehand drawing gesture, without noticeably introducing visible lag or dropped frames?

Advanced

Answer

Handling a genuinely very high frequency of continuous gesture events, such as tracking a user's finger during fast freehand drawing, requires carefully ensuring that whatever specific processing happens on each individual received touch event remains genuinely lightweight and fast, since a slow, overly expensive onPanUpdate callback running many times per second can quite easily and quickly cause your entire app's overall frame rate to visibly drop noticeably, and strategies to help meaningfully address this include batching several rapidly incoming individual touch points together before actually triggering a full widget rebuild, and using a genuinely efficient CustomPainter specifically designed to only actually redraw the small, most recently added incremental portion of a drawing rather than needlessly redrawing the entire accumulated drawing canvas completely from scratch on every single individual received touch event.
// Efficiently redrawing only the newest added path segment,
// rather than the entire accumulated drawing every single time
Real-world example A digital sketching app optimizes its freehand drawing feature to only actually redraw the most recently newly added small path segment on each individual frame, rather than needlessly redrawing an entire accumulated large complex drawing from scratch, keeping the drawing experience genuinely smooth and responsive even during genuinely very fast continuous drawing motion.

Common follow-ups: How do you properly measure whether your specific gesture handling code is genuinely actually causing dropped frames?;What is the specific relationship between this common performance concern and the shouldRepaint method used within a CustomPainter?