跳到主要内容

sized_box_for_whitespace

稳定版
Flutter
修复可用

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