prefer-sized-box-square
- Group
- Style
- Path
lint/style/prefer-sized-box-square- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 407 of 512
Prefers SizedBox.square for an unnamed Flutter SizedBox whose explicit width
and height are stable variable reads or numeric literals with identical token
spelling. Calls, getters, indexing, missing/null dimensions and existing named
constructors are excluded. No automatic fix is offered.
Invalid
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef S = SizedBox;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
SizedBox(width: 10, height: 10);
const SizedBox(width: 20, height: 20);
new SizedBox(width: size, height: size);
f.SizedBox(width: 2.5, height: 2.5);
S(width: 4, height: 4, child: child);
}void examples(Widget child, dynamic image, dynamic color, double size, String label) { SizedBox(width: 10, height: 10); SizedBox(width: 10, height: 10); const SizedBox(width: 20, height: 20); const SizedBox(width: 20, height: 20); new SizedBox(width: size, height: size); new SizedBox(width: size, height: size); f.SizedBox(width: 2.5, height: 2.5); f.SizedBox(width: 2.5, height: 2.5); S(width: 4, height: 4, child: child);Valid
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef S = SizedBox;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
SizedBox(width: 10, height: 20);
SizedBox(width: 10);
SizedBox(height: 10);
SizedBox(width: null, height: null);
SizedBox.square(dimension: 10);
}Configure prefer-sized-box-square
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-sized-box-square": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-sized-box-square: <reason>More style rules
- 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.
- prefer-test-matcherstest
Recommends Matcher expectations and direct type, equality, or ordering matchers.
- prefer-trailing-comma
prefer-trailing-commaFlags multi-line argument lists that are missing a trailing comma.
- prefer-transform-over-containerflutter
Prefers
Transformover aContainerused only fortransform. - 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.