sized_box_for_whitespace
空白のためのSizedBox。
詳細
#レイアウトに空白を追加するにはSizedBoxを使用します。
ContainerはSizedBoxよりも重いWidgetであり、さらにSizedBoxはconstコンストラクタを備えています。
悪い例
dart
Widget buildRow() {
return Row(
children: <Widget>[
const MyLogo(),
Container(width: 4),
const Expanded(
child: Text('...'),
),
],
);
}良い例
dart
Widget buildRow() {
return Row(
children: const <Widget>[
MyLogo(),
SizedBox(width: 4),
Expanded(
child: Text('...'),
),
],
);
}有効にする
#sized_box_for_whitespaceルールを有効にするには、analysis_options.yamlファイルのlinter > rulesの下にsized_box_for_whitespaceを追加します。
analysis_options.yaml
yaml
linter:
rules:
- sized_box_for_whitespace代わりにYAMLマップ構文を使用してlinterルールを設定している場合は、linter > rulesの下にsized_box_for_whitespace: trueを追加します。
analysis_options.yaml
yaml
linter:
rules:
sized_box_for_whitespace: true