跳至正文

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;
}