invalid_ override_ of_ non_ virtual_ member
Details about the 'invalid_override_of_non_virtual_member' diagnostic produced by the Dart analyzer.
The member '{0}' is declared non-virtual in '{1}' and can't be overridden in subclasses.
Description
#
The analyzer produces this diagnostic when a member of a
class, mixin, or enum overrides a member that has the
@nonVirtual annotation on it.
Example
#
The following code produces this diagnostic because the method
m in B overrides the method
m in A, and the method
m in A is annotated with the
@nonVirtual annotation:
import 'package:meta/meta.dart';
class A {
@nonVirtual
void m() {}
}
class B extends A {
@override
void m() {}
}
Common fixes
#If the annotation on the method in the superclass is correct (the method in the superclass is not intended to be overridden), then remove or rename the overriding method:
import 'package:meta/meta.dart';
class A {
@nonVirtual
void m() {}
}
class B extends A {}
If the method in the superclass is intended to be overridden,
then remove the @nonVirtual annotation:
class A {
void m() {}
}
class B extends A {
@override
void m() {}
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.