不要なコンテナの回避
不要なコンテナを避けてください。
このルールは 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
特に明記されていない限り、このサイトのドキュメントは Dart 3.5.3 を反映しています。ページの最終更新日: 2024-07-03。 ソースを表示 または 問題を報告する。