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 falseint 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().lengthis2. - A Map looks up by key:
every['Fern']is3, andevery['Palm']isnull, which is why its type isint?.
The shortcut
Pick the collection by the question you will ask it most.
"What comes next?"
The watering route through the flat has an order. That is a List.
The trap to watch is the Map lookup. Reading a missing key does not crash; it quietly gives null. Null safety forces you to handle that case before you can use the number.
Drills
Answer fast — trust the rule.
What does '${2 + 3} pots' produce?
What is ['Fern', 'Cactus', 'Fern'].toSet().length?
Given Map<String, int> every = {'Fern': 3};, what is every['Palm']?
Which type fits "0.5 litres of water"?
Sprout needs the plants in the order you walk past them, and the same plant may appear twice. Which type?
Remember
- Numbers, text, truth, and three collections: List, Set, Map.
- Choose the collection by its main question: next? has? value for?
- Trap: a missing Map key gives
null, and$only reads a bare name; use${}for expressions.
