What is the difference between package import and normal import in flutter?

Viewed 2766

Going through some flutter source code and found two different types of imports.

What is the difference between the two and which one is better ?


#1
import 'folder/filename.dart';

#2
import 'package:projectname/folder1/folder2/folder/filename.dart';

2 Answers

There's no performance differences or anything like that.

But.. it is better to use package paths because you won't need to edit all your imports in case you move your file to another location (as they're not relative paths).

Saying that there is no difference at all might be tricky. Because importing files as packages in some place and as simple files in another, dart will consider them two different namespaces. So it can cause type conflicts. The safe way to do it is to choose one method to do it and stick to it.

Related