-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Extend EdgeInsetsGeometry with Utility Methods: add EdgeInsets.some and EdgeInsets.except constructors #176507
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
Extend EdgeInsetsGeometry with Utility Methods: add EdgeInsets.some and EdgeInsets.except constructors #176507
Conversation
- Added `EdgeInsets.some` and `EdgeInsetsDirectional.some` for creating insets where all sides share a default value, with optional overrides. - Added `EdgeInsets.exceptTop`, `EdgeInsets.exceptBottom`, `EdgeInsets.exceptLeft`, and `EdgeInsets.exceptRight` for convenience in creating uniform insets except for one side. - Added `EdgeInsetsDirectional.exceptStart` and `EdgeInsetsDirectional.exceptEnd` for direction-aware insets with one side excluded. - Updated documentation for all new constructors. - Added comprehensive unit tests to cover `some` and `except*` constructors, including LTR/RTL resolution.
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 new utility methods to EdgeInsetsGeometry, EdgeInsets, and EdgeInsetsDirectional to simplify creating EdgeInsets instances. Specifically, it adds some() constructors to create insets with a default value for all sides that can be individually overridden, and except...() constructors to create insets where all sides have a given value except for one. The changes also include corresponding factory constructors on EdgeInsetsGeometry and comprehensive unit tests for the new functionality.
|
@fluttergithubbot I don't know why some checks failed, can you please help ! |
|
@Mohamed-7018 Are any of these currently not doable with the current APIs? I hesitate to add API bloat to this class without a clear idea of significant benefit for users. |
|
@justinmc justinmc Actually using EdgeInsets.all(16).copyWith(top: 0);we can achieve the same effect.
|
|
Thanks for explaining. My opinion is that this small improvement in conciseness (and const) is not worth the added maintenance burden and noise in IDE autocomplete. I could be convinced otherwise if there was a lot of community input in favor of this, so I'll keep the issue open to gather feedback. In the meantime maybe this would be a good Pub package, if something like this doesn't already exist. Thank you for your work on this PR though! |
π Summary
fixes #176470
This PR introduces several improvements to the
EdgeInsetsGeometryutilities by adding new helper methods and thorough test coverage.β Changes
some()β CreatesEdgeInsetswith all sides set to the given value.exceptTop()β CreatesEdgeInsetsexcluding the top side.some()exceptTop()π§ͺ Testing
EdgeInsetsvalues.flutter test.π Impact
EdgeInsetscreation patterns.π Related
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.