Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any benefit to use `src` sub-folder inside `lib` folder

Tags:

flutter

dart

When I'm trying to develop a flutter app (not a package, etc), Is there any benefit to create all application files and folders in src sub-folder inside lib folder?

like image 376
Mahdi Zakizadeh Avatar asked Aug 31 '19 09:08

Mahdi Zakizadeh


People also ask

Do we need src folder?

The /src folder comprises of the raw non-minified code. The /src folder is used to store the file with the primary purpose of reading (and/or editing) the code. The /src folder contains all the sources, i.e. the code which is required to be manipulated before it can be used.

What should go in src folder?

When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src . It contains the Java code of the application. A few Java classes are also created together with the new project.

Is SRC a package in Java?

At the top you see a directory called "src". This is the source root directory. It is not a Java package itself.


1 Answers

This question is tagged as Flutter but should probably also have the Dart flag as Dart is the language used by Flutter. According to Dart Organising a library Package, the convention of putting code under lib/src is called a "convention" and the purpose is to separate the library's public code from private implementation code.

There is a second reason further down that states:

Tip for web apps: For the best performance when developing with dartdevc, put implementation files under /lib/src, instead of elsewhere under /lib. Also, avoid imports of package:package_name/src/....

As the dartdevc compiler is used by flutter at development time in debug mode (see Flutter Debug Build mode), there does appear to be a design-time speed advantage with hot reload if you use the lib/src structure rather than just lib. Please note a different compiler is used for release - dart2js - so there is no advantage in this scenario (see the same link above).

A similar historical discussion on the above points can be found on the dart language github here: Recommendations for /lib/src vs. /lib

like image 73
RSF Avatar answered Sep 28 '22 02:09

RSF