prefer-padding-over-container
- Group
- Style
- Path
lint/style/prefer-padding-over-container- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 393 of 512
Prefers Padding over a Container used only for padding.
The unnamed Flutter constructor must have a provably non-null child and
a provably non-null padding argument, with only an optional key.
A lone margin is also replaceable by Padding; combining margin and
padding is not reported.
Other arguments, nullable or unresolved values, and shadowed constructors
are ignored. The dedicated widget makes the layout intent explicit.
Contexts explicitly requiring Container are excluded.
Invalid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as ui;
typedef LayoutContainer = Container;
void examples(Widget child, EdgeInsetsGeometry value) {
Container(padding: value, child: child);
new Container(padding: value, child: child);
ui.Container(child: child, padding: value);
new ui.Container(key: const Key("box"), padding: value, child: child);
LayoutContainer(padding: value, child: child);
Container(key: const Key("ordered"), child: child, padding: (value));
Container(margin: value, child: child);
ui.Container(key: const Key("margin"), margin: value, child: child);
}void examples(Widget child, EdgeInsetsGeometry value) { Container(padding: value, child: child); Container(padding: value, child: child); new Container(padding: value, child: child); new Container(padding: value, child: child); ui.Container(child: child, padding: value); ui.Container(child: child, padding: value); new ui.Container(key: const Key("box"), padding: value, child: child); new ui.Container(key: const Key("box"), padding: value, child: child); LayoutContainer(padding: value, child: child); LayoutContainer(padding: value, child: child); Container(key: const Key("ordered"), child: child, padding: (value)); Container(key: const Key("ordered"), child: child, padding: (value)); Container(margin: value, child: child); Container(margin: value, child: child); ui.Container(key: const Key("margin"), margin: value, child: child);Valid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as ui;
typedef LayoutContainer = Container;
void keepContainer(Widget child, EdgeInsetsGeometry value, EdgeInsetsGeometry? nullable, Widget? nullableChild, dynamic unknown) {
Container(padding: value);
Container(child: child);
Container(padding: null, child: child);
Container(padding: nullable, child: child);
Container(padding: unknown, child: child);
Container(padding: value, child: null);
Container(padding: value, child: nullableChild);
Container(padding: value, width: 12, child: child);
Container(padding: value, decoration: const BoxDecoration(), child: child);
Container(padding: value, color: Colors.red, child: child);
}
Object parameterShadow(dynamic Container, Widget child, EdgeInsetsGeometry value) =>
Container(padding: value, child: child);
Object prefixShadow(dynamic ui, Widget child, EdgeInsetsGeometry value) =>
ui.Container(padding: value, child: child);
Object aliasShadow(dynamic LayoutContainer, Widget child, EdgeInsetsGeometry value) =>
LayoutContainer(padding: value, child: child);
void localShadow(dynamic factory, Widget child, EdgeInsetsGeometry value) {
final Container = factory;
Container(padding: value, child: child);
}
void combined(Widget child, EdgeInsetsGeometry value) {
Container(padding: value, margin: value, child: child);
}
void unusedTransformAlignment(Widget child, EdgeInsetsGeometry value) {
Container(padding: value, transformAlignment: Alignment.center, child: child);
}Configure prefer-padding-over-container
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-padding-over-container": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-padding-over-container: <reason>More style rules
- prefer-provider-extensionsprovider
Prefer context.read/watch when provider extensions are in scope.
- prefer-returning-condition
Flags an
ifreturning a boolean literal followed by the opposite literal. - prefer-riverpod-notifier-suffixriverpod
Requires a
Notifiersuffix on classes extending resolved Riverpod notifiers. - prefer-riverpod-provider-suffixriverpod
Requires a Provider suffix on resolved Riverpod top-level providers and static fields.
- prefer-single-quotes
prefer_single_quotesFlags double-quoted string literals that could use single quotes without needing an escape.
- prefer-sized-box-squareflutter
Prefers SizedBox.square for an unnamed Flutter
SizedBoxwhose explicit width and height are stable variable reads or numeric literals with identical token spelling. - prefer-spread-collections
prefer_spread_collectionsrecommendedFlags an
addAllcascade on a collection literal that a spread would express. - prefer-switch-expression
Prefer switch expressions for exhaustive switches that only return or assign a value.