Challenge - 5 Problems
Clip Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the visual output of this ClipRRect widget?
Consider this Flutter widget code snippet:
What will the blue container look like on screen?
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
)What will the blue container look like on screen?
Flutter
ClipRRect( borderRadius: BorderRadius.circular(20), child: Container( width: 100, height: 100, color: Colors.blue, ), )
Attempts:
2 left
💡 Hint
ClipRRect clips its child with rounded corners defined by borderRadius.
✗ Incorrect
ClipRRect applies a rounded rectangle clip to its child. Here, the Container is clipped to have corners rounded by 20 pixels radius, so the blue box appears with rounded corners.
❓ ui_behavior
intermediate2:00remaining
What shape does this ClipPath create?
Given this Flutter code:
What shape will the red container be clipped into?
ClipPath(
clipper: TriangleClipper(),
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
)
class TriangleClipper extends CustomClipper {
@override
Path getClip(Size size) {
Path path = Path();
path.moveTo(size.width / 2, 0);
path.lineTo(0, size.height);
path.lineTo(size.width, size.height);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper oldClipper) => false;
} What shape will the red container be clipped into?
Flutter
ClipPath(
clipper: TriangleClipper(),
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
)
class TriangleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.moveTo(size.width / 2, 0);
path.lineTo(0, size.height);
path.lineTo(size.width, size.height);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}Attempts:
2 left
💡 Hint
The custom clipper defines a path with three points forming a triangle.
✗ Incorrect
The TriangleClipper creates a path shaped like a triangle with the top point at the center top and the base along the bottom edge. The ClipPath clips the container to this triangle shape.
❓ lifecycle
advanced2:00remaining
When does Flutter call shouldReclip in a CustomClipper?
In a CustomClipper used with ClipPath, when is the method shouldReclip called by Flutter?
Attempts:
2 left
💡 Hint
Think about when Flutter needs to know if it should redraw the clip shape.
✗ Incorrect
Flutter calls shouldReclip when the clipper instance changes to check if the clipping path needs to be recalculated and the widget redrawn.
📝 Syntax
advanced2:00remaining
Which ClipRRect code snippet correctly applies a circular border radius?
Choose the correct Flutter code to clip a widget with a circular border radius of 50 pixels.
Attempts:
2 left
💡 Hint
The radius value must be a double, not a string.
✗ Incorrect
BorderRadius.circular expects a double value. Option A passes a string which causes a type error. Options A and B are both valid, but B explicitly uses a double literal. Option A is also valid but more verbose. Option A is the best choice.
🔧 Debug
expert2:00remaining
Why does this ClipPath not clip the child widget as expected?
This Flutter code uses ClipPath with a custom clipper but the child widget is not clipped:
What is the reason the clipping does not happen?
ClipPath(
clipper: MyClipper(),
child: Container(
width: 100,
height: 100,
color: Colors.green,
),
)
class MyClipper extends CustomClipper {
@override
Path getClip(Size size) {
return Path();
}
@override
bool shouldReclip(CustomClipper oldClipper) => false;
} What is the reason the clipping does not happen?
Flutter
ClipPath(
clipper: MyClipper(),
child: Container(
width: 100,
height: 100,
color: Colors.green,
),
)
class MyClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
return Path();
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}Attempts:
2 left
💡 Hint
Check what the getClip method returns as the clipping shape.
✗ Incorrect
An empty Path means no area is defined for clipping, so the child is not clipped at all. The shouldReclip returning false only affects updates, not initial clipping. Container has size and ClipPath does not use borderRadius.