mixin_class_declaration_extends_not_object
The class '{0}' can't be declared a mixin because it extends a class other than 'Object'.
Description
#The analyzer produces this diagnostic when a class that is marked with
the mixin
modifier extends a class other than Object
. A mixin class
can't have a superclass other than Object
.
Example
#The following code produces this diagnostic because the class B
, which
has the modifier mixin
, extends A
:
class A {}
mixin class B extends A {}
Common fixes
#If you want the class to be used as a mixin, then change the superclass to
Object
, either explicitly or by removing the extends clause:
class A {}
mixin class B {}
If the class needs to have a superclass other than Object
, then remove
the mixin
modifier:
class A {}
class B extends A {}
If you need both a mixin and a subclass of a class other than Object
,
then move the members of the subclass to a new mixin, remove the mixin
modifier from the subclass, and apply the new mixin to the subclass:
class A {}
class B extends A with M {}
mixin M {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。