invalid_super_formal_parameter_location
Super parameters can only be used in non-redirecting generative constructors.
Description
#The analyzer produces this diagnostic when a super parameter is used anywhere other than a non-redirecting generative constructor.
Examples
#The following code produces this diagnostic because the super parameter
x
is in a redirecting generative constructor:
class A {
A(int x);
}
class B extends A {
B.b(super.x) : this._();
B._() : super(0);
}
The following code produces this diagnostic because the super parameter
x
isn't in a generative constructor:
class A {
A(int x);
}
class C extends A {
factory C.c(super.x) => C._();
C._() : super(0);
}
The following code produces this diagnostic because the super parameter
x
is in a method:
class A {
A(int x);
}
class D extends A {
D() : super(0);
void m(super.x) {}
}
Common fixes
#If the function containing the super parameter can be changed to be a non-redirecting generative constructor, then do so:
class A {
A(int x);
}
class B extends A {
B.b(super.x);
}
If the function containing the super parameter can't be changed to be a
non-redirecting generative constructor, then remove the super
:
class A {
A(int x);
}
class D extends A {
D() : super(0);
void m(int x) {}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。