mixin_ class_ declares_ non_ trivial_ generative_ constructor
Details about the 'mixin_class_declares_non_trivial_generative_constructor' diagnostic produced by the Dart analyzer.
The mixin class '{0}' can't declare a non-trivial generative constructor.
Description
#The analyzer produces this diagnostic when a mixin class declares a non-trivial generative constructor. Trivial constructors are allowed, but non-trivial ones (those with parameters, bodies, or initializers) aren't.
Example
#
The following code produces this diagnostic because the mixin class A
defines a generative constructor with a body:
mixin class A {
A() {}
}
Common fixes
#If you can remove the body or parameters of the constructor to make it trivial, then do so:
mixin class A {
A(); // Trivial constructor
}
If the constructor can't be made trivial, then convert the mixin class to a
regular class and extend or implement it, or separate the mixin capability:
class A {
A() {}
}
mixin class AM { // A separate mixin for mixing in behavior
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.