Dart First Program

As we have discussed earlier, Dart is easy to learn if you know any of Java, C++, JavaScript, etc. The simplest "Hello World" program gives the idea of the basic syntax of the programming language. It is the way of testing the system and working environment. In this tutorial, we will give the basic idea of Dart's syntax. There are several ways to run the first program, which is given below:

  • Using Command Line
  • Running on Browser
  • Using IDE

Before running the first program, it must ensure that we have installed the Dart SDK properly. We have discussed the complete installation guide in our previous tutorial. Let's run our first program.

Using Command Line

Step - 1:

Type dart on the terminal if it is showing dart runtime then Dart is successfully installed.

Step - 2:

Open a text editor and create a file called "helloword.dart". The file extension should be .dart that specifies; it is a Dart program file.

Dart First Program
  • main() - The main() function indicates that it is the beginning of our program. It is an essential function where the program starts its execution.
  • print() - This function is used to display the output on the console. It is similar to C, JavaScript, or any other language. The curly brackets and semicolons are necessary to use appropriately.

Step - 3:

Open the command line; compile the program run the Dart program by typing dart helloworld.dart. It will show Hello World on the screen.

Dart First Program

Running on Browser

Dart provides an online editor which is known as DartPad available at https://dartpad.dartlang.org/. On the left side, we can write the code and the output displays on the right side of the screen. We can add HTML and CSS with the Dart Code. Dart also provides some sample programs to learn. Let's have a look at the following image.

Dart First Program

Using IDE

There are various IDEs that support Dart, such as Visual Studio Code, WebStorm, IntelliJ, etc. For the visual studio code, download the dart extension and run the code.

Dart First Program

We recommend running the Dart code using the command line or IDE.






Latest Courses