I've been using dart projects in order to practice dart programs and wondered why there are two folders bin
and lib
both can contain dart files.
I did some research about this and they said bin
folder is for creating console application but that didn't help me. I don't have a clear idea about console application.
and why should I bother about these folder if I'm only using dart projects just for practicing dart language?
CodePudding user response:
The bin
folder is where you put the public entrypoints for your project to compile it to executable binaries for console applications.
If you are just practing dart code, you can leave it there and just use the lib
folder. Just make sure you'll have a file inside bin
with the same name as the project/package you created (defined in pubspec.yaml
) and a main()
function, so you can use dart run
.
The lib
folder is for all the other code you write. You can add in there all your classes files of your project as a additional code to be called by the files from the bin
folder. Or you can use just the lib
folder to write a package/library for other apps, without needing to have a bin
folder.
But the bin
folder can have a file for each command, with a main()
inside each file.
For example, you could have in it bin/sum.dart
and bin/subtract.dart
. Then you can compile each to a executable binary (sum.exe and subtract.exe) to use it as a command-line/console program.
To run each file without compiling just use dart run :COMMAND
(in the example above, dart run :sum
).
If you want to know more about it, see the documentation explaining how to compile and how to write a package that has a command-line tool
CodePudding user response:
The bin folder is typically used to store executable Dart scripts, while the lib folder is used to store library code that can be used by other Dart scripts or programs. Executable scripts in the bin folder can be run directly from the command line, while code in the lib folder is intended to be imported and used by other Dart code. From https://chat.openai.com