目次

sized_box_for_whitespace

空白用の SizedBox

このルールは Dart 2.9 から利用可能です。

ルールセット: flutter

このルールには、利用可能な クイックフィックス があります。

詳細

#

レイアウトに空白を追加するには、SizedBox を使用します。

ContainerSizedBox よりも重い Widget であり、さらにボーナスとして、SizedBox には const コンストラクタがあります。

BAD

dart
Widget buildRow() {
  return Row(
    children: <Widget>[
      const MyLogo(),
      Container(width: 4),
      const Expanded(
        child: Text('...'),
      ),
    ],
  );
}

GOOD

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