nullable_type_in_with_clause
A class or mixin can't mix in a nullable type.
Description
#The analyzer produces this diagnostic when a class or mixin declaration has a with
clause, and a mixin is followed by a ?
.
It isn't valid to specify a nullable mixin because doing so would have no meaning; it wouldn't change either the interface or implementation being inherited by the class containing the with
clause.
Note, however, that it is valid to use a nullable type as a type argument to the mixin, such as class A with B<C?> {}
.
Example
#The following code produces this diagnostic because A?
is a nullable type, and nullable types can't be used in a with
clause:
mixin M {}
class C with M? {}
Common fixes
#Remove the question mark from the type:
mixin M {}
class C with M {}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.