メインコンテンツにスキップ

sized_box_for_whitespace

安定版
Flutter
修正が利用可能です

空白のためのSizedBox

詳細

#

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

ContainerSizedBoxよりも重いWidgetであり、さらにSizedBoxconstコンストラクタを備えています。

悪い例

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