subtype_of_sealed_class
The class '{0}' shouldn't be extended, mixed in, or implemented because it's sealed.
Description
#The analyzer produces this diagnostic when a sealed class (one that either has the sealed
annotation or inherits or mixes in a sealed class) is referenced in either the extends
, implements
, or with
clause of a class or mixin declaration if the declaration isn't in the same package as the sealed class.
Example
#Given a library in a package other than the package being analyzed that contains the following:
import 'package:meta/meta.dart';
class A {}
@sealed
class B {}
The following code produces this diagnostic because C
, which isn't in the same package as B
, is extending the sealed class B
:
import 'package:a/a.dart';
class C extends B {}
Common fixes
#If the class doesn't need to be a subtype of the sealed class, then change the declaration so that it isn't:
import 'package:a/a.dart';
class B extends A {}
If the class needs to be a subtype of the sealed class, then either change the sealed class so that it's no longer sealed or move the subclass into the same package as the sealed class.
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.