Dart Analyze logoDart Analyze/
DRT-W1488

Invalid use of class with constructor as a mixinDRT-W1488

Major severityMajor
Bug Risk categoryBug Risk

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 {}