prefer_ relative_ imports
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
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.