avoid_wrapping_in_padding
v0.4.0 Warning Fix Widget Replacement
Flags Padding widgets whose child already supports a padding parameter (such as Container, Card, ListView, etc.). Instead of wrapping in Padding, you should pass padding directly to the child widget.
Why use this rule
Section titled “Why use this rule”Many Flutter widgets accept a padding parameter in their constructor. Wrapping them in a Padding widget adds an unnecessary layer to the widget tree when the same effect can be achieved by passing padding directly to the child. This keeps the tree flatter, reduces nesting, and makes the code easier to read.
// Container supports padding, no need to wrap in PaddingPadding( padding: EdgeInsets.all(16), child: Container(child: Text('Hello')),);
// Card supports paddingPadding( padding: EdgeInsets.symmetric(horizontal: 12), child: Card(child: Text('Card content')),);// Pass padding directly to ContainerContainer(padding: EdgeInsets.all(16), child: Text('Hello'));
// Padding wrapping a widget that doesn't support padding is finePadding(padding: EdgeInsets.all(8), child: Text('Hello'));
// Container already has its own padding set -- wrapping is acceptablePadding( padding: EdgeInsets.all(8), child: Container(padding: EdgeInsets.all(4), child: Text('Hello')),);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: avoid_wrapping_in_padding: false