Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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';

like image 288
UVic Avatar asked Jun 24 '19 16:06

UVic


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).

like image 182
GaboBrandX Avatar answered Oct 02 '22 19:10

GaboBrandX


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.

like image 33
Yacine Brih Avatar answered Oct 02 '22 20:10

Yacine Brih