invalid_visible_outside_template_annotation
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 {}
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.