Replace BorderRadius.circular with const BorderRadius.all and update documentation examples#183074
Conversation
There was a problem hiding this comment.
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.
…_const # Conflicts: # packages/flutter/lib/src/material/predictive_back_page_transitions_builder.dart
victorsanni
left a comment
There was a problem hiding this comment.
Should we deprecate BorderRadius.circular or at least call out in its documentation when it should (not) be used?
|
I feel like I recall discussion on this in the past. @BrainLUX is there an open issue this is resolving? |
I actually really support an idea of making .circular deprecated |
|
I doubt if it's needed. 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. |
Thanks for digging this up! Hixie left a comment at the time recommending against deprecation for the same reasons mentioned above: #91239 (comment) This change seems fine as is to utilize const in the framework. 👍 |
Thanks for the tip! Honestly, I'd really like to see the mentioned study on the performance of const constructors for my own development. 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? |
SGTM! I will see if I can dig up that reference on const. IIRC, it's somewhere here on Github. |
|
Phew! That was easier to dig up than I thought! |
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…nd update documentation examples (flutter/flutter#183074)
…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
Mirrors a change made in Flutter: flutter/flutter#183074
…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
This PR replaces usages of
BorderRadius.circular(double radius)withconst BorderRadius.all(Radius.circular(radius))(and similarly forBorderRadiusDirectionalandBorderRadiusGeometry) 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-assistbot 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.