Challenge - 5 Problems
CustomPaint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What does this CustomPainter draw?
Look at the CustomPainter code below. What shape will appear on the screen?
Flutter
class MyPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { final paint = Paint() ..color = Colors.blue ..style = PaintingStyle.fill; canvas.drawCircle(Offset(size.width / 2, size.height / 2), 50, paint); } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => false; }
Attempts:
2 left
💡 Hint
Look at the drawCircle method and the paint style used.
✗ Incorrect
The paint object has color blue and style fill, so drawCircle draws a filled blue circle at the center with radius 50.
❓ lifecycle
intermediate1:30remaining
When does shouldRepaint get called?
In a CustomPainter, when is the shouldRepaint method called by Flutter?
Attempts:
2 left
💡 Hint
Think about when Flutter needs to know if it should redraw the custom painting.
✗ Incorrect
Flutter calls shouldRepaint every time the widget rebuilds to check if the painting needs to update.
📝 Syntax
advanced2:00remaining
What error does this CustomPainter code cause?
What error will this CustomPainter code produce when run?
Flutter
class BadPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { final paint = Paint() ..color = Colors.red ..style = PaintingStyle.fill; canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), paint); } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => false; }
Attempts:
2 left
💡 Hint
Check the parentheses in the drawRect line carefully.
✗ Incorrect
The drawRect call is missing a closing parenthesis, causing a syntax error.
advanced
2:30remaining
How to update CustomPaint when data changes?
You have a CustomPainter that draws based on a variable color. How do you make sure the CustomPaint updates when the color changes?
Attempts:
2 left
💡 Hint
Think about how Flutter knows when to repaint a CustomPainter.
✗ Incorrect
Passing color and comparing it in shouldRepaint lets Flutter know when to repaint the widget.
🧠 Conceptual
expert3:00remaining
Why use CustomPaint instead of regular widgets?
Which is the best reason to use CustomPaint with a CustomPainter instead of composing regular widgets?
Attempts:
2 left
💡 Hint
Think about what CustomPainter gives you that widgets do not.
✗ Incorrect
CustomPaint allows drawing custom graphics directly on canvas, enabling complex visuals not possible with widgets alone.