Skip to main content

prefer-correct-edge-insets-constructor

added in: 1.6.0
🛠
Free+

Suggests using the correct EdgeInsets constructor.

If any value passed to EdgeInsets.fromLTRB is 0, then EdgeInsets.fromLTRB should be replaced with EdgeInsets.only, passing all non-zero values. If passed values are symmetric, then EdgeInsets.fromLTRB or EdgeInsets.only should be replaced with the EdgeInsets.symmetric constructor.

Example

❌ Bad:

// LINT: This 'EdgeInsets' constructor can be simplified. Try to simplify it.
EdgeInsets.fromLTRB(8, 0, 8, 0);

// LINT: This 'EdgeInsets' constructor can be simplified. Try to simplify it.
EdgeInsets.fromLTRB(8, 0, 0, 0);

// LINT: This 'EdgeInsets' constructor can be simplified. Try to simplify it.
EdgeInsets.only(left: 16, right: 16);

// LINT: This 'EdgeInsets' constructor can be simplified. Try to simplify it.
EdgeInsets.fromLTRB(8, 8, 8, 8);

✅ Good:

EdgeInsets.symmetric(horizontal: 8);
EdgeInsets.only(left: 8);
EdgeInsets.symmetric(horizontal: 16);
EdgeInsets.all(8);