use_colored_box
ColoredBox
を使用してください。
このルールは、Dart 2.17以降で使用できます。
このルールには、クイックフィックスがあります。
詳細
#Container
にColor
のみがある場合、ColoredBox
を使用してください。
Container
はColoredBox
よりも重いウィジェットであり、さらにColoredBox
にはconst
コンストラクタがあります。
悪い例
dart
Widget buildArea() {
return Container(
color: Colors.blue,
child: const Text('hello'),
);
}
良い例
dart
Widget buildArea() {
return const ColoredBox(
color: Colors.blue,
child: Text('hello'),
);
}
使用方法
#use_colored_box
ルールを有効にするには、analysis_options.yaml
ファイルのlinter > rulesの下にuse_colored_box
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- use_colored_box
特に明記されていない限り、このサイトのドキュメントはDart 3.5.3を反映しています。ページは2024年7月3日に最終更新されました。 ソースコードを表示 または 問題を報告する。