Learning Dart; wrapping my head around types
Hi everyone. I'm learning Dart and Flutter, and I'm trying to wrap my head around the types. I come from the web dev world, but I'm trying to approach Dart from a fresh perspective.
While trying to figure out the difference between records and the collection types, I made the follow in my notes. I tried to use clear example data to make it obvious when to use each. Is it correct or have I misunderstood anything?
--------
List
Basically an array; All values have the same type
typedef AnimalsList = List<String>;
AnimalsList animals = ['cat', 'dog'];
print(animals[0]); // 'cat'
Map
Maps keys to values; All keys and values have the same type
typedef NumeralsMap = Map<String, int>;
NumeralsMap numerals = {
'I': 1,
'V': 5,
};
print(numerals['I']); // 1
Set
Fixed set of values; unordered; can't get a set's items by index (position)
typedef Directions = Set<String>;
Directions directions = {'up', 'down', 'left', 'right'};
print(directions.contains('home')); // false
Record
Basically an standard object; Values and keys can be any type
typedef Dog = ({String name, int age});
Dog dog = (
name: 'Jeff',
age: 3,
);
print(dog.name); // 'Jeff'