mixin_ class_ declares_ constructor
The class '{0}' can't be used as a mixin because it declares a constructor.
Description
#The analyzer produces this diagnostic when a class is used as a mixin and the mixed-in class defines a constructor.
Example
#
The following code produces this diagnostic because the class
A
, which
defines a constructor, is being used as a mixin:
//@dart=2.19
class A {
A();
}
class B with A {}
Common fixes
#If it's possible to convert the class to a mixin, then do so:
mixin A {
}
class B with A {}
If the class can't be a mixin and it's possible to remove the constructor, then do so:
//@dart=2.19
class A {
}
class B with A {}
If the class can't be a mixin and you can't remove the constructor, then try extending or implementing the class rather than mixing it in:
class A {
A();
}
class B extends A {}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.