invalid_ reference_ to_ this
Details about the 'invalid_reference_to_this' diagnostic produced by the Dart analyzer.
Invalid reference to 'this' expression.
Description
#
The analyzer produces this diagnostic when
this is used outside of an instance method or a
generative constructor. The reserved word this is
only defined in the context of an instance method, a
generative constructor, or the initializer of a late instance
field declaration.
Example
#
The following code produces this diagnostic because
v is a top-level variable:
C f() => this;
class C {}
Common fixes
#
Use a variable of the appropriate type in place of
this, declaring it if necessary:
C f(C c) => c;
class C {}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.