Dart Lists allow you to work with a collection of objects. They are similar to arrays in other programming languages but can also be growable or fixed-length.
Dart Lists are collections of objects accessible by index. They can hold objects of different types and have methods to manipulate elements.
Create a List
To create a list we can use square brackets and commas to separate the elements. The general syntax to create a list in Dart is as follows:
data_type list_name = [elem1, elem2, … , elemN];
var numbers = [10, 20, 30, 40, 50];
Access an element
To access an element in the list, we can use the index :
For example, to access and print the first element in the list, we can use the
the following code:
Create a growable List
To create a growable list, we can use the list List.generate() constructor.
var growableList = List.generate(6, (i) => (i + 1) * 3);
Add an element
To add an element to the list, we can use the add() method.
For example, to an element to the list,
Remove an element
To remove an element from the list, we can use the following methods
To remove element 18 from the list:
To remove the first element from the list:
Dart tutorial on this website can be found at:
More information on Dart: