Avoid using private types in public APIs.

This rule is available as of Dart 2.14.0.

Rule sets: recommended, flutter


AVOID using library private types in public APIs.

For the purposes of this lint, a public API is considered to be any top-level or member declaration unless the declaration is library private or contained in a declaration that’s library private. The following uses of types are checked:

  • the return type of a function or method,
  • the type of any parameter of a function or method,
  • the bound of a type parameter to any function, method, class, mixin, extension’s extended type, or type alias,
  • the type of any top level variable or field,
  • any type used in the declaration of a type alias (for example typedef F = _Private Function();), or
  • any type used in the on clause of an extension or a mixin


f(_Private p) { ... }
class _Private {}


f(String s) { ... }


To enable the library_private_types_in_public_api rule, add library_private_types_in_public_api under linter > rules in your analysis_options.yaml file:

    - library_private_types_in_public_api