[Linter] prefer_padding_over_margin_container
lint rule
#56987
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
Proposal for New Dart Lint Rule
TLDR
Add lint rule to avoid using
Container
with only amargin
property.Motivation
Using
Container
with only amargin
property introduces an unnecessary widget in the widget tree, asContainer
adds a range of unused functionalities (decoration, padding, alignment) in this case. ReplacingContainer
withPadding
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
prefer_padding_over_margin_container
Container
is used with only amargin
property, suggesting the use ofPadding
instead.Code Examples
Bad
Good
The text was updated successfully, but these errors were encountered: