nullable_ type_ in_ on_ clause
Details about the 'nullable_type_in_on_clause' diagnostic produced by the Dart analyzer.
Nullable types can't be used as a superclass constraint.
Description
#
The analyzer produces this diagnostic when a mixin declaration
uses an on clause to specify a superclass
constraint, and the class that's specified is followed by a
?.
It isn't valid to specify a nullable superclass constraint
because doing so would have no meaning; it wouldn't change the
interface being depended on by the mixin containing the
on clause.
Note, however, that it is valid to use a nullable
type as a type argument to the superclass constraint, such as
mixin A on B<C?> {}.
Example
#
The following code produces this diagnostic because
A? is a nullable type and nullable types can't be
used in an on clause:
class C {}
mixin M on C? {}
Common fixes
#Remove the question mark from the type:
class C {}
mixin M on C {}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.