prefer-transform-over-container
- Group
- Style
- Path
lint/style/prefer-transform-over-container- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 412 of 512
Prefers Transform over a Container used only for transform.
The unnamed Flutter constructor must have a provably non-null child and
a provably non-null transform argument, with only an optional key.
transformAlignment is also allowed and maps to Transform.alignment.
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, Matrix4 value) {
Container(transform: value, child: child);
new Container(transform: value, child: child);
ui.Container(child: child, transform: value);
new ui.Container(key: const Key("box"), transform: value, child: child);
LayoutContainer(transform: value, child: child);
Container(key: const Key("ordered"), child: child, transform: (value));
Container(transform: value, transformAlignment: Alignment.center, child: child);
}void examples(Widget child, Matrix4 value) { Container(transform: value, child: child); Container(transform: value, child: child); new Container(transform: value, child: child); new Container(transform: value, child: child); ui.Container(child: child, transform: value); ui.Container(child: child, transform: value); new ui.Container(key: const Key("box"), transform: value, child: child); new ui.Container(key: const Key("box"), transform: value, child: child); LayoutContainer(transform: value, child: child); LayoutContainer(transform: value, child: child); Container(key: const Key("ordered"), child: child, transform: (value)); Container(key: const Key("ordered"), child: child, transform: (value)); Container(transform: value, transformAlignment: Alignment.center, child: child);Valid
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as ui;
typedef LayoutContainer = Container;
void keepContainer(Widget child, Matrix4 value, Matrix4? nullable, Widget? nullableChild, dynamic unknown) {
Container(transform: value);
Container(child: child);
Container(transform: null, child: child);
Container(transform: nullable, child: child);
Container(transform: unknown, child: child);
Container(transform: value, child: null);
Container(transform: value, child: nullableChild);
Container(transform: value, width: 12, child: child);
Container(transform: value, decoration: const BoxDecoration(), child: child);
Container(transform: value, color: Colors.red, child: child);
}
Object parameterShadow(dynamic Container, Widget child, Matrix4 value) =>
Container(transform: value, child: child);
Object prefixShadow(dynamic ui, Widget child, Matrix4 value) =>
ui.Container(transform: value, child: child);
Object aliasShadow(dynamic LayoutContainer, Widget child, Matrix4 value) =>
LayoutContainer(transform: value, child: child);
void localShadow(dynamic factory, Widget child, Matrix4 value) {
final Container = factory;
Container(transform: value, child: child);
}Configure prefer-transform-over-container
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-transform-over-container": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-transform-over-container: <reason>More style rules
- prefer-type-over-var
Prefer explicit types over
varin ordinary variable declarations. - prefer-typing-uninitialized-variables
prefer_typing_uninitialized_variablesrecommendedFlags uninitialized variables declared without a type annotation.
- prefer-underscore-for-unused-callback-parameters
prefer_underscore_for_unused_callback_parametersFlags unused closure parameters that are not named with underscores.
- prefer-void-callbackflutter
Prefers Flutter's
VoidCallbackalias over a nongenericvoid Function()type. - provide-deprecation-message
provide_deprecation_messagerecommendedFlags
@deprecatedand@Deprecated()annotations that carry no message. - public-member-api-docs
public_member_api_docsDocuments public declarations and members in package libraries.
- record-fields-ordering
Flags named record type fields that violate the configured order.
- require-trailing-commas
require_trailing_commasFlags a multi-line call, declaration, assert, or collection literal that is missing a trailing comma.