Reputation: 435
So, here is the problem:
Whenever I am coding with Flutter and Dart
, and I use a feature from another file, when I press Tab
, VS Code will auto-import the file for me.
The thing is, VS Code will use the package import syntax, like import 'package:<project_name>/<file_path>';
. But I prefer relative import syntax.
So, is there a setting I can change in VS Code for Dart to configure it to use relative imports by default?
Thanks!
Upvotes: 11
Views: 7550
Reputation: 192
It isn't necessary to download an extension.
As explained here, simply add this to the analysis_options.yaml
file:
linter:
rules:
- prefer_relative_imports
Upvotes: 6
Reputation: 655
Personally, I am using dart-import extension. There is an extension setting you can turn on to modify imports on save. So, you can have a consistent import structure without needing to choose every single time.
There is a recommendation in effective dart guideline for relative path import usage.
Upvotes: 6
Reputation: 63709
While importing, you can find both option by tapping on yellow bulb or pressing ctrl+.
Another handy thing, using dart-import extension on Vs-code.
Upvotes: 9