prefer_relative_imports
Use relative imports for files in the 'lib' directory.
Description
#The analyzer produces this diagnostic when an import
in a library inside the lib
directory uses a package:
URI to refer to another library in the same package.
Example
#The following code produces this diagnostic because it uses a package:
URI when a relative URI could have been used:
dart
import 'package:my_package/bar.dart';
Common fixes
#Use a relative URI to import the library:
dart
import 'bar.dart';
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.