📱 Flutter Intermediate

What is CustomPainter in Flutter?

Why Interviewers Ask This

This tests whether you can apply Flutter knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

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.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Flutter answers easy to follow.