-
Notifications
You must be signed in to change notification settings - Fork 29k
Add borderRadius parameter to Image widget for rounded corners #173613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add borderRadius parameter to Image widget for rounded corners #173613
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a borderRadius
parameter to the Image
widget, which is a great enhancement for developer ergonomics. The implementation is clean and the added tests cover the basic functionality. I have a suggestion for a minor performance optimization to avoid creating a ClipRRect
when borderRadius
is BorderRadius.zero
, along with a corresponding test case. Overall, this is a solid contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a borderRadius
property to the Image
widget, providing a convenient way to create rounded corners without needing a ClipRRect
. The implementation is straightforward and includes corresponding tests. My review focuses on a platform-specific issue on the web where clipping platform views is not supported, which affects Image.network
when using an HtmlElementView
. I've suggested a code change to handle this case gracefully and a documentation update to inform developers of this limitation. The changes are well-documented, aligning with the Flutter Style Guide's emphasis on useful documentation.
… is null or zero; add test for zero radius case
Not sure if this is worth adding versus wrapping Image in a ClipRRect yourself. What do you think @victorsanni ? |
@justinmc Thanks for your feedback! While ClipRRect achieves the same effect, adding borderRadius directly to Image reduces the need for an extra composited layer and widget in the tree. It allows the framework to handle clipping internally, which can be more efficient, especially in scrollable lists with many images. This keeps the widget tree shallower, improves readability, and aligns Image with other core widgets that expose borderRadius as a first-class property... |
If I understand correctly this PR still implements the radius by wrapping with an extra
I don't see this as a convincing merit.
Can you point out which widgets you're referring to? I would imagine that the widgets that we've added border radius properties to are those that can't be simply implemented with wrapping with an extra |
@dkwingsmt Thanks for you reply! What about updating it to handle the clipping inside RenderImage by calling canvas.clipRRect() before paintImage(), which would draw the image with rounded corners in a single pass and remove the extra widget overhead? |
Let's move to #173612 for discussion. |
This PR adds an optional
borderRadius
parameter to theImage
widget and its named constructors (Image.asset
,Image.network
,Image.file
, andImage.memory
). When provided, the image content is clipped to a rounded rectangle with the specified radius, allowing developers to easily display images with rounded corners without needing to wrapImage
in a separateClipRRect
.This change simplifies common UI patterns involving rounded images, improves developer ergonomics, and keeps the existing API backward-compatible by defaulting the parameter to
null
.Issue fixed
issue: #173612
Tests added
borderRadius
is set, theImage
widget wraps its content in aClipRRect
with the correct radius.borderRadius
is null or zero.Documentation
Updated the
Image
widget’s constructor docs to includeborderRadius
and added explanations about its usage and impact.Pre-launch Checklist
///
).