sized_box_for_whitespace
`SizedBox` 用於新增空白。
詳情
#使用 `SizedBox` 為佈局新增空白。
`Container` 是比 `SizedBox` 更重的 Widget,此外,`SizedBox` 還有一個 `const` 建構函式。
不推薦
dart
Widget buildRow() {
return Row(
children: <Widget>[
const MyLogo(),
Container(width: 4),
const Expanded(
child: Text('...'),
),
],
);
}推薦
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如果你使用 YAML 對映語法來配置 Linter 規則,請在 linter > rules 下新增 `sized_box_for_whitespace: true`
analysis_options.yaml
yaml
linter:
rules:
sized_box_for_whitespace: true