EthicsComputerCourses
Join training +91 90532 10052

Dart Introduction & Setup

Flutter & Dart · Lesson 1 of 29 Beginner 7 min read Updated

Every Flutter app is written in Dart, so this course starts with the language itself. If you understand Dart well, Flutter becomes much easier, because a Flutter screen is simply Dart code that creates objects.

In this lesson you will learn what Dart is, install the Dart SDK (or use the copy that comes with Flutter), write your first program and create a small project with the dart command-line tool.

What is Dart?

Dart is a programming language made by Google. It is type safe, which means every value has a type such as int or String, and the tools check these types before your program runs. It is also null safe: a variable can hold null only if you allow it. You will learn this in Variables & Sound Null Safety.

Dart can turn your code into different kinds of programs. This step is called compiling:

Where the code runsHow Dart compiles itUsed for
While you developJIT (just-in-time) on the Dart VMFast edit-and-run cycles, Flutter hot reload
Phones and desktopsAOT (ahead-of-time) to native machine codeFast release apps on Android, iOS, Windows, macOS, Linux
BrowsersJavaScript or WebAssemblyFlutter web apps and Dart web apps

The Dart VM (virtual machine) is the program that runs Dart code directly during development. JIT compiles code while it runs, which allows quick reloads. AOT compiles everything before the app starts, which gives a fast, small app for your users. You do not need to remember these details now. Just know that the same Dart code can run almost anywhere.

Install the Dart SDK

The SDK (software development kit) is the set of tools you need: the compiler, the dart command and the core libraries. You have two choices:

  1. If you will install Flutter (see Install Flutter & Set Up), you already get the full Dart SDK. Flutter puts the dart command in the same bin folder as flutter.
  2. If you want only Dart for now, install the SDK on its own with a package manager.
Terminal
# Windows (choose one)
winget install --id=Google.DartSDK -e
choco install dart-sdk

# macOS with Homebrew
brew tap dart-lang/dart
brew install dart

# Check that it works (any OS)
dart --version
Output
Dart SDK version: 3.13.5 (stable) (Tue Sep 29 01:00:52 2026 -0700) on "windows_x64"

Your version number and date may be newer; any Dart 3.13 or later release works for this course. On Linux (Debian or Ubuntu), the official site explains how to add Google's package repository and then install the dart package with apt-get. The official installation page is dart.dev/get-dart.

Your first Dart program

Create a folder for practice, open it in VS Code (or any editor) and make a file called hello.dart:

Dart
// hello.dart: my first Dart program
void main() {
  print('Namaste! I am Priya from Pune.');
  print('I am learning Dart to build my first app.');
}

Open a terminal in that folder and run it with dart run hello.dart:

Output
Namaste! I am Priya from Pune.
I am learning Dart to build my first app.

Every Dart program starts at a function called main. The word void means the function does not give back (return) a value. print writes a line of text to the terminal. Text in single quotes is a string. Each statement ends with a semicolon ;, and the curly braces { } mark where the body of main starts and ends. A line starting with // is a comment: Dart ignores it, but it helps people who read your code.

Values, variables and string interpolation

Programs become useful when they work with values. Here is a slightly bigger program that stores values in variables and puts them inside text:

Dart
void main() {
  var name = 'Kabir';
  var city = 'Lucknow';
  var age = 19;

  print('Name: $name');
  print('$name lives in $city.');
  print('Next year $name will be ${age + 1}.');

  /* A multi-line comment
     can span several lines. */
  print('Name has ${name.length} letters.');
}
Output
Name: Kabir
Kabir lives in Lucknow.
Next year Kabir will be 20.
Name has 5 letters.

var creates a variable, and Dart works out its type from the value. Writing $name inside a string inserts the value of name. This is called string interpolation. For anything more than a plain variable name, such as a calculation or name.length, wrap it in ${ }.

Create a project with dart create

For anything bigger than one file, create a project. The dart create command makes a folder with a standard layout:

Terminal
dart create -t console hello_dart
cd hello_dart
dart run
Output
Hello world: 42!

The console template creates these important files:

  • bin/hello_dart.dart: the entry point that contains main.
  • lib/hello_dart.dart: library code that other files can import.
  • test/: automated tests (you will write tests in Unit & Widget Testing).
  • pubspec.yaml: the project's name, Dart version and the packages it depends on. Flutter projects have the same file.

Inside a project, dart run with no file name runs the program in bin/. Other templates exist too, such as package for a reusable library and cli for a command-line tool with argument parsing.

Everyday dart commands

CommandWhat it does
dart runRuns a Dart program or the project's main program
dart format .Formats all files in the official style (spaces, line breaks)
dart analyzeChecks your code for errors and warnings without running it
dart fix --applyApplies automatic fixes suggested by the analyzer
dart testRuns the tests in the test/ folder
dart compile exe bin/hello_dart.dartBuilds a native program you can run without the SDK

Run dart format . often. Dart has one standard style, so formatted code looks the same in every team.

Common mistakes

  • Missing semicolon. print('Hi') without ; is a compile error. Read the error message: it names the line.
  • Leaving out the braces. '$name.length' prints the name followed by the text .length. Use '${name.length}'.
  • Running the wrong folder. dart run with no file only works inside a project folder that has a pubspec.yaml.
  • Forgetting main. Without a main function, Dart has nowhere to start and reports an error.

Key points

  • Dart is Google's type-safe, null-safe language, and it is the language of Flutter.
  • Dart compiles with JIT during development and AOT to native code for release; it also compiles to JavaScript and WebAssembly.
  • The Flutter SDK includes Dart; you can also install Dart alone with winget, Chocolatey, Homebrew or apt.
  • Every program starts at main(); print writes a line of output.
  • $name and ${expression} insert values into strings.
  • dart create, dart run, dart format and dart analyze are your everyday tools.

Exercise

Write a program intro.dart that stores your name, your city and the number of hours you study each day in three variables. Print three lines: a greeting with your name, a line saying where you live, and a line that says how many hours you study in a week (multiply by 7 inside ${ }).

Show solution
Dart
void main() {
  var name = 'Meera';
  var city = 'Kochi';
  var hoursPerDay = 2;

  print('Hello, I am $name.');
  print('I live in $city.');
  print('I study ${hoursPerDay * 7} hours every week.');
}
Output
Hello, I am Meera.
I live in Kochi.
I study 14 hours every week.

The calculation hoursPerDay * 7 is an expression, so it must go inside ${ }. A plain variable such as $name does not need braces.

Quick Quiz

1. Where does every Dart program start running?

2. Which line prints the length of the string stored in city?

3. You have installed Flutter. Do you also need to install the Dart SDK separately?

4. Which command checks your code for errors without running it?

Learn Flutter & Dart with a mentor

Free lessons get you started. Our Mobile App Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call