sized_box_shrink_expand
SizedBox の shrink および expand という名前付きコンストラクターを使用します。
このルールは Dart 2.16 以降で使用できます。
詳細
#SizedBox.shrink(...)
および SizedBox.expand(...)
コンストラクターを適切に使用します。
コードの意図をより簡潔に捉える名前付きコンストラクターがある場合は、より一般的な SizedBox(...)
コンストラクターではなく、SizedBox.shrink(...)
または SizedBox.expand(...)
コンストラクターを使用する必要があります。
例
悪い例
dart
Widget buildLogo() {
return SizedBox(
height: 0,
width: 0,
child: const MyLogo(),
);
}
dart
Widget buildLogo() {
return SizedBox(
height: double.infinity,
width: double.infinity,
child: const MyLogo(),
);
}
良い例
dart
Widget buildLogo() {
return SizedBox.shrink(
child: const MyLogo(),
);
}
dart
Widget buildLogo() {
return SizedBox.expand(
child: const MyLogo(),
);
}
使用法
#sized_box_shrink_expand
ルールを有効にするには、analysis_options.yaml
ファイルの linter > rules の下に sized_box_shrink_expand
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- sized_box_shrink_expand
特に明記されていない限り、このサイトのドキュメントは Dart 3.5.3 を反映しています。 ページ最終更新日:2024-07-03。 ソースを表示または問題を報告。