目次

不要なコンテナの回避

不要なコンテナを避けてください。

このルールは Dart 2.7 以降で使用できます。

ルールセット: flutter

このルールにはクイックフィックスが用意されています。

詳細

#

避けるべきこと: ウィジェットを不必要なコンテナでラップすること。

他のパラメータを設定せずにウィジェットをContainerでラップしても効果はなく、コードが不必要に複雑になります。

悪い例

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

良い例

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

使用方法

#

avoid_unnecessary_containersルールを有効にするには、analysis_options.yamlファイルのlinter > rulesの下にavoid_unnecessary_containersを追加します。

analysis_options.yaml
yaml
linter:
  rules:
    - avoid_unnecessary_containers