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

Built-in Types

Built-in Types 12 minDart's core types are int, double, String and bool for single values plus List, Set and Map for collections, and strings can embed values with interpolation.

flutter / Built-in Types

Explore each scene at your own pace.

01 · The rule

The rule

Built-in Types

Every piece of Sprout's data fits into a handful of types that ship with Dart. Knowing which one to reach for, and what each one does at the edges, saves you from bugs like a watering interval of 3.5 days or a lookup that silently returns nothing.

The rule

Numbers, text, truth, and three collections: List, Set, Map.

Single values

int days = 3;            // whole numbers
double litres = 0.25;    // numbers with a fractional part
String name = 'Fern';    // text, single or double quotes
bool outdoors = false;   // true or false

int and double are both kinds of num. Strings can embed values with interpolation: '$name needs ${litres * 1000} ml' gives Fern needs 250.0 ml. Use $name for a plain variable and ${...} for any expression.

Collections

List<String> order = ['Fern', 'Cactus', 'Fern'];   // ordered, duplicates allowed
Set<String> kinds = {'Fern', 'Cactus'};            // no duplicates
Map<String, int> every = {'Fern': 3, 'Cactus': 14}; // key to value
  • A List keeps position: order[0] is 'Fern'.
  • A Set keeps each value once: order.toSet().length is 2.
  • A Map looks up by key: every['Fern'] is 3, and every['Palm'] is null, which is why its type is int?.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.