Getting Started with Dart Programming

In this tutorial, let us see how to setup Dart for writing Dart Code and run a simple Hello World Program.

In Windows Machine, follow the below steps

Step 1: Install Chocolatey by following the instructions using the below link. https://chocolatey.org/install

Chocolatey is required to install Dart from Command Line.

Step 2: Install or Upgrade Dart SDK

To install the Dart SDK:
C:\> choco install dart-sdk

To upgrade the Dart SDK:
C:\>choco upgrade dart-sdk

By default, the SDK is installed at C:\tools\dart-sdk. You can change that location by setting the ChocolateyToolsLocation environment variable to your chosen installation directory.

Creating Hello World Dart App

Use the dart create command and the console template to create a command-line app:

C:\> dart create -t console hellodart
This command creates a small Dart app that has the following:

A main Dart source file, bin/hellodart.dart, that contains a top-level main() function. This is the entrypoint for your app.
An additional Dart file, lib/hellodart.dart, that contains the functionality of the app and is imported by the hellodart.dart file.
A pubspec file, pubspec.yaml, that contains the app’s metadata, including information about which packages the app depends on and which versions of those packages are required.

Run the App

To run the app from the command line, use the Dart VM by running the dart run command in the app’s top directory:

C:\> cd hellodart
C:\hellodart> dart run

Update the bin/hellodart.dart file as below

import 'package:hellodart/hellodart.dart' as hellodart;

void main() {

var message = "Welcome to Dart Programming World!";

  print(message);
}

Save your changes. Rerun the main entrypoint of your app:

C:\hellodart>dart run

References:

  • https://dart.dev/get-dart
  • https://dart.dev/tutorials/server/get-started

Learn more about Dart in the next upcoming Blog Articles.

Happy Learning!