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:
dart
import 'package:my_package/bar.dart';GOOD:
dart
import 'bar.dart';Incompatible rules
#The prefer_relative_imports rule 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:
analysis_options.yaml
yaml
linter:
rules:
- prefer_relative_importsIf you're instead using the YAML map syntax to configure linter rules,
add prefer_relative_imports: true under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
prefer_relative_imports: true