0% found this document useful (0 votes)
27 views2 pages

1 Basic Dart Program

This document provides an overview of basic Dart programming, including a simple Hello World program and explanations of key concepts such as the main function, code blocks, and string interpolation. It also covers basic calculations and the process of creating and running a Dart project. The document outlines steps for setting up a Dart project and executing it using the command line.

Uploaded by

pearlyjacob6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

1 Basic Dart Program

This document provides an overview of basic Dart programming, including a simple Hello World program and explanations of key concepts such as the main function, code blocks, and string interpolation. It also covers basic calculations and the process of creating and running a Dart project. The document outlines steps for setting up a Dart project and executing it using the command line.

Uploaded by

pearlyjacob6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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!");
}

Basic Dart Program Explained

 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.

Basic Dart Program For Printing Name

void main()
{
var name = "John";
print(name);
}

Dart Program To Join One Or More Variables

Here $variableName is used to join variables. This joining process in dart is


called string interpolation.

void main(){
var firstName = "John";
var lastName = "Doe";
print("Full name is $firstName $lastName");
}

Dart Program For Basic Calculation

Performing addition, subtraction, multiplication, and division in dart.

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.

// displaying the output


print("The sum is $sum");
print("The diff is $diff");
print("The mul is $mul");
print("The div is $div");
}

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 a dart project will
help you to manage this all.

dart create <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 first_app)
 Type cd first_app
 Type code . to open project with visual studio code
 To check the main dart file go to bin/first_app.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 run

You might also like