subtype_of_disallowed_type
'{0}' can't be used as a superclass constraint.
Classes and mixins can't implement '{0}'.
Classes can't extend '{0}'.
Classes can't mixin '{0}'.
Description
#The analyzer produces this diagnostic when one of the restricted classes is used in either an extends
, implements
, with
, or on
clause. The classes bool
, double
, FutureOr
, int
, Null
, num
, and String
are all restricted in this way, to allow for more efficient implementations.
Examples
#The following code produces this diagnostic because String
is used in an extends
clause:
class A extends String {}
The following code produces this diagnostic because String
is used in an implements
clause:
class B implements String {}
The following code produces this diagnostic because String
is used in a with
clause:
class C with String {}
The following code produces this diagnostic because String
is used in an on
clause:
mixin M on String {}
Common fixes
#If a different type should be specified, then replace the type:
class A extends Object {}
If there isn't a different type that would be appropriate, then remove the type, and possibly the whole clause:
class B {}
Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.