invalid_visibility_annotation
The member '{0}' is annotated with '{1}', but this annotation is only meaningful on declarations of public members.
Description
#The analyzer produces this diagnostic when either the visibleForTemplate
or visibleForTesting
annotation is applied to a non-public declaration.
Example
#The following code produces this diagnostic:
dart
import 'package:meta/meta.dart';
@visibleForTesting
void _someFunction() {}
void f() => _someFunction();
Common fixes
#If the declaration doesn't need to be used by test code, then remove the annotation:
dart
void _someFunction() {}
void f() => _someFunction();
If it does, then make it public:
dart
import 'package:meta/meta.dart';
@visibleForTesting
void someFunction() {}
void f() => someFunction();
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.