📱 Flutter
Intermediate
What is CustomPainter in Flutter?
Answer
CustomPainter lets you draw custom graphics directly on a canvas, similar to onDraw() in Android. You subclass it and override paint(Canvas, Size) to draw shapes, paths, text, and images using the Canvas API. The shouldRepaint() method tells Flutter whether to repaint when the painter is rebuilt — return false if the output has not changed. Use CustomPainter inside a CustomPaint widget. It is ideal for custom charts, progress indicators, and complex graphics.