Skip to content

Dart Basics

Glossary

174 terms from Dart Basics, in plain words, each with the chapter that teaches it.

#

@override
An annotation placed above a method that replaces one the class inherited, such as Drink's own label() or a custom toString(). It lets Dart warn you if the name doesn't match anything to replace.
~/
The operator that divides and drops the part after the decimal point, giving a whole number. 7 ~/ 2 is 3.

A

abstract class
A class that works as a pattern and can't be created directly. Subclasses fill in its missing parts, like Shipper, which Ups must complete.
abstract method
A method declared without a body, such as daysTo in Shipper. Every non-abstract subclass must write its own version.
analysis_options.yaml
A project file holding style rules that `dart analyze` uses to check your code.
anonymous function
A function with no name, written as parameters followed by a body, like (n) => print('Pouring cup $n'). You can pass it to other functions such as where or fold.
apt
The package manager on Debian and Ubuntu Linux, used to install and update software from the command line. It can install the Dart SDK once Google's package list has been added.
argument
A value you pass to a function when you call it. In lineTotal(475, 2), the arguments are 475 and 2.
ArgumentError
A built-in exception for a bad value passed to code, which you raise with throw. The order-line constructor throws it when the quantity is below 1.
arrow function
A short way to write a function whose body is one expression. The `=>` means "return this".
assignment
Storing a value in a variable with `=`. It means "store this", not "is equal to".
async
A keyword that marks a function as able to use await. An async function always returns a Future.
async*
A keyword marking a function that produces a Stream. Inside it, each yield sends out the next value.
await
A keyword that pauses an async function until a Future completes, then gives you its value. The rest of the program keeps running meanwhile.
await for
A loop that goes over a Stream's values as they arrive, waiting for each one.

B

bash
A common shell language for typing commands in a terminal. In command examples, a line starting with `$` is a command to type, without the `$`, and lines without it show the output.
block
Code between braces { }, such as the body of main or an if. Blocks are indented by two spaces.
bool
A type with only two values, true and false. Comparisons give a bool.
break
A keyword that leaves a loop at once, even if its condition is still true.

C

call
Running a function by writing its name with parentheses and any values, such as lineTotal(475, 2).
case-sensitive
Treating capital and small letters as different. In Dart, Print is not print.
catch
Parts of a try statement that handle an exception. `on Type catch (e)` handles one kind, plain `catch (e)` handles anything, and `finally` always runs.
cd
A terminal command that moves into a folder. `cd shop` goes into shop and `cd ..` goes back up one.
Chocolatey
A package manager for Windows, an alternative way to install the Dart SDK.
class
A blueprint that defines a new type, with its fields and methods. MenuItem describes every menu item object.
closure
An anonymous function that can use and change variables from the place where it was written, even after being passed elsewhere.
collection for
A for or if written inside a list literal to decide which items go in, such as adding 'drip' only if the customer is a member.
command
One instruction typed in the terminal and run when you press Enter.
command-line arguments
The words typed after a program's name, which reach main as a List<String>. In the coffee-order project, `lat 2` arrives as ['lat', '2'].
comment
A note for people that Dart ignores, written after `//` or between `/*` and `*/`.
comparison operators
Operators that compare two values and give a bool: ==, !=, <, >, <= and >=. Note == compares, while a single = assigns.
compile error
A mistake Dart finds by checking the whole file before running, so nothing runs until you fix it.
condition
An expression that is true or false, such as bags >= 3, used by if and loops.
conditional expression
The form `condition ? a : b`, which picks one of two values, like 'bag' or 'bags' depending on the quantity.
const
Marks a value fixed before the program runs, such as a price. A const object with the same values is the same object, saving memory.
const constructor
A constructor marked const that lets you make const objects before the program runs. Every field of the class must be final.
constructor
The code that creates an object and sets its fields, like MenuItem(this.code, this.name, this.cents).
continue
A keyword that skips the rest of the current loop pass and jumps to the next one.
core library
A library that ships with Dart and is imported with a `dart:` prefix, such as dart:io, dart:convert and dart:math.

D

