跳至正文

unnecessary_this

不必要的 'this.' 限定符。

描述

#

當使用關鍵字 this 訪問未被 shadowing 的成員時,分析器會生成此診斷。

示例

#

以下程式碼會生成此診斷,因為使用 this 訪問欄位 _f 是不必要的

dart
class C {
  int _f = 2;

  int get f => this._f;
}

常見修復方法

#

移除 this.

dart
class C {
  int _f = 2;

  int get f => _f;
}