Dart Fundamentals - Lists
Hmm, I Know This From Somewhere
Lists in Dart have a lot in common with arrays. So anyone who is familiar with arrays will have no problems with lists. What makes the difference between the two, however, are the many helpful functions that List in Dart offers. Let’s take a look at initialization…
void main() {
List names = ['Martin', 'Peter', 'Coding Like A Noob'];
List names = List.from(['Martin', 'Peter', 'Coding Like A Noob'], growable: false);
List names = List.generate(4, (index) => index);
}
These are three different ways to initialize lists in Dart. However, I usually prefer the first way, which is initialization like an array. When it comes to data types, Dart is very flexible. It’s possible to create both a dynamic and a concrete data type.
void main() {
List data = ['Martin', 20, null];
List<String> names = ['Martin', 'Peter', 'Coding Like A Noob'];
}
You can see everything else you can do with lists in my new short and concise video.