implementation_imports
Don't import implementation files from another package.
此规则自 Dart 2.0 版本起可用。
_规则集:recommended , flutter _
详情
#From the the pub package layout doc:
DON'T import implementation files from another package.
The libraries inside lib
are publicly visible: other packages are free to import them. But much of a package's code is internal implementation libraries that should only be imported and used by the package itself. Those go inside a subdirectory of lib
called src
. You can create subdirectories in there if it helps you organize things.
You are free to import libraries that live in lib/src
from within other Dart code in the same package (like other libraries in lib
, scripts in bin
, and tests) but you should never import from another package's lib/src
directory. Those files are not part of the package's public API, and they might change in ways that could break your code.
BAD:
// In 'road_runner'
import 'package:acme/src/internals.dart';
使用方法
#要启用 implementation_imports
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 implementation_imports
:
linter:
rules:
- implementation_imports
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.