Skip to the workspace
Pebellslearn by building
Basics of Dart  ›  Lesson

DartPad — Your First Dart Program

Dart Pad 12 minDartPad runs Dart and Flutter code in the browser, and every Dart program starts running at the top-level main function.

flutter / DartPad — Your First Dart Program

Explore each scene at your own pace.

01 · The rule

The rule

DartPad — Your First Dart Program

Throughout this course you will build the ideas behind Sprout, a small app that reminds you when each houseplant needs water. Before any screens exist, you need to be able to try a line of Dart in seconds. DartPad, at dartpad.dev, lets you do that in a browser tab with nothing installed.

The rule

Dart starts at main(); everything else waits to be called.

A Dart program is a file of declarations: functions, classes, variables. None of them run on their own. When the program starts, Dart looks for one top-level function named main and runs its body from top to bottom.

void main() {
  print('Sprout');
  print('Water the fern today');
}
  • void says main gives nothing back.
  • print writes a line to the console, which DartPad shows beside your code.
  • Every statement ends with a semicolon. Leave one out and DartPad underlines the line before you even press Run.

DartPad can also run Flutter. If the code imports package:flutter/material.dart and calls runApp, the right-hand panel shows a live app instead of plain text. It supports only a chosen set of popular packages, so it is a sketchpad, not a place to build the whole project.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.