prefer-align-over-container
- Group
- Style
- Path
lint/style/prefer-align-over-container- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 313 of 512
Prefers Align over a Container used only for alignment.
The unnamed Flutter constructor must have a provably non-null child and
a provably non-null alignment argument, with only an optional key.
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, AlignmentGeometry value) {
Container(alignment: value, child: child);
new Container(alignment: value, child: child);
ui.Container(child: child, alignment: value);
new ui.Container(key: const Key("box"), alignment: value, child: child);
LayoutContainer(alignment: value, child: child);
Container(key: const Key("ordered"), child: child, alignment: (value));
}void examples(Widget child, AlignmentGeometry value) { Container(alignment: value, child: child); Container(alignment: value, child: child); new Container(alignment: value, child: child); new Container(alignment: value, child: child); ui.Container(child: child, alignment: value); ui.Container(child: child, alignment: value); new ui.Container(key: const Key("box"), alignment: value, child: child); new ui.Container(key: const Key("box"), alignment: value, child: child); LayoutContainer(alignment: value, child: child); LayoutContainer(alignment: value, child: child); Container(key: const Key("ordered"), child: child, alignment: (value));Valid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as ui;
typedef LayoutContainer = Container;
void keepContainer(Widget child, AlignmentGeometry value, AlignmentGeometry? nullable, Widget? nullableChild, dynamic unknown) {
Container(alignment: value);
Container(child: child);
Container(alignment: null, child: child);
Container(alignment: nullable, child: child);
Container(alignment: unknown, child: child);
Container(alignment: value, child: null);
Container(alignment: value, child: nullableChild);
Container(alignment: value, width: 12, child: child);
Container(alignment: value, decoration: const BoxDecoration(), child: child);
Container(alignment: value, color: Colors.red, child: child);
}
Object parameterShadow(dynamic Container, Widget child, AlignmentGeometry value) =>
Container(alignment: value, child: child);
Object prefixShadow(dynamic ui, Widget child, AlignmentGeometry value) =>
ui.Container(alignment: value, child: child);
Object aliasShadow(dynamic LayoutContainer, Widget child, AlignmentGeometry value) =>
LayoutContainer(alignment: value, child: child);
void localShadow(dynamic factory, Widget child, AlignmentGeometry value) {
final Container = factory;
Container(alignment: value, child: child);
}
void unusedTransformAlignment(Widget child, AlignmentGeometry value) {
Container(alignment: value, transformAlignment: Alignment.center, child: child);
}Configure prefer-align-over-container
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-align-over-container": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-align-over-container: <reason>More style rules
- prefer-asserts-in-initializer-lists
prefer_asserts_in_initializer_listsFlags leading constructor-body asserts that could live in the initializer list.
- prefer-asserts-with-message
prefer_asserts_with_messageFlags
assertstatements and assert initializers that have no message. - prefer-async-await
prefer-async-awaitFlags
.then(...)future chains that should useasync/await. - prefer-async-callback
prefer_async_callbackflutterFlags the type
Future<void> Function()in favor of Flutter'sAsyncCallback. - prefer-bloc-event-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-bloc-extensionsbloc
Prefer context.read/watch over
package:flutter_bloc's provider lookups. - prefer-bloc-state-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-center-over-alignflutter
Prefers
Centerover anAlignwhose alignment is known to be centered.