Dart Hello World

Summary: in this tutorial, you’ll learn how to develop a simple but famous program in Dart called Hello, World!. The main purpose is to help you get started with the Dart programming as quickly as possible.

Download & Install the Dart SDK

The Dart Software Development Kit or SDK is a collection of command-line tools that allow you to develop Dart programs.

To download and install SDK, you open the Get the Dart SDK page and follow the instructions. This page explains in detail how to install the Dart SDK on Windows, Linux, and macOS.

To verify the Dart SDK installation, you can run the following command in a terminal:

dart --version

It should return the Dart SDK version.

Developing the Dart Hello World Program

To develop a Dart Hello World program:

First, create a simple file with the path D:\dart\hello_world.dart. The Dart source code files have the .dart extension.

Second, use your preferred editor to open the hello_world.dart file, copy the following code into the file, and save it:

void main() {
  print("Hello, World!");
}Code language: JavaScript (javascript)

Third, open a terminal and execute the following command to run the Dart file:

dart run d:\dart\hello_world.dartCode language: CSS (css)

It’ll show a message like this:

Hello, World!

A Dart program always starts with the main() function. In Dart, a function is a unit of code that does one or more tasks. You’ll learn more about functions in later tutorials.

Inside the main() function, we use the print() function to display the message Hello, World! on the screen:

print("Hello, World!");Code language: PHP (php)

Visual Studio Code

Visual Studio Code or VS Code is a popular tool for developing the Dart program.

Once VS code is installed, you can open the project folder and click the Run button to run the Hello, World! program as shown in the following picture:

The Debug Console tab shows the output of the program.

Summary

  • Dart Software Development Kit or SDK is a set of command-line tools for developing Dart programs.
  • A Dart program always starts with the main() function.
  • Use the print() function to display a message on the screen.
Was this tutorial helpful ?