library_private_types_in_public_api
Invalid use of a private type in a public API.
Description
#The analyzer produces this diagnostic when a type that is not part of the public API of a library is referenced in the public API of that library.
Using a private type in a public API can make the API unusable outside the defining library.
Example
#The following code produces this diagnostic because the parameter c
of the public function f
has a type that is library private (_C
):
void f(_C c) {}
class _C {}
Common fixes
#If the API doesn't need to be used outside the defining library, then make it private:
void _f(_C c) {}
class _C {}
If the API needs to be part of the public API of the library, then either use a different type that's public, or make the referenced type public:
void f(C c) {}
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.