Dart
A programming language made by Google. Flutter apps are written in it, and it also runs on servers and the command line.
dart (command)
The command-line tool in the Dart SDK. It checks, runs, formats, creates and tests your code, with subcommands like dart run and dart format.
dart analyze
A command that checks your code for mistakes and style problems without running it.
Dart Code
The extension for VS Code that colors Dart code and underlines mistakes as you type.
dart pub
Commands for managing packages. `dart pub add intl` adds a package, and `dart pub get` downloads whatever pubspec.yaml lists.
Dart SDK
The download that gives you the `dart` tool and Dart's core libraries.
dart test
A command that finds and runs every test in the test/ folder and reports passes and failures.
dart:convert
A core library holding jsonDecode and jsonEncode, which convert between JSON text and Dart maps and lists.
dart:io
A core library for the terminal and files: stdin, stdout and the File class.
DartPad
A website at dartpad.dev that runs small Dart programs in your browser, with no install. It can't read files or typed input.
default value
A value a parameter uses when the call leaves it out, such as size = '12 oz'.
dependencies
The pubspec.yaml sections listing the packages your program uses (dependencies) or needs only while developing, like test (dev_dependencies).
destructuring
Unpacking a record into separate variables in one line, as in final (name, cents) = item;.
double
A type for numbers with a decimal point, such as 0.75.
Duration
A length of time, given in seconds:, milliseconds:, minutes: and so on, such as Duration(milliseconds: 500).
dynamic
A type that turns off type checks, so any value is allowed and mistakes appear only when the program runs. It is rarely needed, but appears for values like decoded JSON, whose types aren't known in advance.

E

endless loop
A loop whose condition never becomes false, so it never stops. Press Ctrl+C in the terminal to end the program.
enum
A type with a fixed set of named values, like Size.small, Size.medium and Size.large. An enhanced enum can also carry data such as a price extra.
escape
A backslash code in a string that gives the next character a special meaning or removes one, such as \n for a new line or \$ for a real dollar sign.
exception
An error object thrown while a program runs. It stops the program unless something catches it.
exhaustive matching
The rule that a switch expression must cover every possible value, or Dart reports an error. An enum or sealed class lets Dart check this without a `_` line.
expect
The test function that checks a value: expect(actual, matcher). If the check fails, the test stops and reports it.
extends
The keyword that makes a subclass inherit everything from a superclass, as in class Drink extends MenuItem.
extension
Adds methods or getters to a type you didn't write, even int. Inside it, `this` is the value it's called on, as in 475.money.

F

factory constructor
A constructor marked factory that returns an object instead of just filling in fields. It's an alternative way to write fromJson.
field
A variable that belongs to an object. Each MenuItem has its own code, name and cents.
File
A dart:io class for reading and writing files. Its methods return Futures because disks can be slow.
FileSystemException
The exception thrown when a file can't be read or written, such as a missing orders.txt. PathNotFoundException is one kind.
final
Marks a variable or field that is set once and then never changed.
Flutter
Google's toolkit for building apps for phones, the web and desktops, written in Dart. It comes with its own copy of Dart.
fold
A list method that adds things up. It starts from an initial value and calls your function once per item with the running total and the item.
for loop
A loop that counts, with a start, a condition and a step, such as for (var i = 1; i <= 3; i++).
for-in
A loop that runs its block once for each item in a collection: for (final x in list).
FormatException
The exception thrown when text isn't in the expected form, such as int.parse('two').
fromJson
A named constructor pattern that builds an object from a decoded JSON map, such as MenuItem.fromJson. toJson does the reverse.
function
A named set of instructions you can run whenever you need it by calling it.
Future
A promise of a value that will arrive later, such as a Future<int> that will one day hold an int.
Future.wait
Takes a list of Futures, runs them at the same time and gives a list of their results.

G

generics
Types that take another type in angle brackets, such as List<int>. The part in brackets is the type argument.
getter
A member read like a field, with no parentheses, but computed each time, such as total or dollars. You write it with get.
group
Test helpers: group collects related tests under one heading, and setUp runs before each test in the group to give it a fresh starting value.

H

Homebrew
A package manager for macOS that installs software from the command line. It can install the Dart SDK with `brew install dart`.

I

