Skip to content

Conversation

@Mohamed-7018
Copy link

πŸ“Œ Summary

fixes #176470
This PR introduces several improvements to the EdgeInsetsGeometry utilities by adding new helper methods and thorough test coverage.

βœ… Changes

  • Added new methods:
    • some() β†’ Creates EdgeInsets with all sides set to the given value.
    • exceptTop() β†’ Creates EdgeInsets excluding the top side.
    • Additional utility methods for more flexibility.
  • Added comprehensive unit tests for:
    • some()
    • exceptTop()
    • Other utility methods.
  • Ensured consistency across the API surface.

πŸ§ͺ Testing

  • Verified new methods produce expected EdgeInsets values.
  • All test cases pass with flutter test.

πŸš€ Impact

  • Simplifies common EdgeInsets creation patterns.
  • Increases reliability with full test coverage.
  • Prepares the package for future extensions.

πŸ”— Related

  • Resolves #<issue_number> (if applicable).

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.

- 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.
@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 4, 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 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.

@Mohamed-7018
Copy link
Author

@fluttergithubbot I don't know why some checks failed, can you please help !

@justinmc
Copy link
Contributor

justinmc commented Oct 7, 2025

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

@Mohamed-7018
Copy link
Author

Mohamed-7018 commented Oct 8, 2025

@justinmc justinmc Actually using

EdgeInsets.all(16).copyWith(top: 0);

we can achieve the same effect.
It effectively achieves the same result. However, having it at the constructor level:

  • Allows EdgeInsets to be const.
  • Prevents creating an additional copy.
  • Allows it to be expressed in a more concise way (and saves a few characters too). :)

@justinmc
Copy link
Contributor

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!

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.

[Feature] Add EdgeInsets.some + exceptTop/Left/Right/Bottom constructors

2 participants