sized_box_for_whitespace
SizedBox
for whitespace.
此规则自 Dart 2.9 版本起可用。
_规则集:flutter _
此规则提供 快速修复 。
详情
#Use SizedBox
to add whitespace to a layout.
A Container
is a heavier Widget than a SizedBox
, and as bonus, SizedBox
has a const
constructor.
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.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.