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
//@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:
dart
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
//@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:
dart
class A {
A();
}
class B extends A {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。