sized-box-for-whitespace
Same as sized_box_for_whitespace in Dart lints
- Group
- Performance
- Path
lint/performance/sized-box-for-whitespace- Default
- On (recommended)
- Origin
- Dart lints
- Domain
- flutter
- Rule
- 433 of 512
Flags a Container used only to add fixed width/height whitespace.
A Container sized only by width/height (optionally with a child or
key) does nothing a SizedBox cannot, and SizedBox has a const
constructor, so it is cheaper and clearer for spacing. The rule fires when a
Container has no positional arguments, at least one of width/height,
and no named arguments other than width, height, child, or key.
The diagnostic covers the constructor name, excluding new and arguments.
Invalid
// Bad: a Container used only for width/height whitespace.
import 'package:flutter/material.dart';
Widget b0() => Container(width: 10);
Widget b1() => Container(height: 20);
Widget b2() => Container(width: 10, height: 20);
Widget b3() => Container(width: 10, child: Text('a'));
Widget b4() => Container(height: 20, child: Text('b'), key: Key('k'));
Widget b5() => Container(width: 5, height: 5, child: SizedBox()); Widget b0() => Container(width: 10); Widget b1() => Container(height: 20); Widget b2() => Container(width: 10, height: 20); Widget b3() => Container(width: 10, child: Text('a')); Widget b4() => Container(height: 20, child: Text('b'), key: Key('k')); Widget b5() => Container(width: 5, height: 5, child: SizedBox());Valid
// Good: Containers with real layout properties, or non-Container widgets.
import 'package:flutter/material.dart';
Widget g0() => Container(color: Colors.red, width: 10);
Widget g1() => Container(child: Text('a'));
Widget g2() => Container();
Widget g3() => Container(padding: EdgeInsets.zero, height: 10);
Widget g4() => SizedBox(width: 10, height: 10);
Widget g5() => Container(width: 10, decoration: BoxDecoration());
Widget g6() => Container(alignment: Alignment.center, width: 5, child: Text('b'));Configure sized-box-for-whitespace
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"performance": {
"sized-box-for-whitespace": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/performance/sized-box-for-whitespace: <reason>More performance rules
- unnecessary-to-list-in-spreads
unnecessary_to_list_in_spreadsrecommendedFlags a
.toList()call on the operand of a spread, e.g. - use-is-even-rather-than-modulo
use_is_even_rather_than_moduloPrefers
isEven/isOddto comparingx % 2with0or1. - use-string-buffers
use_string_buffersrecommendedPrefers a
StringBufferto growing aStringwith+inside a loop. - avoid-border-allflutter
Avoids Flutter's non-const
Border.allfactory. - avoid-shrink-wrap-in-listsflutter
Avoids shrink-wrapped Flutter lists nested in rows, columns, or other lists.
- avoid-slow-async-io
avoid_slow_async_ioAvoid the slow asynchronous
dart:iofile-system queries. - avoid-slow-collection-methods
Reports filtered iterable searches that have a direct search-method alternative.
- avoid-unnecessary-collections
Avoid singleton collection literals where SDK APIs accept a single value.