invalid_non_virtual_annotation
The annotation '@nonVirtual' can only be applied to a concrete instance member.
Description
#The analyzer produces this diagnostic when the nonVirtual
annotation is
found on a declaration other than a member of a class, mixin, or enum, or
if the member isn't a concrete instance member.
Examples
#The following code produces this diagnostic because the annotation is on a class declaration rather than a member inside the class:
import 'package:meta/meta.dart';
@nonVirtual
class C {}
The following code produces this diagnostic because the method m
is an
abstract method:
import 'package:meta/meta.dart';
abstract class C {
@nonVirtual
void m();
}
The following code produces this diagnostic because the method m
is a
static method:
import 'package:meta/meta.dart';
abstract class C {
@nonVirtual
static void m() {}
}
Common fixes
#If the declaration isn't a member of a class, mixin, or enum, then remove the annotation:
class C {}
If the member is intended to be a concrete instance member, then make it so:
import 'package:meta/meta.dart';
abstract class C {
@nonVirtual
void m() {}
}
If the member is not intended to be a concrete instance member, then remove the annotation:
abstract class C {
static void m() {}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。