Ad space (banner)
Lesson 9 / 20

Working with lists (List)

This lesson covers the list, which handles several values together.

Writing List<type> creates a list of values of the same type. add() appends an element and for-in takes every element out.

The sample code creates List<String> fruits = [];, adds fruit with add(), and then displays every element with for (var f in fruits).

A common early stumble is that list indexes start at 0. A list with three elements runs from fruits[0] to fruits[2], and reaching fruits[3] is a runtime error.

In professional work, managing the data shown on screen — a product listing, say — in a list is the basic pattern in Flutter apps.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)