目錄

sized_box_for_whitespace

SizedBox 用於空白。

此規則從 Dart 2.9 開始提供。

規則集:flutter

此規則有可用的快速修復

詳細資訊

#

使用 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