Rod
Rod

Reputation: 464

How to move dart files in VSCode and keep imports correct

When I move my dart files inside VSCode, the imports throughout the project get messed up (they don't point to the new file's location automatically).

Is there a way to fix this?

Upvotes: 3

Views: 1216

Answers (2)

Muldec
Muldec

Reputation: 4921

VSCode does not allow extensions to participate (or catch) the renaming of a file. An issue is in progress on this topic on the VSCode repo.

The Dart team is waiting for it to implement this feature.

edit: already implemented, just drag and drop the file, release note

Upvotes: 3

Maciej Szakacz
Maciej Szakacz

Reputation: 614

It is possible if you use a Barrel. While moving the file, VSCode will change the export you have in your barrel-file. Main advantage is that the app is still running without errors. However, this export/import may need your attention (for proper structure purposes).

Example:

export 'edit_page.dart';

After moving the file to different folder, the barrel file was changed automatically:

export '../../edit_user/view/edit_page.dart';

And it didn't crash the application.

Upvotes: 0

Related Questions