sized_box_for_whitespace
空白用の SizedBox
。
このルールは Dart 2.9 から利用可能です。
ルールセット: flutter
このルールには、利用可能な クイックフィックス があります。
詳細
#レイアウトに空白を追加するには、SizedBox
を使用します。
Container
は SizedBox
よりも重い Widget であり、さらにボーナスとして、SizedBox
には const
コンストラクタがあります。
BAD
dart
Widget buildRow() {
return Row(
children: <Widget>[
const MyLogo(),
Container(width: 4),
const Expanded(
child: Text('...'),
),
],
);
}
GOOD
dart
Widget buildRow() {
return Row(
children: const <Widget>[
MyLogo(),
SizedBox(width: 4),
Expanded(
child: Text('...'),
),
],
);
}
使い方
#sized_box_for_whitespace
ルールを有効にするには、analysis_options.yaml
ファイルの linter > rules の下に sized_box_for_whitespace
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- sized_box_for_whitespace
特に明記されていない限り、このサイトのドキュメントは Dart 3.5.3 を反映しています。ページ最終更新日: 2024-07-03。 ソースを表示 または 問題を報告する。