The following import :
import 'controller/conferencia_controller.dart';
Is an import relative. This means that the specified path is relative to the file that is making the import. Even, it is also possible to make Imports using ..
which means climbing a directory:
import '../controller/conferencia_controller.dart';
This type of import works, and for small projects should not generate many problems. But if a file changes path, this import will break. This means that you will have to re-look all the sites you made that import and suit the modification. Well, there are FDI’s that do it automatically, and I don’t know how far each can discern.
However, this cannot always be done. When creating a new package (and this includes your own project), the directory /lib is what becomes public to access externally. Normally, in this directory is only what should be visible to those who want to import their package in the future, exporting the necessary files. In addition, it is common to unify all Xports into a single file. Dart, to be only an isolated import, referring to the functionalities of that package.
Directly inside /lib, the library’s main file, Shelf.Dart, exports numerous lib/src files.
(Same website linked up, free translation)
That is, if you want to import a file from within a package, from outside of it, or vice versa, you need to use the second import method (referencing which package it is):
import 'package:utilities/utilities.dart';
This second type of import, allows Imports only of what is public to the package, that is, inside the folder /lib
, and regardless of the path relationship between the files.
According to the linked site:
When in Doubt, use the package: Directive; it Works in all cases.
(When in doubt, use import "package:"; works in all cases
Therefore, a healthier convention is to use the second type always. Well, in small projects it shouldn’t hurt much not to do so, since having a sense of what is being done.
Opa John, could you explain better? Put an example?
– Maurício Z.B
I have already edited the answer to clarify and give examples.
– João Soares