1 Basic Dart Program
1 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.
void main() {
print("Hello World!");
}
void main() is the starting point where the execution of your program
begins.
Every program starts with a 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.
void main()
{
var name = "John";
print(name);
}
void main(){
var firstName = "John";
var lastName = "Doe";
print("Full name is $firstName $lastName");
}
void main() {
int num1 = 10; //declaring number1
int num2 = 3; //declaring number2
// Calculation
int sum = num1 + num2;
int diff = num1 - num2;
int mul = num1 * num2;
double div = num1 / num2; // It is double because it outputs
number with decimal.
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 a dart project will
help you to manage this all.
This will create a simple dart project with some ready-made code.
First, open the project location on the command/terminal and run the project with
this command.
dart run