invalid_ internal_ annotation
Details about the 'invalid_internal_annotation' diagnostic produced by the Dart analyzer.
Only public elements in a package's private API can be annotated as being internal.
Description
#
The analyzer produces this diagnostic when a declaration is
annotated with the
internal
annotation and that declaration is either in a
public libraryPublic libraryA library that is located in a package's `lib`
directory but not inside the `lib/src` directory.
Learn more
or has a private name.
Example
#
The following code, when in a
public libraryPublic libraryA library that is located in a package's `lib`
directory but not inside the `lib/src` directory.
Learn more, produces this diagnostic because the
internal
annotation can't be applied to declarations in a
public libraryPublic libraryA library that is located in a package's `lib`
directory but not inside the `lib/src` directory.
Learn more:
import 'package:meta/meta.dart';
@internal
class C {}
The following code, whether in a public or internal library,
produces this diagnostic because the
internal
annotation can't be applied to declarations with private
names:
import 'package:meta/meta.dart';
@internal
class _C {}
Common fixes
#If the declaration has a private name, then remove the annotation:
class _C {}
If the declaration has a public name and is intended to be
internal to the package, then move the annotated declaration
into an internal library (in other words, a library inside the
src directory).
Otherwise, remove the use of the annotation:
class C {}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.