Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

houssemeddinefadhli81
Copy link

@houssemeddinefadhli81 houssemeddinefadhli81 commented Aug 12, 2025

This PR adds an optional borderRadius parameter to the Image widget and its named constructors (Image.asset, Image.network, Image.file, and Image.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 wrap Image in a separate ClipRRect.

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

  • Widget tests verifying that when borderRadius is set, the Image widget wraps its content in a ClipRRect with the correct radius.
  • Tests confirming no clipping occurs when borderRadius is null or zero.

Documentation

Updated the Image widget’s constructor docs to include borderRadius and added explanations about its usage and impact.


Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 12, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@justinmc
Copy link
Contributor

Not sure if this is worth adding versus wrapping Image in a ClipRRect yourself. What do you think @victorsanni ?

@houssemeddinefadhli81
Copy link
Author

@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...

@dkwingsmt dkwingsmt self-requested a review August 12, 2025 23:45
@dkwingsmt
Copy link
Contributor

dkwingsmt commented Aug 12, 2025

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.

If I understand correctly this PR still implements the radius by wrapping with an extra ClipRRect. How does this PR improve the efficiency as you mentioned?

This keeps the widget tree shallower, improves readability

I don't see this as a convincing merit.

aligns Image with other core widgets that expose borderRadius as a first-class property

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 ClipRRect.

@houssemeddinefadhli81
Copy link
Author

@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?

@dkwingsmt
Copy link
Contributor

Let's move to #173612 for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants