Skip to content
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

[Linter] prefer_padding_over_margin_container lint rule #56987

Open
ricardodalarme opened this issue Oct 29, 2024 · 1 comment
Open

[Linter] prefer_padding_over_margin_container lint rule #56987

ricardodalarme opened this issue Oct 29, 2024 · 1 comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug

Comments

@ricardodalarme
Copy link

ricardodalarme commented Oct 29, 2024

Proposal for New Dart Lint Rule

TLDR

Add lint rule to avoid using Container with only a margin property.

Motivation

Using Container with only a margin property introduces an unnecessary widget in the widget tree, as Container adds a range of unused functionalities (decoration, padding, alignment) in this case. Replacing Container with Padding improves performance and makes the widget tree more readable. Padding is also a constant widget, which tends to be more performative.

Alternatives

Instead of creating a new rule, this could be added as an enhancement to the existing avoid_unnecessary_containers rule.

Lint Rule Implementation

  • Rule Name: prefer_padding_over_margin_container
  • Description: Warns when a Container is used with only a margin property, suggesting the use of Padding instead.
  • Severity Level: WARNING (since it is a performance and readability improvement, not a breaking issue)

Code Examples

Bad
Container(
  margin: EdgeInsets.all(8),
  child: Text("Hello, World!"),
);
Good
Padding(
  padding: EdgeInsets.all(8),
  child: Text("Hello, World!"),
);
@dart-github-bot
Copy link
Collaborator

Summary: This issue proposes a new Dart lint rule, prefer_padding_over_margin_container, to warn developers when using Container with only a margin property, suggesting the use of Padding instead. This is because Padding is more performant and results in a cleaner widget tree.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Oct 29, 2024
@a-siva a-siva removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants