avoid_unnecessary_containers
不要なコンテナを避ける。
詳細
#避けること:不要なコンテナでウィジェットをラップする。
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代わりにYAMLマップ構文を使用してリンタールールを設定している場合は、linter > rulesの下にavoid_unnecessary_containers: trueを追加してください。
analysis_options.yaml
yaml
linter:
rules:
avoid_unnecessary_containers: true