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) {}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.