Basic Dart Program
This is a simple dart program that prints Hello World on screen. Most programmers write the Hello World program as their first program.
Basic Dart Program Explainedβ
- void
main()
is the starting point where the execution of your program begins. Program starts with main function. - The curly braces
{}
represent the beginning and the ending of a block of code. print(βHello World!β);
prints Hello World! on screen.- Each code statement must end with a semicolon.
Basic Dart Program For Printing Nameβ
Basic Dart Program To Join One Or More Variablesβ
Here $variableName
is used to join variables. This joining process in dart is called string interpolation.
Dart Program For Basic Calculationβ
Performing addition, subtraction, multiplication, and division in dart.
Create Full Dart Projectβ
Itβs nice to work on a single file, but if your project gets bigger, you need to manage configurations, packages, and assets files. So creating dart project will help you to manage this all.
dart create -t console <project_name>
This will create a simple dart project with some ready-made code.
Steps To Create Dart Projectβ
- Open folder location on command prompt/terminal.
- Type
dart create project_name
(For E.g. dart create my_project) - Type cd
my_project
- Type
code .
to open project with visual studio code - To check main dart file go to
bin/my_project.dart
and edit your code.
Run Dart Projectβ
First, open the project location on the command/terminal and run the project with this command.
dart bin/my_project.dart
Convert Dart Code To Javascriptβ
Command | Description |
---|---|
dart compile js filename.dart | Compile dart to javascript. You can run this file with Node.js. |
Challengeβ
Create a new dart project with name stockmanagement
and then run it.