目次

空のコンストラクタ本体

空のコンストラクタ本体には、{} の代わりに ; を使用してください。

このルールはDart 2.0以降で使用できます。

ルールセット: 推奨flutter

このルールには、クイックフィックスが用意されています。

詳細

#

Effective Dartより

空のコンストラクタ本体には、{} の代わりに ; を使用してください。

Dartでは、空の本体を持つコンストラクタはセミコロンだけで終了できます。これはconstコンストラクタに必須です。一貫性と簡潔さのために、他のコンストラクタもこれに従うべきです。

悪い例

dart
class Point {
  int x, y;
  Point(this.x, this.y) {}
}

良い例

dart
class Point {
  int x, y;
  Point(this.x, this.y);
}

使用方法

#

empty_constructor_bodies ルールを有効にするには、analysis_options.yaml ファイルの linter > rulesempty_constructor_bodies を追加します。

analysis_options.yaml
yaml
linter:
  rules:
    - empty_constructor_bodies