A sample command-line application with an entrypoint in bin/
, library code
in lib/
, and example unit test in test/
.
.dart_tool
, .packages, pubspec.yaml , pubspec.lock files are associated with the packageslib
folder is realted to the librariesanalysis_options.yaml
is related to the dart lintingbin
- reserverd for command line apps just like this one.vscode
is for vscode configurations.README.md
, .gitignore , CHANGELOG.md , are for git source control
- Dart Package is main component of the dart ecosystem
- (Pub.dev)[https://www.pub.dev] - a site where everyone comes and uploades thier own dart packages
- You can use existing packages to implement common features like database connections & state management ,etc.
- Application Pacakge is the package the will not be uploaded on the pub.dev
- Library Pacakge is the package that will be uploaded on the pub.dev
- Dart also has a pakcage manager that holds the job to manage all these pacakges which is known as
pub
- 'pubspec.yml' is like
package.json
if you are coming from node js it is responsible for- organizing the functionalities , and version of the pacakges
- We have to metion the
name
of the package sdk versiodependancies
anddev-dependacies
- also contains a list of external packages that our packages depends on
- you can more infor about pacakges on (pub.dev)[https://pub.dev]
- ex.
pedantic
package is related to the linting topic and thetest
packages is related to testing topic.
pubspec.lock
andpubspec.yaml
are genreated automatically when we rundart pub get
.dart_tool/pub/package_cofig.json
file contains the imports for the packages that are used in our project here is an example is
{
"name": "_fe_analyzer_shared",
"rootUri": "file:///C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/_fe_analyzer_shared-40.0.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
// Our Pacakge is also listed on the bottom
{
"name": "first",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.16"
}
.packages
file is deprecated version of the.dart_tool/pub/pacakge_config.json
filepubspec.lock
file mainly links to the exact version of the package here's how it looks :
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "40.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
- Pacakge can contain one or more libraries
lib
folder contains code publicly accessible to everyone meaning that if you upload your package on pub.dev then others can only use it'slib
folder only other folders likebin
will not be accessiblelib
folder contains the implemetation for the package which is publicly accessible once it is uplaoded on pub.dev
- used to check for warnings and errors
pedantic
is one of the popular linting package contains the linting rules used by google for creating thier apps.analysis_options.yaml
is responsible for the specidifying the rules for linting- to see the depedancy code go to the vs code
DEPENDACIES
section
very-good-analyzer
is also another linting pacakage used by very-good ventures
- Ideally for every feature and Functionality we should have a test checking functionality to prove it's robusness.
/test
folder in dart contains all the testing code.- Unit tests can be executed from code editor or from the dart cli
dart test
is command to run all the tests.
- Fast & Stable Developement Workflow
- Quick Analayzer & Reformatting tools
- Fast Compilation and Recompilation
- Code Optimization Techniques
- Intuitive Debugging tools
- Focused primarily on UX
- Fast Startup time
- Usefulness , reliability, stability
- Good-lookingness , Interactivity
- Testing in real world scenarios
Dart VM - Provides the execution environment for the dart apps , for production dart also uses a strip down version of dart vm for improved performance
- any code inside the vm runs on an isolated environment
- it is also known as isolated dart universe
- it has it's own heap memory for it;s own thread of control for mutators and helper threads
- heap is a garbage collector managed memory storage for all the objects allocated by the programs
- garbage collector reclaims memory which was allocted to program but it is no longer referenced.
- from
source
by usingJIT/AOT
compiler
- 1.1 Running the source code from JIT Compiler
- 1.2 Running from source code using AOT Compiler :
-
What is snapshot - it just contains efficient representation of the entities that are allocated to the dart VM heap memory. this heap is traversed just before calling the main function.
-
It is optimized for faster startup times so insted of parsing the whole source again
-
basically the heap data is serialized in the snapshot file and it is then deserialized to heap memory again by the Dart VM to run it faster.
- 3 types of snapshot :
- JIT Snapshot - contains all parsed ,classes and code during our training run
- training run -
dart compile jit-snapshot .\bin\first.dart
anddart run .\bin\<YOUR_PROJECT_NAME>.dart
is faster thandart run
[50 % Time improvement.]
- AOT Snapshot - Not uses training run . uses standard AOT Compilation approach so that the VM can directly run the snapshot without having to redo to the compilations and optimizations.
- Kernel Snapshot - portable around all cpu ; dart vm still needs to compile this
-
to see the corresponding kernel file :
dart compile kernel .\bin\<YOUR_PROJECT_NAME>.dart
-
Once this kernel binary is loaded in VM then it is parsed into various programming entities like Classes , Fields , Procedure , libraries ,etc.
-
this process is done in a LAZY way it parses basic information first and each pointer then points to the kernel binary so that later on it can continue parsing hence the name Just In Time Compiler.
- Immediate Dependancies
- Transitive Dependancies
- Regular Dependacies - used for both prod and dev environment
- Dev Dependacies - only be used during the developement phase
Ex . if you pacakge depends on a and a -> b and b-> c (-> means depends on) then a is immediate depedancy and b and c are transitive dependacies.
Dart Community uses semantic versioning for packages refer (semver.org)[https://www.semver.org]
- Caret Syntax ^
ex . ^1.2.3 , ^0.1.2
- traditional syntax =
ex. >=1.2.3 <2.0.0 , >=0.1.2 <0.2.0
- hosted pacakges on HTTP Servers
- git packages
- path packages - multiple realted pacakages ,ex. creating big app that depends on smaller pakcages
- sdk source - packages that came along with the SDKs [currently flutter is only supported here ]