8

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!

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
theProCoder
  • 390
  • 6
  • 21
  • Does this answer your question? [Flutter imports : relative path or package?](https://stackoverflow.com/questions/59693195/flutter-imports-relative-path-or-package) – Md. Yeasin Sheikh Jan 29 '22 at 04:00

2 Answers2

7

While importing, you can find both option by tapping on yellow bulb or pressing ctrl+.

enter image description here

Another handy thing, using dart-import extension on Vs-code.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
5

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.

dart import fix on save

There is a recommendation in effective dart guideline for relative path import usage.

Arkar Min Tun
  • 605
  • 8
  • 12