Dart: Import local file instead of package:myproject/folder/myfile.dart?

Hey there,

    Is there any way to make it so that when I am using Dart and try to import a file from my project directory, to use the relative reference every time instead of importing package:myproject/folder/myfile.dart? It does it automatically if the file is a sibling in the same directory as the current file, but that is barely ever the case.

    There is an addon for VSCode that automatically took any imports that were references to the current project and resolved their relative location automatically and fixes it for you. Right now I just am keeping my project open in VSCode at the same time and I just switch over to it and have the plugin fix it for me, but that is certainly not ideal. Even if it was just a plugin for this IDE, that would be better than swapping back and forth.



Comment actions Permalink
Official comment

Import statement that is auto-inserted on completion is provided by Dart Analysis Server; if you miss a possibility to choose between relative and package: imports for files from lib, please follow https://github.com/dart-lang/sdk/issues/37627 for updates

Comment actions Permalink

I understand. I figured that this might be the case so last night, I started making a tool that I will be able to use "on-save" which will do this for me automatically.

Thank you for your reply. I appreciate it.



Please sign in to leave a comment.