if / else
A statement that runs a block only when its condition is true, with else if and else for other choices. Only the first block whose condition is true runs.
implements
A keyword that uses a class as an interface, promising to provide all its members without inheriting any code.
import
A line at the top of a file that makes a library's names available there. show limits what comes in, hide excludes names, and as adds a prefix.
index
An item's position in a list, counting from 0.
inheritance
A class taking on another class's members with extends. A Drink inherits MenuItem's name and cents.
initializer list
Field settings written after a constructor's colon, which run before the object is ready, such as : cents = 0.
instance
One object made from a class. latte is an instance of MenuItem.
int
A type for whole numbers, such as 475.
int.parse / tryParse
Functions that turn text into a number. parse throws a FormatException on bad text, while tryParse gives null.
interface
The set of members a class promises to have when it uses implements. No code is inherited.
intl
A package from pub.dev that formats money, dates and numbers. Its `NumberFormat` can print amounts as US dollars, such as `$4.75`.
Iterable
A sequence you can loop over. where and map return Iterables, so call toList() when you need a real list.

J

JSON
A text format most web services use to send data, looking like Dart maps and lists. jsonDecode turns JSON text into Dart objects and jsonEncode does the reverse.

K

key
The value you look something up by in a map, such as the drink code 'lat'.

L

late
Promises Dart you'll set a variable before its first use, without making it nullable. Breaking the promise stops the program with an error.
library
Ready-made code in a file or package that you can import, such as dart:io.
library privacy
A name starting with an underscore, like _served, can only be used in its own file, because each file is a library.
List
An ordered collection of values written in square brackets, with each item at an index counting from 0.
listen
A Stream method that runs a function for each value without pausing main, an alternative to await for.
local variable
A variable that exists only inside the function (braces) where it's made.
logical operators
Operators that combine bools: && (and), || (or) and ! (not).
loop
Code that repeats, such as for or while.
ls
A terminal command that lists the files in the current folder (dir on Windows).

M

main
The function every Dart program starts by running. It may take a List<String> of command-line arguments.
Map
A collection of key-value pairs, written in braces like {'lat': 475}. Looking up a missing key gives null.
map (method)
A list method that turns each item into a new value and returns an Iterable. It's lazy: nothing runs until the result is used.
matcher
The second argument of expect, describing what a value should be, such as equals(950), isTrue or contains('att').
method
A function that belongs to a value or class, called with a dot, such as toStringAsFixed(2).
mixin
A bundle of fields and methods with no constructor that a class adds using with. A class can extend one class but use several mixins.

N

named constructor
An extra constructor with its own name after a dot, such as MenuItem.free or MenuItem.fromJson.
named parameters
Parameters written in braces and passed by name, like qty: 2. They can be required or have a default, and may come in any order.
null
The value meaning "no value" or "nothing here".
null assertion
The ! operator, which promises a value isn't null. It crashes with "Null check operator used on a null value" if you're wrong.
null safety
A Dart rule that only types ending in ? can hold null, catching a family of bugs before the program runs.
null-aware operators
Short operators that handle null: ?? gives a default, ??= fills in null, ?. skips a call on null.
nullable type
A type ending in ?, such as String?, which may hold a value or null.
num
A type that can hold either an int or a double.

O

Object
The class every other Dart class quietly extends. It is where members such as toString() come from.
object
A value made from a class, with its own fields. latte is an object built from MenuItem.
object pattern
A switch pattern that matches an object by type, like CardPayment c, which also names the matched object c.
optional positional parameters
Parameters in square brackets that you may leave out. They are filled in order and are null unless they have a default.

P

package
A project folder with a fixed layout and a pubspec.yaml, which can use other packages. Thousands are shared on pub.dev.
padRight / padLeft
String methods that add spaces after (padRight) or in front of (padLeft) the text until it is a given length, which lines text up in columns.
parameter
A named value, with a type, that a function receives when it's called.
primary constructor
A shorter way, added in Dart 3.13, to declare a class's fields and its constructor together in one place. It is an alternative to the classic form, where fields and the constructor are written separately.
program
A list of instructions a computer follows, written as source code.
property
A value read with a dot and no parentheses, such as 'Latte'.length.
pub.dev
Dart's package website, where you find free Dart and Flutter packages.
pubspec.lock
A file where pub records the exact package versions it chose. You leave it for pub to manage.
pubspec.yaml
The project's settings file, naming it and listing its dependencies and supported Dart versions.

R

RangeError
The error you get when a list index is past the end, such as index 2 in a two-item list.
record
A small fixed group of values treated as one, such as ('Latte', 475) of type (String, int). Handy for returning two values.
relative import
An import of a file in the same folder by its plain name, such as import 'menu.dart';.
remainder
What's left over after whole-number division, given by %. 7 % 2 is 1.
return type
The type of value a function gives back, written before its name. void means it gives nothing back.

S

scope
The part of the code where a name can be used. A local variable's scope runs from its line to the closing brace.
sealed class
An abstract class whose subclasses must all be in the same file, so a switch on it can be checked for completeness without a wildcard.
Set
A collection with no duplicates and no index, written in braces like {'esp', 'lat'}.
setter
A member that runs code when you assign to it, written with set. The reverse of a getter.
source code
The text of a program as you type it, stored in .dart files.
spread operator
The ... operator that copies all of another list's items into a list literal.
statement
One instruction, ending in a semicolon.
static
Marks a member that belongs to the class itself, not to each object, such as OrderLine.maxQty.
stdin / stdout
dart:io tools for the terminal. stdout.write prints without a new line, and stdin.readLineSync reads a typed line as a String?.
Stream
A sequence of values that arrive over time, like drinks coming off the bar. A Future gives one value; a Stream gives many.
string
A piece of text, written in quotes, such as `'Latte'`. In Dart its type is `String`, and it has methods like `trim()` and `toUpperCase()`.
string interpolation
Putting values inside a string with $name for a variable or ${...} around a calculation.
subclass / superclass
A superclass is the class being extended and a subclass is the one that extends it. super.name passes an argument up to the superclass constructor.
switch expression
A switch that gives back a value, with cases written pattern => value. It must cover every possible value, often using _ as the catch-all.
switch statement
A statement that compares one value with a list of cases and runs the first that matches, with default for no match. Each case ends by itself, so no break is needed.

T

terminal
A window where you type commands: PowerShell on Windows, the Terminal app on Mac or Linux.
this
A keyword meaning the current object or value. In a constructor, this.code stores an argument in the field code; in an extension, this is the value it was called on.
throw
Starting an exception on purpose, as in throw ArgumentError('Must be at least 1').
top-level
Written outside any class or function, so it's usable anywhere in the file.
toString()
A method every object has that turns it into text, and which print uses. Writing your own with @override changes how the object prints.
toStringAsFixed
A number method that gives text with an exact count of decimal places, such as toStringAsFixed(2) for 48.00.
try
A block holding risky code. If it throws, Dart skips to a matching catch part.
type
The kind of a value, such as int or String, which fixes what you can do with it.
type inference
Dart working out a variable's type from its first value when you use var.
type promotion
After a null check, Dart treats a nullable value as its plain type inside that block.

U

unit test
A small piece of code that runs one part of your program and checks the result, so you can re-check everything automatically.

V

value
A piece of data such as 475 or 'Latte'.
var
Makes a variable whose type Dart infers from its first value and whose value can change later.
variable
A named box that holds a value.
version constraint
A rule in pubspec.yaml for which package versions a project accepts. ^1.9.0 means 1.9.0 or any later 1.x version.
void
A return type meaning the function hands nothing back.
VS Code
A free code editor from Microsoft. With the Dart extension it colors your code and underlines mistakes as you type.

W

where
A list method that keeps the items for which your function returns true, returning an Iterable.
while loop
A loop that repeats its block as long as its condition is true, checking before each pass. A do-while checks at the end, so it runs at least once.
wildcard
The _ in a pattern, which matches anything, such as the catch-all line in a switch expression.
winget
The Windows package manager, run from PowerShell to install software. It can install the Dart SDK with `winget install --id=Google.DartSDK -e`.

Y

YAML
A simple plain-text settings format where indentation shows what belongs to what. pubspec.yaml is written in it.
yield
Inside an async* function, sends out the next value of a Stream, and the function carries on.