invalid_ visible_ outside_ template_ annotation
Details about the 'invalid_visible_outside_template_annotation' diagnostic produced by the Dart analyzer.
The annotation 'visibleOutsideTemplate' can only be applied to a member of a class, enum, or mixin that is annotated with 'visibleForTemplate'.
Description
#
The analyzer produces this diagnostic when the
@visibleOutsideTemplate annotation is used
incorrectly. This annotation is only meant to annotate members
of a class, enum, or mixin that has the
@visibleForTemplate
annotation, to opt those members out of the visibility
restrictions that
@visibleForTemplate imposes.
Examples
#
The following code produces this diagnostic because there is
no
@visibleForTemplate annotation at the class
level:
import 'package:angular_meta/angular_meta.dart';
class C {
@visibleOutsideTemplate
int m() {
return 1;
}
}
The following code produces this diagnostic because the annotation is on a class declaration, not a member of a class, enum, or mixin:
import 'package:angular_meta/angular_meta.dart';
@visibleOutsideTemplate
class C {}
Common fixes
#
If the class is only visible so that templates can reference
it, then add the @visibleForTemplate annotation
to the class:
import 'package:angular_meta/angular_meta.dart';
@visibleForTemplate
class C {
@visibleOutsideTemplate
int m() {
return 1;
}
}
If the @visibleOutsideTemplate annotation is on
anything other than a member of a class, enum, or mixin with
the @visibleForTemplate
annotation, remove the annotation:
class C {}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.