prefer_ relative_ imports
Learn about the prefer_relative_imports linter rule.
Prefer relative imports for files in lib/.
Details
#
PREFER relative imports for files in
lib/.
When mixing relative and absolute imports it's possible to
create confusion where the same member gets imported in two
different ways. One way to avoid that is to ensure you
consistently use relative imports for files within the
lib/ directory.
BAD:
import 'package:my_package/bar.dart';
GOOD:
import 'bar.dart';
Incompatible rules
#
The prefer_relative_imports lint is incompatible
with the following rules:
Enable
#
To enable the prefer_relative_imports rule, add
prefer_relative_imports under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- prefer_relative_imports
If you're instead using the YAML map syntax to configure
linter rules, add
prefer_relative_imports: true under
linter > rules:
linter:
rules:
prefer_relative_imports: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.