subtype_of_deferred_class
Classes and mixins can't implement deferred classes.
Classes can't extend deferred classes.
Classes can't mixin deferred classes.
Description
#The analyzer produces this diagnostic when a type (class or mixin) is a subtype of a class from a library being imported using a deferred import. The supertypes of a type must be compiled at the same time as the type, and classes from deferred libraries aren't compiled until the library is loaded.
For more information, check out Lazily loading a library.
Example
#Given a file a.dart
that defines the class A
:
class A {}
The following code produces this diagnostic because the superclass of B
is declared in a deferred library:
import 'a.dart' deferred as a;
class B extends a.A {}
Common fixes
#If you need to create a subtype of a type from the deferred library, then
remove the deferred
keyword:
import 'a.dart' as a;
class B extends a.A {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。