-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-set-fluttertype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
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:
use_padding
- Description: Warns when a
Container
is used with only amargin
property, suggesting the use ofPadding
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!"),
);
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-set-fluttertype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug