Skip to content

Replace BorderRadius.circular with const BorderRadius.all and update documentation examples#183074

Merged
auto-submit[bot] merged 11 commits into
flutter:masterfrom
BrainLUX:make_border_radius_const
Mar 19, 2026
Merged

Replace BorderRadius.circular with const BorderRadius.all and update documentation examples#183074
auto-submit[bot] merged 11 commits into
flutter:masterfrom
BrainLUX:make_border_radius_const

Conversation

@BrainLUX

Copy link
Copy Markdown
Contributor

This PR replaces usages of BorderRadius.circular(double radius) with const BorderRadius.all(Radius.circular(radius)) (and similarly for BorderRadiusDirectional and BorderRadiusGeometry) to improve code consistency and enable const constructors where applicable.

Additionally, all code examples in the documentation have been updated to reflect this pattern, ensuring that developers see the recommended style.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus labels Feb 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 aims to standardize the usage of BorderRadius by replacing BorderRadius.circular with const BorderRadius.all. While the intent is good and many changes are correct, I've found several instances where this change introduces compilation errors. This is primarily due to adding const to a constructor call without ensuring all its arguments are also compile-time constants. I've also identified a couple of other issues, including a typo in documentation and incorrect usage of const with an instance variable. My review includes specific suggestions to fix these problems.

Comment thread packages/flutter/test/material/input_decorator_test.dart
Comment thread packages/flutter/test/material/progress_indicator_theme_test.dart
Comment thread packages/flutter/lib/src/material/range_slider_parts.dart
Comment thread packages/flutter/test/widgets/media_query_test.dart
Comment thread packages/flutter/test/painting/shape_decoration_test.dart
Comment thread packages/flutter/test/material/input_decorator_test.dart
Comment thread packages/flutter/lib/src/material/outlined_button.dart Outdated
Comment thread packages/flutter/test/material/input_decorator_test.dart
Comment thread packages/flutter/test/material/divider_test.dart
Comment thread packages/flutter/test/material/divider_test.dart
@dkwingsmt dkwingsmt self-requested a review March 4, 2026 19:22
dkwingsmt
dkwingsmt previously approved these changes Mar 13, 2026

@dkwingsmt dkwingsmt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Love to see more consts!

Can you resolve the merge conflict?

…_const

# Conflicts:
#	packages/flutter/lib/src/material/predictive_back_page_transitions_builder.dart
dkwingsmt
dkwingsmt previously approved these changes Mar 13, 2026

@victorsanni victorsanni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate BorderRadius.circular or at least call out in its documentation when it should (not) be used?

@Piinks

Piinks commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

I feel like I recall discussion on this in the past. @BrainLUX is there an open issue this is resolving?

@BrainLUX

Copy link
Copy Markdown
Contributor Author

I feel like I recall discussion on this in the past. @BrainLUX is there an open issue this is resolving?

Not an issue, but a similar MR was there a time ago #91239

And during code reviews at my work, I constantly ask to change the use of .circular to .all :)

@BrainLUX

BrainLUX commented Mar 14, 2026

Copy link
Copy Markdown
Contributor Author

Should we deprecate BorderRadius.circular or at least call out in its documentation when it should (not) be used?

I actually really support an idea of making .circular deprecated

@dkwingsmt

dkwingsmt commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

I doubt if it's needed. .circular is nice, concise, and convenient. Its only downside is that it's not const due to Dart's limitation of forbidding constructing objects in const initializers, which is not a problem for situations where the parameter for .circular is a variable (common in real apps).

Also, this discussion shouldn't be a blocker for this PR. Even if we're to deprecate it, it should be in a separate issue and PR.

@dkwingsmt dkwingsmt added the CICD Run CI/CD label Mar 16, 2026
@dkwingsmt dkwingsmt requested a review from victorsanni March 16, 2026 18:36
@Piinks

Piinks commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Not an issue, but a similar MR was there a time ago #91239

Thanks for digging this up!

Hixie left a comment at the time recommending against deprecation for the same reasons mentioned above: #91239 (comment)
I think that recommendation is still a good one. :)

This change seems fine as is to utilize const in the framework. 👍

Comment thread packages/flutter/lib/src/cupertino/context_menu.dart Outdated
Comment thread packages/flutter/lib/src/cupertino/cupertino_focus_halo.dart Outdated
Comment thread packages/flutter/lib/src/material/elevated_button.dart Outdated
Comment thread packages/flutter/lib/src/material/navigation_bar.dart Outdated
Comment thread packages/flutter/lib/src/material/outlined_button.dart Outdated
Comment thread packages/flutter/lib/src/material/popup_menu.dart Outdated
Comment thread packages/flutter/lib/src/material/tabs.dart Outdated
Comment thread packages/flutter/lib/src/material/text_button.dart Outdated
Comment thread packages/flutter/lib/src/painting/box_decoration.dart Outdated
@BrainLUX

BrainLUX commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for digging this up!

Hixie left a comment at the time recommending against deprecation for the same reasons mentioned above: #91239 (comment) I think that recommendation is still a good one. :)

This change seems fine as is to utilize const in the framework. 👍

This I might omit. We lean towards brevity for our sample code so it is not overly verbose. A while back, an engineer on the team was able to demonstrate that const did not result in a perceivable performance improvement in most cases, so I think it is ok to prefer the less verbose options in sample code.

Thanks for the tip! Honestly, I'd really like to see the mentioned study on the performance of const constructors for my own development.
Also I can't help but agree that the widespread use of const BorderRadius.all instead of BorderRadius.circular adds verbosity (although, let's be honest, with shorthand, it all boils down to the laconic
const .all(.circular(radius)) – which in practice won't be as verbose).

As a compromise, I'd suggest adding a reminder to the .circular constructor's dart doc: "It's better to use the const BorderRadius.all constructor for better performance." This statement is a useful truth and will allow novice developers to even know about the existence of the .all constructor for their needs and will also give them a hint about the usefulness of const constructors in general.

What do you think?

@Piinks

Piinks commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

As a compromise, I'd suggest adding a reminder to the .circular constructor's dart doc: "It's better to use the const BorderRadius.all constructor for better performance."

SGTM! I will see if I can dig up that reference on const. IIRC, it's somewhere here on Github.

@Piinks

Piinks commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Phew! That was easier to dig up than I thought!
Here are the const findings I referenced: #149932 (comment)

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 23, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2026
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…documentation examples (flutter#183074)

This PR replaces usages of `BorderRadius.circular(double radius)` with
`const BorderRadius.all(Radius.circular(radius))` (and similarly for
`BorderRadiusDirectional` and `BorderRadiusGeometry`) to improve code
consistency and enable const constructors where applicable.

Additionally, all code examples in the documentation have been updated
to reflect this pattern, ensuring that developers see the recommended
style.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] 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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
adil192 added a commit to saber-notes/saber that referenced this pull request Apr 3, 2026
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…documentation examples (flutter#183074)

This PR replaces usages of `BorderRadius.circular(double radius)` with
`const BorderRadius.all(Radius.circular(radius))` (and similarly for
`BorderRadiusDirectional` and `BorderRadiusGeometry`) to improve code
consistency and enable const constructors where applicable.

Additionally, all code examples in the documentation have been updated
to reflect this pattern, ensuring that developers see the recommended
style.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] 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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants