Stage 1 · Lesson 3 of 10
Functions, named parameters and closures
code is full of functions. Every onPressed is a , a function the button calls when tapped, and every widget takes . Learn positional parameters, then named parameters in braces, marked required or given a default.
Learn arrow syntax for one-line bodies, as in int double(int x) => x * 2;. Functions are objects in Dart, like are, so you can pass them around and store them in variables. A closure remembers the variables around the place it was written. That is how a button on a list item knows which item it belongs to.
Common trapa closure that captures a value which later changes, or a callback that keeps a large object alive after its screen has gone.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with
- GuideFreeDart Language Tour
Google · Beginner
The official tour: read it in order and rerun every example in DartPad